Example #1
0
		private RenderableObject getRenderableObjectListFromLayerSet(World curWorld, LayerSet.Type_LayerSet curLayerSet, string layerSetFile)//ref TreeNode treeNode)
		{
			RenderableObjectList rol = null;

			// If the layer set has icons, use the icon list layer as parent
			if(curLayerSet.HasIcon())
			{
				rol = new Icons(curLayerSet.Name.Value);
				rol.RenderPriority = RenderPriority.Icons;
			}
			else
				rol = new RenderableObjectList(curLayerSet.Name.Value);
			
			if(curLayerSet.HasShowOnlyOneLayer())
				rol.ShowOnlyOneLayer = curLayerSet.ShowOnlyOneLayer.Value;

			// HACK: This should be part of the settings
			if(curLayerSet.Name.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture)=="PLACENAMES")
				rol.RenderPriority = RenderPriority.Placenames;

			if(curLayerSet.HasExtendedInformation())
			{
				if(curLayerSet.ExtendedInformation.HasToolBarImage())
					rol.MetaData.Add("ToolBarImagePath", curLayerSet.ExtendedInformation.ToolBarImage.Value);
			}
			if(curLayerSet.HasImageLayer())
			{
				for(int i = 0; i < curLayerSet.ImageLayerCount; i++)
				{
					LayerSet.Type_ImageLayer curImageLayerType = curLayerSet.GetImageLayerAt(i);
					
					// <TexturePath> could contain Url, relative path, or absolute path
					string imagePath = null;
					string imageUrl = null;
                    if (curImageLayerType.TexturePath.Value.ToLower(System.Globalization.CultureInfo.InvariantCulture).StartsWith(("http://")))
					{
						imageUrl = curImageLayerType.TexturePath.Value;
					}
					else
					{
						imagePath = curImageLayerType.TexturePath.Value;
						if(!Path.IsPathRooted(imagePath))
							imagePath = Path.Combine(DirectoryPath, imagePath);
					}

					int transparentColor = 0;

					if(curImageLayerType.HasTransparentColor())
					{
						transparentColor = System.Drawing.Color.FromArgb(
							curImageLayerType.TransparentColor.Red.Value,
							curImageLayerType.TransparentColor.Green.Value,
							curImageLayerType.TransparentColor.Blue.Value).ToArgb();

					}

					ImageLayer newImageLayer = new ImageLayer(
						curImageLayerType.Name.Value,
						curWorld,
						(float)curImageLayerType.DistanceAboveSurface.Value,
						imagePath,
						(float)curImageLayerType.BoundingBox.South.Value2.DoubleValue(),
						(float)curImageLayerType.BoundingBox.North.Value2.DoubleValue(),
						(float)curImageLayerType.BoundingBox.West.Value2.DoubleValue(),
						(float)curImageLayerType.BoundingBox.East.Value2.DoubleValue(),
						(byte)curImageLayerType.Opacity.Value,
						(curImageLayerType.TerrainMapped.Value ? curWorld.TerrainAccessor : null));

					newImageLayer.ImageUrl = imageUrl;
					newImageLayer.TransparentColor = transparentColor;
					newImageLayer.IsOn = curImageLayerType.ShowAtStartup.Value;
					if(curImageLayerType.HasLegendImagePath())
						newImageLayer.LegendImagePath = curImageLayerType.LegendImagePath.Value;
					
					if(curImageLayerType.HasExtendedInformation() && curImageLayerType.ExtendedInformation.HasToolBarImage())
						newImageLayer.MetaData.Add("ToolBarImagePath", Path.Combine(DirectoryPath, curImageLayerType.ExtendedInformation.ToolBarImage.Value));

					rol.Add(newImageLayer);
				}
			}

			if(curLayerSet.HasQuadTileSet())
			{
				for(int i = 0; i < curLayerSet.QuadTileSetCount; i++)
				{
					LayerSet.Type_QuadTileSet2 curQtsType = curLayerSet.GetQuadTileSetAt(i);

					/*ImageAccessor imageAccessor = null;

					string permDirPath = null;
					if(curQtsType.ImageAccessor.HasPermanantDirectory())
					{
						permDirPath = curQtsType.ImageAccessor.PermanantDirectory.Value;
						if(!Path.IsPathRooted(permDirPath))
							permDirPath = Path.Combine( DirectoryPath, permDirPath );
					}

					string cacheDirPath = Path.Combine(worldWindow.Cache.CacheDirectory,
						Path.Combine(curWorld.Name,
						Path.Combine(rol.Name, curQtsType.Name.Value )));

					int transparentColor = 0;
					if(curQtsType.HasTransparentColor())
					{
						transparentColor = System.Drawing.Color.FromArgb(
							curQtsType.TransparentColor.Red.Value,
							curQtsType.TransparentColor.Green.Value,
							curQtsType.TransparentColor.Blue.Value).ToArgb();

					}
					if(curQtsType.ImageAccessor.HasWMSAccessor())
					{
						WMSLayerAccessor wmsLayerAccessor = null;
						wmsLayerAccessor = new WMSLayerAccessor();
						wmsLayerAccessor.ImageFormat = curQtsType.ImageAccessor.WMSAccessor.ImageFormat.Value;
						wmsLayerAccessor.IsTransparent = curQtsType.ImageAccessor.WMSAccessor.UseTransparency.Value;
						wmsLayerAccessor.ServerGetMapUrl = curQtsType.ImageAccessor.WMSAccessor.ServerGetMapUrl.Value;
						wmsLayerAccessor.Version = curQtsType.ImageAccessor.WMSAccessor.Version.Value;
						wmsLayerAccessor.WMSLayerName = curQtsType.ImageAccessor.WMSAccessor.WMSLayerName.Value;

						if(curQtsType.ImageAccessor.WMSAccessor.HasUsername())
							wmsLayerAccessor.Username = curQtsType.ImageAccessor.WMSAccessor.Username.Value;

						if(curQtsType.ImageAccessor.WMSAccessor.HasPassword())
							wmsLayerAccessor.Password = curQtsType.ImageAccessor.WMSAccessor.Password.Value;

						if(curQtsType.ImageAccessor.WMSAccessor.HasWMSLayerStyle())
							wmsLayerAccessor.WMSLayerStyle = curQtsType.ImageAccessor.WMSAccessor.WMSLayerStyle.Value;
						else
							wmsLayerAccessor.WMSLayerStyle = "";

						if(curQtsType.ImageAccessor.WMSAccessor.HasServerLogoFilePath())
						{
							string logoPath = Path.Combine(DirectoryPath, curQtsType.ImageAccessor.WMSAccessor.ServerLogoFilePath.Value);
							if(File.Exists(logoPath))
								wmsLayerAccessor.LogoFilePath = logoPath;
						}

						imageAccessor = new ImageAccessor(
							permDirPath,
							curQtsType.ImageAccessor.TextureSizePixels.Value,
							curQtsType.ImageAccessor.LevelZeroTileSizeDegrees.DoubleValue(),
							curQtsType.ImageAccessor.NumberLevels.Value,
							curQtsType.ImageAccessor.ImageFileExtension.Value,
							cacheDirPath,
							wmsLayerAccessor);
					}
					else if(curQtsType.ImageAccessor.HasImageTileService())
					{
						string logoPath = null;
						if(curQtsType.ImageAccessor.ImageTileService.HasServerLogoFilePath())
							logoPath = Path.Combine( DirectoryPath, curQtsType.ImageAccessor.ImageTileService.ServerLogoFilePath.Value);

						ImageTileService imageTileService = new ImageTileService(
							curQtsType.ImageAccessor.ImageTileService.DataSetName.Value,
							curQtsType.ImageAccessor.ImageTileService.ServerUrl.Value,
							logoPath );

						imageAccessor = new ImageAccessor(
							permDirPath,
							curQtsType.ImageAccessor.TextureSizePixels.Value,
							curQtsType.ImageAccessor.LevelZeroTileSizeDegrees.DoubleValue(),
							curQtsType.ImageAccessor.NumberLevels.Value,
							curQtsType.ImageAccessor.ImageFileExtension.Value,
							cacheDirPath,
							imageTileService);
					}
					else if(curQtsType.ImageAccessor.HasDuplicateTilePath())
					{
						string dupePath = curQtsType.ImageAccessor.DuplicateTilePath.Value;
						if(!Path.IsPathRooted(dupePath))
							dupePath = Path.Combine(DirectoryPath, dupePath);
						imageAccessor = new ImageAccessor(
							permDirPath,
							curQtsType.ImageAccessor.TextureSizePixels.Value,
							curQtsType.ImageAccessor.LevelZeroTileSizeDegrees.DoubleValue(),
							curQtsType.ImageAccessor.NumberLevels.Value,
							curQtsType.ImageAccessor.ImageFileExtension.Value,
							cacheDirPath,
							dupePath);
					}
					else
					{
						imageAccessor = new ImageAccessor(
							permDirPath,
							curQtsType.ImageAccessor.TextureSizePixels.Value,
							curQtsType.ImageAccessor.LevelZeroTileSizeDegrees.DoubleValue(),
							curQtsType.ImageAccessor.NumberLevels.Value,
							curQtsType.ImageAccessor.ImageFileExtension.Value,
							cacheDirPath);
					}

					QuadTileSet qts = new QuadTileSet(
						curQtsType.Name.Value,
						curWorld,
						curQtsType.DistanceAboveSurface.DoubleValue(),
						curQtsType.BoundingBox.North.Value2.DoubleValue(),
						curQtsType.BoundingBox.South.Value2.DoubleValue(),
						curQtsType.BoundingBox.West.Value2.DoubleValue(),
						curQtsType.BoundingBox.East.Value2.DoubleValue(),
						(curQtsType.TerrainMapped.Value ? curWorld.TerrainAccessor : null),
						imageAccessor);

					qts.TransparentColor = transparentColor;

					if(curQtsType.ShowAtStartup.Value)
						qts.IsOn = true;
					else
						qts.IsOn = false;


					if(curQtsType.HasExtendedInformation() && curQtsType.ExtendedInformation.HasToolBarImage())
					{
						try
						{
							string fileName = Path.Combine(DirectoryPath, curQtsType.ExtendedInformation.ToolBarImage.Value);
							if (File.Exists(fileName))
								qts.MetaData.Add("ToolBarImagePath", fileName);
						}
						catch
						{
							// TODO: Log or display warning
						}
					}

					rol.Add(qts);*/
				}
			}

			if(curLayerSet.HasPathList())
			{
				for(int i = 0; i < curLayerSet.PathListCount; i++)
				{
					LayerSet.Type_PathList2 newPathList = curLayerSet.GetPathListAt(i);

					PathList pl = new PathList(
						newPathList.Name.Value,
						curWorld,
						newPathList.MinDisplayAltitude.DoubleValue(),
						newPathList.MaxDisplayAltitude.DoubleValue(),
						DirectoryPath + "//" + newPathList.PathsDirectory.Value,
						newPathList.DistanceAboveSurface.DoubleValue(),
						(newPathList.HasWinColorName() ? System.Drawing.Color.FromName(newPathList.WinColorName.Value) : System.Drawing.Color.FromArgb(newPathList.RGBColor.Red.Value, newPathList.RGBColor.Green.Value, newPathList.RGBColor.Blue.Value)),
						curWorld.TerrainAccessor);

					pl.IsOn = newPathList.ShowAtStartup.Value;

					if(newPathList.HasExtendedInformation() && newPathList.ExtendedInformation.HasToolBarImage())
						pl.MetaData.Add("ToolBarImagePath", Path.Combine(DirectoryPath, newPathList.ExtendedInformation.ToolBarImage.Value));
					
					rol.Add(pl);
				}
			}

			if(curLayerSet.HasShapeFileLayer())
			{
				for(int i = 0; i < curLayerSet.ShapeFileLayerCount; i++)
				{
					LayerSet.Type_ShapeFileLayer2 newShapefileLayer = curLayerSet.GetShapeFileLayerAt(i);
					Microsoft.DirectX.Direct3D.FontDescription fd = GetLayerFontDescription(newShapefileLayer.DisplayFont);
					Microsoft.DirectX.Direct3D.Font font = worldWindow.DrawArgs.CreateFont( fd );
					ShapeLayer sp = new ShapeLayer(
						newShapefileLayer.Name.Value,
						curWorld,
						newShapefileLayer.DistanceAboveSurface.DoubleValue(),
						newShapefileLayer.MasterFilePath.Value,
						newShapefileLayer.MinimumViewAltitude.DoubleValue(),
						newShapefileLayer.MaximumViewAltitude.DoubleValue(),
						font,
						(newShapefileLayer.HasWinColorName() ? System.Drawing.Color.FromName(newShapefileLayer.WinColorName.Value) : System.Drawing.Color.FromArgb(newShapefileLayer.RGBColor.Red.Value, newShapefileLayer.RGBColor.Green.Value, newShapefileLayer.RGBColor.Blue.Value)),
						(newShapefileLayer.HasScalarKey() ? newShapefileLayer.ScalarKey.Value : null),
						(newShapefileLayer.HasShowBoundaries() ? newShapefileLayer.ShowBoundaries.Value : false),
						(newShapefileLayer.HasShowFilledRegions() ? newShapefileLayer.ShowFilledRegions.Value : false));

					sp.IsOn = newShapefileLayer.ShowAtStartup.BoolValue();

					if(newShapefileLayer.HasExtendedInformation() && newShapefileLayer.ExtendedInformation.HasToolBarImage())
						sp.MetaData.Add("ToolBarImagePath", Path.Combine(DirectoryPath, newShapefileLayer.ExtendedInformation.ToolBarImage.Value));

					rol.Add(sp);
				}
			}

			if(curLayerSet.HasIcon())
			{
				Icons icons = (Icons)rol;

				for(int i = 0; i < curLayerSet.IconCount; i++)
				{
					LayerSet.Type_Icon newIcon = curLayerSet.GetIconAt(i);

					string textureFullPath = newIcon.TextureFilePath.Value;
					if (textureFullPath.Length > 0 && !Path.IsPathRooted(textureFullPath))
						// Use absolute path to icon image
						textureFullPath = Path.Combine( DirectoryPath, newIcon.TextureFilePath.Value );

					WorldWind.Renderable.Icon ic = new WorldWind.Renderable.Icon(
						newIcon.Name.Value,
						(float)newIcon.Latitude.Value2.DoubleValue(),
						(float)newIcon.Longitude.Value2.DoubleValue(),
						(float)newIcon.DistanceAboveSurface.DoubleValue() );
					
					ic.TextureFileName = textureFullPath;
					ic.Width =	newIcon.IconWidthPixels.Value;
					ic.Height = newIcon.IconHeightPixels.Value;
					ic.IsOn = newIcon.ShowAtStartup.Value;
					if(newIcon.HasDescription())
						ic.Description = newIcon.Description.Value;
					if(newIcon.HasClickableUrl())
						ic.ClickableActionURL = newIcon.ClickableUrl.Value;
					if(newIcon.HasMaximumDisplayAltitude())
						ic.MaximumDisplayDistance = (float)newIcon.MaximumDisplayAltitude.Value;
					if(newIcon.HasMinimumDisplayAltitude())
						ic.MinimumDisplayDistance = (float)newIcon.MinimumDisplayAltitude.Value;

					icons.Add(ic);
				}
			}

			if(curLayerSet.HasTiledPlacenameSet())
			{
				for(int i = 0; i < curLayerSet.TiledPlacenameSetCount; i++)
				{
					LayerSet.Type_TiledPlacenameSet2 newPlacenames = curLayerSet.GetTiledPlacenameSetAt(i);

					string filePath = newPlacenames.PlacenameListFilePath.Value;
					if(!Path.IsPathRooted(filePath))
						filePath = Path.Combine(DirectoryPath, filePath);

					Microsoft.DirectX.Direct3D.FontDescription fd = GetLayerFontDescription(newPlacenames.DisplayFont);
					TiledPlacenameSet tps = new TiledPlacenameSet(
						newPlacenames.Name.Value,
						curWorld,
						newPlacenames.DistanceAboveSurface.DoubleValue(),
						newPlacenames.MaximumDisplayAltitude.DoubleValue(),
						newPlacenames.MinimumDisplayAltitude.DoubleValue(),
						filePath,
						fd,
						(newPlacenames.HasWinColorName() ? System.Drawing.Color.FromName(newPlacenames.WinColorName.Value) : System.Drawing.Color.FromArgb(newPlacenames.RGBColor.Red.Value, newPlacenames.RGBColor.Green.Value, newPlacenames.RGBColor.Blue.Value)),
						(newPlacenames.HasIconFilePath() ? newPlacenames.IconFilePath.Value : null));

					if(newPlacenames.HasExtendedInformation() && newPlacenames.ExtendedInformation.HasToolBarImage())
						tps.MetaData.Add("ToolBarImagePath", Path.Combine(DirectoryPath, newPlacenames.ExtendedInformation.ToolBarImage.Value));

					tps.IsOn = newPlacenames.ShowAtStartup.Value;
					rol.Add(tps);
				}
			}

			if(curLayerSet.HasChildLayerSet())
			{
				for(int i = 0; i < curLayerSet.ChildLayerSetCount; i++)
				{
					LayerSet.Type_LayerSet ls = curLayerSet.GetChildLayerSetAt(i);

					rol.Add( getRenderableObjectListFromLayerSet( curWorld, ls, layerSetFile));
				}
			}

			rol.IsOn = curLayerSet.ShowAtStartup.Value;
			return rol;
		}
Example #2
0
        public static RenderableObjectList getRenderableFromLayerFile(string layerFile, World parentWorld, Cache cache, bool enableRefresh, string layerSetSchema)
        {
            Log.Write(Log.Levels.Debug + 1, "CONF", "Loading renderable from " + layerFile);
            try
            {
                XPathDocument docNav = null;
                XPathNavigator nav = null;

                XmlReaderSettings readerSettings = new XmlReaderSettings();

                if (layerSetSchema != null && File.Exists(layerSetSchema))
                {
                    Log.Write(Log.Levels.Debug, "CONF", "validating " + layerFile + " against LayerSet.xsd");
                    readerSettings.ValidationType = ValidationType.Schema;
                    XmlSchemaSet schemas = new XmlSchemaSet();
                    schemas.Add(null, layerSetSchema);

                    readerSettings.Schemas = schemas;
                    readerSettings.ValidationEventHandler += new ValidationEventHandler(XMLValidationCallback);
                    readerSettings.ValidationFlags |= System.Xml.Schema.XmlSchemaValidationFlags.ReportValidationWarnings;
                }
                else
                {
                    Log.Write(Log.Levels.Debug, "CONF", "loading " + layerFile + " without validation");
                    readerSettings.ValidationType = ValidationType.None;
                }

                try
                {
                    if (layerFile.IndexOf(@"http://") < 0)
                    {
                        XmlReader docReader = XmlReader.Create(layerFile, readerSettings);
                        docNav = new XPathDocument(docReader);
                        docReader.Close();
                    }
                    else
                    {
                        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 = layerFile.IndexOf("?");
                        if (flag == -1)
                            layerFile = layerFile + "?BBOX=" + viewBBox;
                        else
                            layerFile = layerFile + "&BBOX=" + viewBBox;

                        WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(layerFile);
                        download.DownloadMemory();

                        XmlReader docReader = XmlReader.Create(download.ContentStream, readerSettings);
                        docNav = new XPathDocument(docReader);
                        docReader.Close();
                    }

                    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", "");
                    redirect = redirect.Replace("${WORLDWINDVERSION}", System.Windows.Forms.Application.ProductVersion);
                    string redirectWithoutBBOX = 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;

                            WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(redirect);

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

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

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

                            download.DownloadFile(tempDownloadFile.FullName, WorldWind.Net.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(redirectWithoutBBOX);
                            }
                        }
                        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);
                            }
                            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", ""));
                            }
                            else
                            {
                                parentRenderable = new RenderableObjectList(iter.Current.GetAttribute("Name", ""));
                            }
                        }

                        parentRenderable.ParentList = parentWorld.RenderableObjects;
                        parentRenderable.IsOn = ParseBool(iter.Current.GetAttribute("ShowAtStartup", ""));

                        string description = getInnerTextFromFirstChild(iter.Current.Select("Description"));
                        if (description != null && description.Length > 0)
                            parentRenderable.Description = description;

                        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, System.Globalization.CultureInfo.InvariantCulture) == 0)
                            {
                                parentRenderable.RenderPriority = RenderPriority.Icons;
                            }
                            else if (String.Compare(renderPriorityString, "LinePaths", false, System.Globalization.CultureInfo.InvariantCulture) == 0)
                            {
                                parentRenderable.RenderPriority = RenderPriority.LinePaths;
                            }
                            else if (String.Compare(renderPriorityString, "Placenames", false, System.Globalization.CultureInfo.InvariantCulture) == 0)
                            {
                                parentRenderable.RenderPriority = RenderPriority.Placenames;
                            }
                            else if (String.Compare(renderPriorityString, "AtmosphericImages", false, System.Globalization.CultureInfo.InvariantCulture) == 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);
                            }
                        }

                        addTiledWFSPlacenameSet(iter.Current.Select("TiledWFSPlacenameSet"), parentWorld, parentRenderable, cache);
                        addExtendedInformation(iter.Current.Select("ExtendedInformation"), parentRenderable);

                        if (parentRenderable.RefreshTimer != null && enableRefresh)
                        {
                            parentRenderable.RefreshTimer.Start();
                        }
                        return parentRenderable;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                //Log.Write(Log.Levels.Debug, layerFile);
            }
            Log.Write(Log.Levels.Warning, "CONF", "WARNING: no renderable created for " + layerFile);

            return null;
        }
		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 ConfigurationLoader.getRenderableFromLayerFile(redirect, parentWorld, cache);
					}

					RenderableObjectList rol = new RenderableObjectList(layerName);
					if(iter.Current.Select("Icon").Count > 0)
					{
						rol = new Icons(layerName);
					}
					
					rol.ParentList = parentRenderable;

					if(World.Settings.useDefaultLayerStates)
					{
						rol.IsOn = showAtStartup;
					}
					else
					{
						rol.IsOn = IsLayerOn(rol);
					}

					string disableExpansionString = iter.Current.GetAttribute("DisableExpansion", "");
					if(disableExpansionString != null)
					{
						rol.DisableExpansion = ParseBool(disableExpansionString);
					}


					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, System.Globalization.CultureInfo.InvariantCulture) == 0)
						{
							rol.RenderPriority = RenderPriority.Icons;
						}
                        else if (String.Compare(renderPriorityString, "LinePaths", false, System.Globalization.CultureInfo.InvariantCulture) == 0)
						{
							rol.RenderPriority = RenderPriority.LinePaths;
						}
                        else if (String.Compare(renderPriorityString, "Placenames", false, System.Globalization.CultureInfo.InvariantCulture) == 0)
						{
							rol.RenderPriority = RenderPriority.Placenames;
						}
                        else if (String.Compare(renderPriorityString, "AtmosphericImages", false, System.Globalization.CultureInfo.InvariantCulture) == 0)
						{
							rol.RenderPriority = RenderPriority.AtmosphericImages;
						}
					}

					string description = getInnerTextFromFirstChild(iter.Current.Select("Description"));
					if(description != null && description.Length > 0)
						rol.Description = description;

					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);

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

			return null;
		}
Example #4
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;
        }
Example #5
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;
        }
Example #6
0
        private static RenderableObject Construct(String strRelativeDirectory, KMLObject oSource, World oWorld, GeographicBoundingBox oBounds, ProjectedVectorRenderer oPVR, Icons oIcons)
        {
            if (oSource is KMLContainer)
            {
                KMLContainer oCastSource = oSource as KMLContainer;
                KMLRenderableObjectList result = new KMLRenderableObjectList(oCastSource.Name);

                if (oPVR == null)
                {
                    oPVR = new ProjectedVectorRenderer("Polygons and LineStrings", oWorld);
                    result.Add(oPVR);
                }
                if (oIcons == null)
                {
                    oIcons = new Icons("Icons");
                    result.Add(oIcons);
                }

                for (int count = 0; count < oCastSource.Count; count++)
                {
                    if (oCastSource[count].Visibility == true)
                    {
                        RenderableObject oLayer = Construct(strRelativeDirectory, oCastSource[count], oWorld, oBounds, oPVR, oIcons);
                        if (oLayer != null)
                        {
                            result.Add(oLayer);
                        }
                    }
                }
                return result;
            }
            else if (oSource is KMLPlacemark)
            {
                KMLPlacemark oCastSource = oSource as KMLPlacemark;
                return Construct(strRelativeDirectory, oCastSource.Geometry, oWorld, oBounds, oPVR, oIcons);
            }
            else if (oSource is KMLMultiGeometry)
            {
                KMLMultiGeometry oCastSource = oSource as KMLMultiGeometry;
                KMLRenderableObjectList result = new KMLRenderableObjectList("MultiGeometry");
                for (int count = 0; count < oCastSource.Count; count++)
                {
                    RenderableObject oLayer = Construct(strRelativeDirectory, oCastSource[count], oWorld, oBounds, oPVR, oIcons);
                    if (oLayer != null)
                    {
                        result.Add(oLayer);
                    }
                }
                return result;
            }
            else if (oSource is KMLPoint)
            {
                KMLPoint oCastSource = oSource as KMLPoint;

                KMLIcon result = new KMLIcon(oCastSource.Owner.Name, oCastSource.Coordinates.Latitude, oCastSource.Coordinates.Longitude, oCastSource.Coordinates.Altitude);
                result.DrawGroundStick = oCastSource.Extrude;
                result.Rotation = WorldWind.Angle.FromDegrees(oCastSource.Style.NormalStyle.IconStyle.Heading);
                result.IsRotated = oCastSource.Style.NormalStyle.IconStyle.Heading != 0.0f;
                result.NormalColor = oCastSource.Style.NormalStyle.LabelStyle.Color;
                result.HotColor = oCastSource.Style.HighlightStyle.LabelStyle.Color;
                oIcons.Add(result);

                oBounds.Union(oCastSource.Coordinates.Longitude, oCastSource.Coordinates.Latitude, oCastSource.Coordinates.Altitude);
                return null;
            }
            else if (oSource is KMLPolygon)
            {
                KMLPolygon oCastSource = oSource as KMLPolygon;

                Polygon oTool = new Polygon();
                oTool.outerBoundary = new WorldWind.LinearRing(GetPoints(oCastSource.OuterBoundary));
                oTool.innerBoundaries = GetInnerBoundaries(oCastSource);
                oTool.PolgonColor = oCastSource.Style.NormalStyle.PolyStyle.Color;
                oTool.Fill = oCastSource.Style.NormalStyle.PolyStyle.Fill;
                oTool.LineWidth = oCastSource.Style.NormalStyle.LineStyle.Width;
                oTool.Outline = oCastSource.Style.NormalStyle.PolyStyle.Outline;
                oTool.OutlineColor = oCastSource.Style.NormalStyle.LineStyle.Color;
                oPVR.Add(oTool);

                oBounds.Union(oTool.GetGeographicBoundingBox());
                return null;
            }
            else if (oSource is KMLLineString)
            {
                KMLLineString oCastSource = oSource as KMLLineString;

                LineString oTool = new LineString();
                oTool.Coordinates = GetPoints(oCastSource);
                oTool.Color = oCastSource.Style.NormalStyle.LineStyle.Color;
                oTool.LineWidth = oCastSource.Style.NormalStyle.LineStyle.Width;
                oPVR.Add(oTool);

                oBounds.Union(oTool.GetGeographicBoundingBox());
                return null;
            }
            else if (oSource is KMLGroundOverlay)
            {
                KMLGroundOverlay oCastSource = oSource as KMLGroundOverlay;

                KMLGroundOverlayRenderable result = new KMLGroundOverlayRenderable(oCastSource, strRelativeDirectory);
                oBounds.Union(new GeographicBoundingBox(oCastSource.LatLonBox.North, oCastSource.LatLonBox.South, oCastSource.LatLonBox.West, oCastSource.LatLonBox.East));
                return result;
            }
            else
            {
                return null;
            }
        }