Exemple #1
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));
                }
            }
        }
Exemple #2
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() == "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(PluginEngineGlobal.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(PluginEngineGlobal.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);
                }
            }

            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(),
                        PluginEngineGlobal.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(PluginEngineGlobal.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   = Global.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(PluginEngineGlobal.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(PluginEngineGlobal.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(PluginEngineGlobal.DirectoryPath, filePath);
                    }

                    Microsoft.DirectX.Direct3D.FontDescription fd = Global.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(PluginEngineGlobal.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);
        }
Exemple #3
0
		private void ProcessWmsEncodedUri()
		{
			//first parse the rawUri string looking for "functions"
			string uri = worldWindUri.RawUrl.Substring(12, worldWindUri.RawUrl.Length - 12);
			uri = uri.Replace("wmsimage=", "wmsimage|");
			uri = uri.Replace("&wmsimage", "#wmsimage");
			string[] uriFunctions = uri.Split('#');

			foreach(string uriFunction in uriFunctions)
			{
				string[] paramValuePair = uriFunction.Split('|');

				if(String.Compare(paramValuePair[0], "wmsimage", true, CultureInfo.InvariantCulture) == 0)
				{
					string displayName = null;
					int transparencyPercent = 0;
					double heightAboveSurface = 0.0;
					string wmslink = "";
					string[] wmsImageParams = new string[0];
					if(paramValuePair[1].IndexOf("://") > 0)
					{
						wmsImageParams = paramValuePair[1].Replace("%26", "|").Split('|');
					}
					else
					{
						wmsImageParams = System.Web.HttpUtility.UrlDecode(paramValuePair[1]).Replace("%26", "|").Split('|');
					}
					foreach(string p in wmsImageParams)
					{
						string new_p = p.Replace("%3d", "|");
						char[] deliminator = new char[1] {'|'};
						string[] functionParam = new_p.Split(deliminator, 2);

						if(String.Compare(functionParam[0], "displayname", true, CultureInfo.InvariantCulture) == 0)
						{
							displayName = functionParam[1];
						}
						else if(String.Compare(functionParam[0], "transparency", true, CultureInfo.InvariantCulture) == 0)
						{
							transparencyPercent = Int32.Parse(functionParam[1], CultureInfo.InvariantCulture);
						}
						else if(String.Compare(functionParam[0], "altitude", true, CultureInfo.InvariantCulture) == 0)
						{
							heightAboveSurface = Double.Parse(functionParam[1], CultureInfo.InvariantCulture);
						}
						else if(String.Compare(functionParam[0], "link", true, CultureInfo.InvariantCulture) == 0)
						{
							wmslink = functionParam[1];
							if(wmslink.EndsWith("/"))
								wmslink = wmslink.Substring(0, wmslink.Length - 1);
						}
					}

					try
					{
						string[] wmslinkParams = wmslink.Split('?')[1].Split('&');

						string wmsLayerName = null;
						LayerSet.Type_LatitudeCoordinate2 bb_north = new LayerSet.Type_LatitudeCoordinate2();
						LayerSet.Type_LatitudeCoordinate2 bb_south = new LayerSet.Type_LatitudeCoordinate2();
						LayerSet.Type_LongitudeCoordinate2 bb_west = new LayerSet.Type_LongitudeCoordinate2();
						LayerSet.Type_LongitudeCoordinate2 bb_east = new LayerSet.Type_LongitudeCoordinate2();

						foreach(string wmslinkParam in wmslinkParams)
						{
							string linkParamUpper = wmslinkParam.ToUpper(CultureInfo.InvariantCulture);
							if(linkParamUpper.IndexOf("BBOX") >= 0)
							{
								string[] bb_parts = wmslinkParam.Split('=')[1].Split(',');
								bb_west.AddValue2(new LayerSet.ValueType4(bb_parts[0]));
								bb_south.AddValue2(new LayerSet.ValueType3(bb_parts[1]));
								bb_east.AddValue2(new LayerSet.ValueType4(bb_parts[2]));
								bb_north.AddValue2(new LayerSet.ValueType3(bb_parts[3]));
							}
							else if(linkParamUpper.IndexOf("LAYERS") >= 0)
							{
								wmsLayerName = wmslinkParam.Split('=')[1];
							}
						}

						string path = String.Format(CultureInfo.InvariantCulture,
							@"{0}\{1}\___DownloadedWMSImages.xml", Settings.ConfigPath, "");//this.currentWorld.LayerDirectory.Value);
						
						string texturePath = string.Format(CultureInfo.InvariantCulture,
							@"{0}\Data\DownloadedWMSImages\{1}", DirectoryPath, System.DateTime.Now.ToFileTimeUtc());

						if(!File.Exists(path))
						{
							LayerSet.LayerSetDoc newDoc = new LayerSet.LayerSetDoc();
							LayerSet.Type_LayerSet root = new LayerSet.Type_LayerSet();

							root.AddName(new LayerSet.NameType2("Downloaded WMS Images"));
							root.AddShowAtStartup(new Altova.Types.SchemaBoolean(true));
							root.AddShowOnlyOneLayer(new Altova.Types.SchemaBoolean(false));
							newDoc.SetRootElementName("", "LayerSet");
							newDoc.Save(path, root);
						}

						LayerSet.LayerSetDoc doc = new LayerSet.LayerSetDoc();
						LayerSet.Type_LayerSet curRoot = new LayerSet.Type_LayerSet(doc.Load(path));

						if(displayName == null)
						{
							displayName = wmslink.Split('?')[0] + " - " + wmsLayerName + " : " + System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToLongTimeString();
						}

						for(int i = 0; i < curRoot.ImageLayerCount; i++)
						{
							LayerSet.Type_ImageLayer curImageLayerType = (LayerSet.Type_ImageLayer)curRoot.GetImageLayerAt(i);
							if(curImageLayerType.Name.Value.Equals(displayName))
							{
								displayName += String.Format(CultureInfo.CurrentCulture, " : {0} {1}", System.DateTime.Now.ToShortDateString(), System.DateTime.Now.ToLongTimeString());
							}
						}

						LayerSet.Type_ImageLayer newImageLayer = new LayerSet.Type_ImageLayer();
						newImageLayer.AddShowAtStartup(new Altova.Types.SchemaBoolean(false));

						if(bb_north.Value2.DoubleValue() - bb_south.Value2.DoubleValue() > 90 ||
							bb_east.Value2.DoubleValue() - bb_west.Value2.DoubleValue() > 90)
							heightAboveSurface = 10000.0;

						newImageLayer.AddName(new LayerSet.NameType(
							displayName));
						newImageLayer.AddDistanceAboveSurface( new Altova.Types.SchemaDecimal(heightAboveSurface));

						LayerSet.Type_LatLonBoundingBox2 bb = new LayerSet.Type_LatLonBoundingBox2();

						bb.AddNorth(bb_north);
						bb.AddSouth(bb_south);
						bb.AddWest(bb_west);
						bb.AddEast(bb_east);
						newImageLayer.AddBoundingBox(bb);
						newImageLayer.AddTexturePath(new Altova.Types.SchemaString(
							texturePath));

						byte opacityValue = (byte)((100.0 - transparencyPercent) * 0.01 * 255);
						newImageLayer.AddOpacity(new LayerSet.OpacityType( opacityValue.ToString(CultureInfo.InvariantCulture)));
						newImageLayer.AddTerrainMapped(new Altova.Types.SchemaBoolean(false));

						curRoot.AddImageLayer(newImageLayer);
						doc.Save(path, curRoot);

						ImageLayer newLayer = new ImageLayer(
							displayName,
							this.worldWindow.CurrentWorld,
							(float)heightAboveSurface,
							texturePath,
							(float)bb_south.Value2.DoubleValue(),
							(float)bb_north.Value2.DoubleValue(),
							(float)bb_west.Value2.DoubleValue(),
							(float)bb_east.Value2.DoubleValue(),
							0.01f * (100.0f - transparencyPercent),
							this.worldWindow.CurrentWorld.TerrainAccessor);
						newLayer.ImageUrl = wmslink;

						RenderableObjectList downloadedImagesRol = (RenderableObjectList)this.worldWindow.CurrentWorld.RenderableObjects.GetObject("Downloaded WMS Images");
						if(downloadedImagesRol == null)
							downloadedImagesRol = new RenderableObjectList("Downloaded WMS Images");

						this.worldWindow.CurrentWorld.RenderableObjects.Add(newLayer);

						worldWindUri.Latitude = Angle.FromDegrees(0.5 * (bb_north.Value2.DoubleValue() + bb_south.Value2.DoubleValue()));
						worldWindUri.Longitude = Angle.FromDegrees(0.5 * (bb_west.Value2.DoubleValue() + bb_east.Value2.DoubleValue()));

						if(bb_north.Value2.DoubleValue() - bb_south.Value2.DoubleValue() > bb_east.Value2.DoubleValue() - bb_west.Value2.DoubleValue())
							worldWindUri.ViewRange = Angle.FromDegrees(bb_north.Value2.DoubleValue() - bb_south.Value2.DoubleValue());
						else
							worldWindUri.ViewRange = Angle.FromDegrees(bb_east.Value2.DoubleValue() - bb_west.Value2.DoubleValue());

						if(worldWindUri.ViewRange.Degrees > 180)
							worldWindUri.ViewRange = Angle.FromDegrees(180);

						System.Threading.Thread.Sleep(10);
					}
					catch
					{}
				}
			}
		}