Пример #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;
		}
Пример #2
0
      // utility function - given a layerset, add all its placenamesets to the above collection, recursing into child layers
      private void collectTiledPlacenamesSets(LayerSet.Type_LayerSet curLayerSet)
      {
         if(curLayerSet.HasTiledPlacenameSet()) // any placenames at all?
         {
            // yes, iterate over them
            for(int i = 0; i < curLayerSet.TiledPlacenameSetCount; i++)
            {
               // get tilesplacenameset
               LayerSet.Type_TiledPlacenameSet2 tpns = curLayerSet.GetTiledPlacenameSetAt(i);

               // compute full path to wpl file - WplIndex constructor needs this
               string wplFullPath = Path.Combine(MainApplication.DirectoryPath, tpns.PlacenameListFilePath.Value);

               // build an index descriptor (does not create or load the index yet)
               WplIndex idx = new WplIndex(tpns, wplFullPath);

               // an indexedTilePlacenameSet associates the index descriptor with the placenameset
               IndexedTiledPlaceNameSet ipns = new IndexedTiledPlaceNameSet(tpns, idx);

               // add them to our collection
               this.indexedTiledPlacenameSets.Add(ipns);
            }
         }
			
         // now recurse into child layers of this set and do the same
         if(curLayerSet.HasChildLayerSet())
         {
            for(int i = 0; i < curLayerSet.ChildLayerSetCount; i++)
            {
               this.collectTiledPlacenamesSets(curLayerSet.GetChildLayerSetAt(i));
            }
         }
      }