Exemple #1
0
        private ImageSource GetPreviewSourceFromStyle(Style style)
        {
            if (style != null)
            {
                System.Drawing.Bitmap nativeImage  = new System.Drawing.Bitmap(20, 20);
                MemoryStream          streamSource = new MemoryStream();

                try
                {
                    var geoCanvas = new PlatformGeoCanvas();
                    geoCanvas.BeginDrawing(nativeImage, new RectangleShape(-10, 10, 10, -10), GeographyUnit.DecimalDegree);
                    geoCanvas.Clear(new GeoSolidBrush(GeoColor.StandardColors.White));
                    style.DrawSample(geoCanvas);
                    geoCanvas.EndDrawing();

                    nativeImage.Save(streamSource, System.Drawing.Imaging.ImageFormat.Png);
                    BitmapImage imageSource = new BitmapImage();
                    imageSource.BeginInit();
                    imageSource.StreamSource = streamSource;
                    imageSource.EndInit();

                    return(imageSource);
                }
                catch (Exception ex)
                {
                    GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                    return(new BitmapImage());
                }
                finally
                {
                    nativeImage.Dispose();
                }
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
        public GeoImage ToGeoImage(RectangleShape worldExtent, GeographyUnit drawingMapUnit)
        {
            // only support SingleTile mode, otherwise return the background image directly
            if (TileType != TileType.SingleTile)
            {
                if (BackgroundImage == null)
                {
                    return(null);
                }
                else
                {
                    return(new GeoImage(BackgroundImage.GetImageStream()));
                }
            }

            // find any layer tiles in this overlay
            var layerTiles = new List <LayerTile>();

            foreach (var overlayUIElement in OverlayCanvas.Children)
            {
                if (overlayUIElement is Canvas)
                {
                    foreach (var canvasUIElement in (overlayUIElement as Canvas).Children)
                    {
                        if (canvasUIElement is LayerTile)
                        {
                            layerTiles.Add(canvasUIElement as LayerTile);
                        }
                    }
                }
            }

            GeoImage geoImage = null;

            if (layerTiles.Count > 0)
            {
                int width  = Convert.ToInt32(layerTiles.First().ActualWidth);
                int height = Convert.ToInt32(layerTiles.First().ActualHeight);
                if (width > 0 && height > 0)
                {
                    // initialize geoCanvas by using current BackgroundImage
                    var geoCanvas = new PlatformGeoCanvas();
                    if (BackgroundImage == null)
                    {
                        geoImage = new GeoImage(width, height);
                        geoCanvas.BeginDrawing(geoImage, worldExtent, drawingMapUnit);
                        geoCanvas.Clear(new GeoSolidBrush(GeoColors.Transparent));
                    }
                    else
                    {
                        geoImage = new GeoImage(BackgroundImage.GetImageStream());
                        geoCanvas.BeginDrawing(geoImage, worldExtent, drawingMapUnit);
                    }

                    // draw each layer tiles
                    foreach (var layerTile in layerTiles)
                    {
                        layerTile.Draw(geoCanvas);
                    }

                    geoCanvas.EndDrawing();
                }
            }

            return(geoImage);
        }