Beispiel #1
0
        public bool DownLoadImage(DrawArgs drawArgs)
        {
            if (this.imageLayer != null || (this.downloadThread != null && this.downloadThread.IsAlive))
            {
                return(false);
            }

            this.LoadImage = true;
            this.drawArgs  = drawArgs;
            //download the thing...
            if (!this.IsTextureAvailable)
            {
                this.downloadThread              = new Thread(new ThreadStart(this.DownloadImage));
                this.downloadThread.Name         = "DownloadableImageFromIconSet.DownloadImage";
                this.downloadThread.IsBackground = true;
                this.downloadThread.Start();
            }
            else
            {
                this.imageLayer = new ImageLayer(this.Name, this.m_ParentWorld,
                                                 this.layerRadius - (float)this.m_ParentWorld.EquatorialRadius, this.saveTexturePath, this.south, this.north, this.west, this.east, 255, this._terrainAccessor);
            }
            return(true);
        }
Beispiel #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);
        }
Beispiel #3
0
        private void UpdateImageLayers(DrawArgs drawArgs)
        {
            try
            {
                this.m_LastUpdate = DateTime.Now;

                if (this.m_NwImageLayer != null)
                {
                    this.m_NwImageLayer.Dispose();
                }

                if (this.m_NeImageLayer != null)
                {
                    this.m_NeImageLayer.Dispose();
                }

                if (this.m_SwImageLayer != null)
                {
                    this.m_SwImageLayer.Dispose();
                }

                if (this.m_SeImageLayer != null)
                {
                    this.m_SeImageLayer.Dispose();
                }

                double centerLatitude  = 0.5 * (this.m_geographicBoundingBox.North + this.m_geographicBoundingBox.South);
                double centerLongitude = 0.5 * (this.m_geographicBoundingBox.West + this.m_geographicBoundingBox.East);

                this.m_NwImageLayer = this.CreateImageLayer(this.m_geographicBoundingBox.North, centerLatitude, this.m_geographicBoundingBox.West, centerLongitude, drawArgs,
                                                            String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds",
                                                                          null, //ShapeTile.CachePath,
                                                                          "R",  //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer),
                                                                          this.Level + 1,
                                                                          2 * this.Row + 1,
                                                                          2 * this.Col));

                this.m_NeImageLayer = this.CreateImageLayer(this.m_geographicBoundingBox.North, centerLatitude, centerLongitude, this.m_geographicBoundingBox.East, drawArgs,
                                                            String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds",
                                                                          null, //ShapeTile.CachePath,
                                                                          "R",  //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer),
                                                                          this.Level + 1,
                                                                          2 * this.Row + 1,
                                                                          2 * this.Col + 1));

                this.m_SwImageLayer = this.CreateImageLayer(centerLatitude, this.m_geographicBoundingBox.South, this.m_geographicBoundingBox.West, centerLongitude, drawArgs,
                                                            String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds",
                                                                          null, //ShapeTile.CachePath,
                                                                          "R",  //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer),
                                                                          this.Level + 1,
                                                                          2 * this.Row,
                                                                          2 * this.Col));

                this.m_SeImageLayer = this.CreateImageLayer(centerLatitude, this.m_geographicBoundingBox.South, centerLongitude, this.m_geographicBoundingBox.East, drawArgs,
                                                            String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds",
                                                                          null, //ShapeTile.CachePath,
                                                                          "R",  //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer),
                                                                          this.Level + 1,
                                                                          2 * this.Row,
                                                                          2 * this.Col + 1));

                if (this.m_NwImageLayer != null)
                {
                    this.m_NwImageLayer.Initialize(drawArgs);
                }
                if (this.m_NeImageLayer != null)
                {
                    this.m_NeImageLayer.Initialize(drawArgs);
                }
                if (this.m_SwImageLayer != null)
                {
                    this.m_SwImageLayer.Initialize(drawArgs);
                }
                if (this.m_SeImageLayer != null)
                {
                    this.m_SeImageLayer.Initialize(drawArgs);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Beispiel #4
0
        /*public byte Opacity
         * {
         *      get
         *      {
         *              return m_parentProjectedLayer.Opacity;
         *      }
         *      set
         *      {
         *              if(m_NwImageLayer != null)
         *              {
         *                      m_NwImageLayer.Opacity = value;
         *              }
         *              if(m_NeImageLayer != null)
         *              {
         *                      m_NeImageLayer.Opacity = value;
         *              }
         *              if(m_SwImageLayer != null)
         *              {
         *                      m_SwImageLayer.Opacity = value;
         *              }
         *              if(m_SeImageLayer != null)
         *              {
         *                      m_SeImageLayer.Opacity = value;
         *              }
         *
         *              if(m_NorthWestChild != null)
         *              {
         *                      m_NorthWestChild.Opacity = value;
         *              }
         *              if(m_NorthEastChild != null)
         *              {
         *                      m_NorthEastChild.Opacity = value;
         *              }
         *              if(m_SouthWestChild != null)
         *              {
         *                      m_SouthWestChild.Opacity = value;
         *              }
         *              if(m_SouthEastChild != null)
         *              {
         *                      m_SouthEastChild.Opacity = value;
         *              }
         *      }
         * }*/

        private ImageLayer CreateImageLayer(double north, double south, double west, double east, DrawArgs drawArgs, string imagePath)
        {
            Bitmap                b          = null;
            Graphics              g          = null;
            ImageLayer            imageLayer = null;
            GeographicBoundingBox geoBB      = new GeographicBoundingBox(north, south, west, east);
            int numberPolygonsInTile         = 0;

            FileInfo imageFile = new FileInfo(imagePath);

            if (!this.m_parentProjectedLayer.EnableCaching ||
                !imageFile.Exists
                )
            {
                if (this.m_parentProjectedLayer.LineStrings != null)
                {
                    for (int i = 0; i < this.m_parentProjectedLayer.LineStrings.Length; i++)
                    {
                        if (!this.m_parentProjectedLayer.LineStrings[i].Visible)
                        {
                            continue;
                        }

                        GeographicBoundingBox currentBoundingBox = this.m_parentProjectedLayer.LineStrings[i].GetGeographicBoundingBox();

                        if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB))
                        {
                            continue;
                        }
                        else
                        {
                            if (b == null)
                            {
                                b = new Bitmap(this.m_parentProjectedLayer.TileSize.Width, this.m_parentProjectedLayer.TileSize.Height,
                                               System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            }

                            if (g == null)
                            {
                                g = Graphics.FromImage(b);
                            }

                            this.drawLineString(this.m_parentProjectedLayer.LineStrings[i],
                                                g,
                                                geoBB,
                                                b.Size
                                                );

                            numberPolygonsInTile++;
                        }
                    }
                }

                if (this.m_parentProjectedLayer.Polygons != null)
                {
                    for (int i = 0; i < this.m_parentProjectedLayer.Polygons.Length; i++)
                    {
                        if (!this.m_parentProjectedLayer.Polygons[i].Visible)
                        {
                            continue;
                        }

                        GeographicBoundingBox currentBoundingBox = this.m_parentProjectedLayer.Polygons[i].GetGeographicBoundingBox();

                        if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB))
                        {
                            continue;
                        }
                        else
                        {
                            if (b == null)
                            {
                                b = new Bitmap(this.m_parentProjectedLayer.TileSize.Width, this.m_parentProjectedLayer.TileSize.Height,
                                               System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            }

                            if (g == null)
                            {
                                g = Graphics.FromImage(b);
                            }

                            this.drawPolygon(this.m_parentProjectedLayer.Polygons[i],
                                             g,
                                             geoBB,
                                             b.Size);

                            numberPolygonsInTile++;
                        }
                    }
                }
            }

            if (b != null)
            {
                System.Drawing.Imaging.BitmapData srcInfo = b.LockBits(new Rectangle(0, 0,
                                                                                     b.Width, b.Height),
                                                                       System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                                                       System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                bool isBlank = true;
                unsafe
                {
                    int *srcPointer = (int *)srcInfo.Scan0;
                    for (int i = 0; i < b.Height; i++)
                    {
                        for (int j = 0; j < b.Width; j++)
                        {
                            int color = *srcPointer++;

                            if (((color >> 24) & 0xff) > 0)
                            {
                                isBlank = false;
                                break;
                            }
                        }

                        srcPointer += (srcInfo.Stride >> 2) - b.Width;
                    }
                }

                b.UnlockBits(srcInfo);
                if (isBlank)
                {
                    numberPolygonsInTile = 0;
                }
            }

            //	if(!m_parentProjectedLayer.EnableCaching)
            //	{
            string id = DateTime.Now.Ticks.ToString();

            if (b != null && numberPolygonsInTile > 0)
            {
                MemoryStream ms = new MemoryStream();
                b.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                //must copy original stream into new stream, if not, error occurs, not sure why
                this.m_ImageStream = new MemoryStream(ms.GetBuffer());

                imageLayer = new ImageLayer(
                    id, this.m_parentProjectedLayer.World,
                    0, this.m_ImageStream,
                    Color.Black.ToArgb(),
                    (float)south,
                    (float)north,
                    (float)west,
                    (float)east,
                    1.0f                            //(float)m_parentProjectedLayer.Opacity / 255.0f
                    , this.m_parentProjectedLayer.World.TerrainAccessor);

                ms.Close();
            }

            /*	}
             *      else if(imageFile.Exists || numberPolygonsInTile > 0)
             *      {
             *              string id = System.DateTime.Now.Ticks.ToString();
             *
             *              if(b != null)
             *              {
             *                      MemoryStream ms = new MemoryStream();
             *                      b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
             *                      if(!imageFile.Directory.Exists)
             *                              imageFile.Directory.Create();
             *
             *                      //must copy original stream into new stream, if not, error occurs, not sure why
             *                      m_ImageStream = new MemoryStream(ms.GetBuffer());
             *                      ImageHelper.ConvertToDxt3(m_ImageStream, imageFile.FullName);
             *
             *                      ms.Close();
             *              }
             *
             *              imageLayer = new WorldWind.Renderable.ImageLayer(
             *                      id,
             *                      m_parentProjectedLayer.World,
             *                      0,
             *                      imageFile.FullName,
             *                      //System.Drawing.Color.Black.ToArgb(),
             *                      (float)south,
             *                      (float)north,
             *                      (float)west,
             *                      (float)east,
             *                      1.0f,//(float)m_parentProjectedLayer.Opacity / 255.0f,
             *                      m_parentProjectedLayer.World.TerrainAccessor);
             *
             *              imageLayer.TransparentColor = System.Drawing.Color.Black.ToArgb();
             *      }
             */
            if (b != null)
            {
                b.Dispose();
            }
            if (g != null)
            {
                g.Dispose();
            }

            b = null;
            g = null;

            //might not be necessary
            //GC.Collect();

            return(imageLayer);
        }