private static void UpdateLinks(KmlFeature feature, KmlViewInformation viewInfo)
 {
     if (feature.visibility)
     {
         if (feature is KmlContainer)
         {
             KmlContainer container = (KmlContainer)feature;
             if (container.children != null)
             {
                 foreach (KmlFeature child in container.children)
                 {
                     UpdateLinks(child, viewInfo);
                 }
             }
         }
         else
         {
             if (feature is KmlNetworkLink)
             {
                 KmlNetworkLink netLink = (KmlNetworkLink)feature;
                 netLink.ConditionalUpdate(viewInfo);
                 if (netLink.LinkRoot != null)
                 {
                     UpdateRootLinks(netLink.LinkRoot, viewInfo);
                 }
             }
         }
     }
 }
        public void UpdateNetworkLinks(KmlViewInformation viewInfo)
        {
            foreach (KmlRoot root in Roots)
            {
                UpdateRootLinks(root, viewInfo);

            }
        }
 public static void UpdateRootLinks(KmlRoot root, KmlViewInformation viewInfo)
 {
     if (root.children != null)
     {
         foreach (KmlFeature child in root.children)
         {
             UpdateLinks(child, viewInfo);
         }
     }
 }
        private void UpdateLink(KmlViewInformation viewInfo)
        {
            try
            {
                if (Link != null)
                {
                    string url;
                    if (Link.ViewRefreshMode == viewRefreshModeEnum.onStop)
                    //if (!String.IsNullOrEmpty(Link.viewFormat))
                    {
                        url = viewInfo.PrepLinkUrl(Link.Href + "?" + Link.ViewFormat);
                    }
                    else
                    {
                        url = Link.Href;
                    }

                    LinkRoot = new KmlRoot(url, Owner);
                    Dirty = true;

                    //if (open)
                    //{
                    //    if (LinkRoot.children != null)
                    //    {
                    //        foreach (KmlFeature feature in LinkRoot.children)
                    //        {
                    //            feature.open = true;
                    //        }
                    //    }
                    //}

                    //if (visibility)
                    //{
                    //    if (LinkRoot.children != null)
                    //    {
                    //        foreach (KmlFeature feature in LinkRoot.children)
                    //        {
                    //            feature.visibility = true;
                    //        }
                    //    }
                    //}
                }
            }
            catch
            {
            }
        }
        private bool CheckRegionOverlap(KmlViewInformation viewInfo)
        {
            if (region != null)
            {
                if (!( region.west > viewInfo.bboxEast
                    || region.east < viewInfo.bboxWest
                    || region.north > viewInfo.bboxSouth
                    || region.south < viewInfo.bboxNorth) )
                {
                    return true;
                }
            }

            return false;
        }
        internal void ConditionalUpdate(KmlViewInformation viewInfo)
        {
            if (Link != null)
            {
                if ((Link.RefreshMode == refreshModeEnum.onInterval ) && DateTime.Now.Subtract(lastUpdate).TotalSeconds > Link.RefreshInterval)
                {
                    UpdateLink(viewInfo);
                }
                else if (pendingUpdate && DateTime.Now.Subtract(stopTime).TotalSeconds > Link.RefreshInterval)
                {
                    UpdateLink(viewInfo);
                }
                else if (Link.ViewRefreshMode == viewRefreshModeEnum.onStop && viewInfo.viewJustStopped)
                {
                    stopTime = DateTime.Now;
                    pendingUpdate = true;
                }
                else if (Link.ViewRefreshMode == viewRefreshModeEnum.onRequest && CheckRegionOverlap(viewInfo))
                {
                    UpdateLink(viewInfo);
                }
                else if (LinkRoot == null)
                {
                    UpdateLink(viewInfo);
                }

                // TOdo OnExpire

                if (viewInfo != null &&viewInfo.viewMoving)
                {
                    pendingUpdate = false;
                }
            }
        }