コード例 #1
0
        public static RenderableObjectList getRenderableFromLayerFile(string layerFile, World parentWorld, Cache cache, bool enableRefresh)
        {
            try {
                XPathDocument docNav = null;
                XPathNavigator nav = null;

                try {
                    docNav = new XPathDocument(layerFile);
                    nav = docNav.CreateNavigator();
                }
                catch (Exception ex) {
                    Log.Write(ex);
                    return null;
                }

                XPathNodeIterator iter = nav.Select("/LayerSet");

                if (iter.Count > 0) {
                    iter.MoveNext();
                    string redirect = iter.Current.GetAttribute("redirect", "");
                    if (redirect != null
                        && redirect.Length > 0) {
                        FileInfo layerFileInfo = new FileInfo(layerFile);

                        try {
                            Angle[] bbox = CameraBase.getViewBoundingBox();
                            string viewBBox = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", bbox[0].ToString().TrimEnd('бу'), bbox[1].ToString().TrimEnd('бу'), bbox[2].ToString().TrimEnd('бу'), bbox[3].ToString().TrimEnd('бу'));

                            //See if there is a ? already in the URL
                            int flag = redirect.IndexOf("?");
                            if (flag == -1) {
                                redirect = redirect + "?BBOX=" + viewBBox;
                            }
                            else {
                                redirect = redirect + "&BBOX=" + viewBBox;
                            }

                            WebDownload download = new WebDownload(redirect);

                            string username = iter.Current.GetAttribute("username", "");
                            string password = iter.Current.GetAttribute("password", "");

                            if (username != null) {
                                ////	download.UserName = username;
                                ////	download.Password = password;
                            }

                            FileInfo tempDownloadFile = new FileInfo(layerFile.Replace(layerFileInfo.Extension, "_.tmp"));

                            download.DownloadFile(tempDownloadFile.FullName, DownloadType.Unspecified);

                            tempDownloadFile.Refresh();
                            if (tempDownloadFile.Exists
                                && tempDownloadFile.Length > 0) {
                                FileInfo tempStoreFile = new FileInfo(tempDownloadFile.FullName.Replace("_.tmp", ".tmp"));
                                if (tempStoreFile.Exists) {
                                    tempStoreFile.Delete();
                                }

                                tempDownloadFile.MoveTo(tempStoreFile.FullName);
                            }

                            download.Dispose();

                            using (StreamWriter writer = new StreamWriter(layerFile.Replace(layerFileInfo.Extension, ".uri"), false)) {
                                writer.WriteLine(redirect);
                            }
                        }
                        catch (Exception ex) {
                            Log.Write(ex);
                        }

                        return getRenderableFromLayerFile(layerFile.Replace(layerFileInfo.Extension, ".tmp"), parentWorld, cache);
                    }
                    else {
                        RenderableObjectList parentRenderable = null;

                        string sourceUri = null;
                        if (layerFile.EndsWith(".tmp")) {
                            //get source url
                            using (StreamReader reader = new StreamReader(layerFile.Replace(".tmp", ".uri"))) {
                                sourceUri = reader.ReadLine();
                            }
                        }
                        string refreshString = iter.Current.GetAttribute("Refresh", "");
                        if (refreshString != null
                            && refreshString.Length > 0) {
                            if (iter.Current.Select("Icon").Count > 0) {
                                parentRenderable = new Icons(iter.Current.GetAttribute("Name", ""), (sourceUri != null ? sourceUri : layerFile), TimeSpan.FromSeconds(ParseDouble(refreshString)), parentWorld, cache);
                            }
                                #region by zzm
                            else if (iter.Current.Select("MyIcon").Count > 0) {
                                // add my icon here.
                                parentRenderable = new MyIcons(iter.Current.GetAttribute("Name", ""), (sourceUri != null ? sourceUri : layerFile), TimeSpan.FromSeconds(ParseDouble(refreshString)), parentWorld, cache);
                            }
                            else if (iter.Current.Select("MyChart").Count > 0) {
                                // add chart here.
                                parentRenderable = new MyCharts(iter.Current.GetAttribute("Name", ""), (sourceUri != null ? sourceUri : layerFile), TimeSpan.FromSeconds(ParseDouble(refreshString)), parentWorld, cache);
                            }
                                #endregion

                            else {
                                parentRenderable = new RenderableObjectList(iter.Current.GetAttribute("Name", ""), (sourceUri != null ? sourceUri : layerFile), TimeSpan.FromSeconds(ParseDouble(refreshString)), parentWorld, cache);
                            }
                        }
                        else {
                            if (iter.Current.Select("Icon").Count > 0) {
                                parentRenderable = new Icons(iter.Current.GetAttribute("Name", ""));
                            }
                                #region by zzm
                            else if (iter.Current.Select("MyIcon").Count > 0) {
                                // add my icon here.
                                parentRenderable = new MyIcons(iter.Current.GetAttribute("Name", ""));
                            }
                            else if (iter.Current.Select("MyChart").Count > 0) {
                                // add chart here.
                                parentRenderable = new MyCharts(iter.Current.GetAttribute("Name", ""));
                            }
                                #endregion

                            else {
                                parentRenderable = new RenderableObjectList(iter.Current.GetAttribute("Name", ""));
                            }
                        }

                        parentRenderable.ParentList = parentWorld.RenderableObjects;

                        if (World.Settings.useDefaultLayerStates) {
                            parentRenderable.IsOn = ParseBool(iter.Current.GetAttribute("ShowAtStartup", ""));
                        }
                        else {
                            parentRenderable.IsOn = IsLayerOn(parentRenderable);
                        }

                        parentRenderable.ShowOnlyOneLayer = ParseBool(iter.Current.GetAttribute("ShowOnlyOneLayer", ""));

                        parentRenderable.MetaData.Add("XmlSource", (sourceUri != null ? sourceUri : layerFile));

                        parentRenderable.MetaData.Add("World", parentWorld);
                        parentRenderable.MetaData.Add("Cache", cache);
                        parentRenderable.ParentList = parentWorld.RenderableObjects;

                        string renderPriorityString = iter.Current.GetAttribute("RenderPriority", "");
                        if (renderPriorityString != null) {
                            if (String.Compare(renderPriorityString, "Icons", false) == 0) {
                                parentRenderable.RenderPriority = RenderPriority.Icons;
                            }
                            else if (String.Compare(renderPriorityString, "LinePaths", false) == 0) {
                                parentRenderable.RenderPriority = RenderPriority.LinePaths;
                            }
                            else if (String.Compare(renderPriorityString, "Placenames", false) == 0) {
                                parentRenderable.RenderPriority = RenderPriority.Placenames;
                            }
                            else if (String.Compare(renderPriorityString, "AtmosphericImages", false) == 0) {
                                parentRenderable.RenderPriority = RenderPriority.AtmosphericImages;
                            }
                        }

                        string infoUri = iter.Current.GetAttribute("InfoUri", "");

                        if (infoUri != null
                            && infoUri.Length > 0) {
                            if (parentRenderable.MetaData.Contains("InfoUri")) {
                                parentRenderable.MetaData["InfoUri"] = infoUri;
                            }
                            else {
                                parentRenderable.MetaData.Add("InfoUri", infoUri);
                            }
                        }

                        addImageLayersFromXPathNodeIterator(iter.Current.Select("ImageLayer"), parentWorld, parentRenderable);
                        addQuadTileLayersFromXPathNodeIterator(iter.Current.Select("QuadTileSet"), parentWorld, parentRenderable, cache);
                        addPathList(iter.Current.Select("PathList"), parentWorld, parentRenderable);
                        addPolygonFeature(iter.Current.Select("PolygonFeature"), parentWorld, parentRenderable);
                        addLineFeature(iter.Current.Select("LineFeature"), parentWorld, parentRenderable);
                        addTiledPlacenameSet(iter.Current.Select("TiledPlacenameSet"), parentWorld, parentRenderable);
                        addIcon(iter.Current.Select("Icon"), parentWorld, parentRenderable, cache);
                        addScreenOverlays(iter.Current.Select("ScreenOverlay"), parentWorld, parentRenderable, cache);
                        addChildLayerSet(iter.Current.Select("ChildLayerSet"), parentWorld, parentRenderable, cache);

                        #region by zzm
                        AddMyIcon(iter.Current.Select("MyIcon"), parentWorld, parentRenderable, cache);
                        AddMyChart(iter.Current.Select("MyChart"), parentWorld, parentRenderable, cache);
                        AddMesh(iter.Current.Select("MeshLayer"), parentWorld, parentRenderable, cache);
                        #endregion

                        addExtendedInformation(iter.Current.Select("ExtendedInformation"), parentRenderable);

                        if (parentRenderable.RefreshTimer != null && enableRefresh) {
                            parentRenderable.RefreshTimer.Start();
                        }
                        return parentRenderable;
                    }
                }
            }
            catch (Exception ex) {
                Log.Write(ex);
                //Utility.Log.Write(layerFile);
            }
            return null;
        }
コード例 #2
0
        private static RenderableObjectList addChildLayerSet(XPathNodeIterator iter, World parentWorld, RenderableObjectList parentRenderable, Cache cache)
        {
            if (iter.Count > 0) {
                while (iter.MoveNext()) {
                    string layerName = iter.Current.GetAttribute("Name", "");
                    bool showAtStartup = ParseBool(iter.Current.GetAttribute("ShowAtStartup", ""));
                    bool showOnlyOneLayer = ParseBool(iter.Current.GetAttribute("ShowOnlyOneLayer", ""));

                    string redirect = iter.Current.GetAttribute("redirect", "");

                    if (redirect != null
                        && redirect.Length > 0) {
                        return getRenderableFromLayerFile(redirect, parentWorld, cache);
                    }

                    RenderableObjectList rol;
                    if (iter.Current.Select("Icon").Count > 0) {
                        rol = new Icons(layerName);
                    }
                        #region by zzm
                    else if (iter.Current.Select("MyIcon").Count > 0) {
                        rol = new MyIcons(layerName);
                    }
                    else if (iter.Current.Select("MyChart").Count > 0) {
                        rol = new MyCharts(layerName);
                    }
                    else {
                        rol = new RenderableObjectList(layerName);
                    }
                    #endregion

                    rol.ParentList = parentRenderable;

                    if (World.Settings.useDefaultLayerStates) {
                        rol.IsOn = showAtStartup;
                    }
                    else {
                        rol.IsOn = IsLayerOn(rol);
                    }
                    rol.ShowOnlyOneLayer = showOnlyOneLayer;
                    rol.MetaData.Add("XmlSource", (string) parentRenderable.MetaData["XmlSource"]);

                    string renderPriorityString = iter.Current.GetAttribute("RenderPriority", "");
                    if (renderPriorityString != null) {
                        if (String.Compare(renderPriorityString, "Icons", false) == 0) {
                            rol.RenderPriority = RenderPriority.Icons;
                        }
                        else if (String.Compare(renderPriorityString, "LinePaths", false) == 0) {
                            rol.RenderPriority = RenderPriority.LinePaths;
                        }
                        else if (String.Compare(renderPriorityString, "Placenames", false) == 0) {
                            rol.RenderPriority = RenderPriority.Placenames;
                        }
                        else if (String.Compare(renderPriorityString, "AtmosphericImages", false) == 0) {
                            rol.RenderPriority = RenderPriority.AtmosphericImages;
                        }
                    }

                    string infoUri = iter.Current.GetAttribute("InfoUri", "");

                    if (infoUri != null
                        && infoUri.Length > 0) {
                        if (rol.MetaData.Contains("InfoUri")) {
                            rol.MetaData["InfoUri"] = infoUri;
                        }
                        else {
                            rol.MetaData.Add("InfoUri", infoUri);
                        }
                    }

                    addImageLayersFromXPathNodeIterator(iter.Current.Select("ImageLayer"), parentWorld, rol);
                    addQuadTileLayersFromXPathNodeIterator(iter.Current.Select("QuadTileSet"), parentWorld, rol, cache);
                    addPolygonFeature(iter.Current.Select("PolygonFeature"), parentWorld, rol);
                    addLineFeature(iter.Current.Select("LineFeature"), parentWorld, rol);
                    addPathList(iter.Current.Select("PathList"), parentWorld, rol);
                    addTiledPlacenameSet(iter.Current.Select("TiledPlacenameSet"), parentWorld, rol);
                    addIcon(iter.Current.Select("Icon"), parentWorld, rol, cache);
                    addScreenOverlays(iter.Current.Select("ScreenOverlay"), parentWorld, rol, cache);
                    addChildLayerSet(iter.Current.Select("ChildLayerSet"), parentWorld, rol, cache);

                    #region by zzm
                    AddMyIcon(iter.Current.Select("MyIcon"), parentWorld, rol, cache);
                    AddMyChart(iter.Current.Select("MyChart"), parentWorld, rol, cache);
                    AddMesh(iter.Current.Select("MeshLayer"), parentWorld, rol, cache);
                    #endregion

                    addExtendedInformation(iter.Current.Select("ExtendedInformation"), rol);
                    parentRenderable.Add(rol);
                }
            }

            return null;
        }