Ejemplo n.º 1
0
        private static void DrawStyleSamples(Style style, int width, int height, PlatformGeoCanvas canvas)
        {
            var drawingRectangleF = new DrawingRectangleF(width * .5f, height * .5f, width, height);

            if (style is CompositeStyle)
            {
                foreach (var subStyle in ((CompositeStyle)style).Styles)
                {
                    DrawStyleSamples(subStyle, width, height, canvas);
                }
            }
            else if (style is ClassBreakStyle || style is ValueStyle || style is FilterStyle)
            {
                style.DrawSample(canvas, drawingRectangleF);
            }
            else if (style is DotDensityStyle)
            {
                var dotDensityStyle = ((DotDensityStyle)style).CustomPointStyle;
                DrawDotDensityStyle(dotDensityStyle, canvas, drawingRectangleF);
            }

            //RegexStyle is the Filter Style in Gis Editor
            else if (style is RegexStyle)
            {
                DrawStaticImage(canvas, "pack://,,,/GisEditorPluginCore;component/Images/FilterStyle.png", drawingRectangleF);
            }
            else
            {
                DrawNormalStyle(style, canvas, drawingRectangleF);
            }
        }
        private void DataGridViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "FontPreview" || e.PropertyName == "AddingColumnName" || e.PropertyName == "RemovingColumnName")
            {
                return;
            }
            LabelPrinterLayer labelPrinterLayer = GetLabelPrinterLayer();

            using (Bitmap bitmap = new Bitmap(311, 60))
            {
                PlatformGeoCanvas canvas = new PlatformGeoCanvas();
                canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.Meter);

                labelPrinterLayer.SafeProcess(() =>
                {
                    labelPrinterLayer.Draw(canvas, new System.Collections.ObjectModel.Collection <SimpleCandidate>());
                });

                canvas.EndDrawing();
                MemoryStream ms = new MemoryStream();
                bitmap.Save(ms, ImageFormat.Png);
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = ms;
                bitmapImage.EndInit();
                FontPreview = bitmapImage;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method overrides from its base class TileOverlay.
        /// It actually requests image for the passed tile with the passed world extent.
        /// </summary>
        /// <param name="tile">A tile object that creating by the GetTileCore method. It's the tile which needs to be draw in this mehtod.</param>
        /// <param name="targetExtent">A world extent that to draw the passed tile object.</param>
        protected override void DrawTileCore(Wpf.Tile tile, RectangleShape targetExtent)
        {
            LayerTile layerTile = tile as LayerTile;

            if (layerTile != null)
            {
                layerTile.TileCache = TileCache;
                layerTile.DrawingLayers.Clear();
                layerTile.DrawingLayers.Add(wktLayer);

                Bitmap            nativeImage = new Bitmap((int)tile.Width, (int)tile.Height);
                PlatformGeoCanvas geoCanvas   = new PlatformGeoCanvas();
                geoCanvas.BeginDrawing(nativeImage, targetExtent, MapArguments.MapUnit);
                if (tile.IsAsync)
                {
                    layerTile.DrawAsync(geoCanvas);
                }
                else
                {
                    layerTile.Draw(geoCanvas);
                    geoCanvas.EndDrawing();
                    layerTile.CommitDrawing(geoCanvas, MapUtils.GetImageSourceFromNativeImage(nativeImage));
                }
            }
        }
 private void ScaleBarViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName != "Preview")
     {
         ScaleBarPrinterLayer scaleBarPrinterLayer = new ScaleBarPrinterLayer(MapPrinterLayer);
         scaleBarPrinterLayer.BackgroundMask          = Background as AreaStyle;
         scaleBarPrinterLayer.BarBrush                = Color;
         scaleBarPrinterLayer.AlternateBarBrush       = AlternatingColor;
         scaleBarPrinterLayer.TextStyle.NumericFormat = NumericFormatString;
         scaleBarPrinterLayer.UnitFamily              = SelectedUnitSystem;
         scaleBarPrinterLayer.DragMode                = DragMode;
         scaleBarPrinterLayer.ResizeMode              = ResizeMode;
         scaleBarPrinterLayer.Open();
         scaleBarPrinterLayer.MapUnit = MapPrinterLayer.MapUnit;
         scaleBarPrinterLayer.SetPosition(1.25, .25, -3.25, -2.25, PrintingUnit.Inch);
         var boundingBox = scaleBarPrinterLayer.GetBoundingBox();
         //using (Bitmap bitmap = new Bitmap((int)boundingBox.Width, (int)boundingBox.Height))
         using (Bitmap bitmap = new Bitmap(210, 56))
         {
             var ms = new MemoryStream();
             var gdiPlusGeoCanvas = new PlatformGeoCanvas();
             gdiPlusGeoCanvas.BeginDrawing(bitmap, boundingBox, GeographyUnit.Feet);
             scaleBarPrinterLayer.Draw(gdiPlusGeoCanvas, new Collection <SimpleCandidate>());
             gdiPlusGeoCanvas.EndDrawing();
             bitmap.Save(ms, ImageFormat.Png);
             BitmapImage previewImage = new BitmapImage();
             previewImage.BeginInit();
             previewImage.StreamSource = ms;
             previewImage.EndInit();
             Preview = previewImage;
         }
     }
 }
Ejemplo n.º 5
0
        public static BitmapImage GetImageSource(GeoBrush geoBrush)
        {
            BitmapImage result = null;

            System.Drawing.Bitmap nativeImage = new System.Drawing.Bitmap(16, 16);
            PlatformGeoCanvas     geoCanvas   = new PlatformGeoCanvas();
            RectangleShape        area        = new RectangleShape(-90, 90, 90, -90);

            geoCanvas.BeginDrawing(nativeImage, area, GeographyUnit.DecimalDegree);
            try
            {
                geoCanvas.DrawArea(area, geoBrush, DrawingLevel.LevelOne);
                geoCanvas.EndDrawing();

                MemoryStream streamSource = new MemoryStream();
                nativeImage.Save(streamSource, System.Drawing.Imaging.ImageFormat.Png);

                result = new BitmapImage();
                result.BeginInit();
                result.StreamSource = streamSource;
                result.EndInit();
                result.Freeze();
            }
            catch (Exception ex)
            {
                GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
            }
            finally
            {
                nativeImage.Dispose();
            }

            return(result);
        }
Ejemplo n.º 6
0
        public HttpResponseMessage GetTile(string layerId, string accessId, int z, int x, int y)
        {
            // Create the LayerOverlay for displaying the map.
            LayerOverlay layerOverlay;

            // The FilterStyle overlay is not stored in CachedOverlay.
            if (layerId == "FilterStyle")
            {
                layerOverlay = GetFilterStyleOverlay(accessId);
            }
            else
            {
                layerOverlay = cachedOverlays[layerId];
            }

            // Draw the map and return the image back to client in an HttpResponseMessage.
            using (Bitmap bitmap = new Bitmap(256, 256))
            {
                PlatformGeoCanvas geoCanvas   = new PlatformGeoCanvas();
                RectangleShape    boundingBox = WebApiExtentHelper.GetBoundingBoxForXyz(x, y, z, GeographyUnit.Meter);
                geoCanvas.BeginDrawing(bitmap, boundingBox, GeographyUnit.Meter);
                layerOverlay.Draw(geoCanvas);
                geoCanvas.EndDrawing();

                MemoryStream memoryStream = new MemoryStream();
                bitmap.Save(memoryStream, ImageFormat.Png);

                HttpResponseMessage responseMessage = new HttpResponseMessage(HttpStatusCode.OK);
                responseMessage.Content = new ByteArrayContent(memoryStream.ToArray());
                responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");

                return(responseMessage);
            }
        }
        private void TextElementEntity_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (withPreview && e.PropertyName != "Preview" && !string.IsNullOrEmpty(text.Trim()))
            {
                LabelPrinterLayer labelPrinterLayer = new LabelPrinterLayer();
                labelPrinterLayer.LoadFromViewModel(this);
                using (Bitmap bitmap = new Bitmap(250, 100))
                {
                    PlatformGeoCanvas canvas = new PlatformGeoCanvas();
                    canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.Meter);

                    labelPrinterLayer.SafeProcess(() =>
                    {
                        labelPrinterLayer.Draw(canvas, new Collection <SimpleCandidate>());
                    });

                    //labelPrinterLayer.Open();
                    //labelPrinterLayer.Draw(canvas, new System.Collections.ObjectModel.Collection<SimpleCandidate>());
                    //labelPrinterLayer.Close();
                    canvas.EndDrawing();
                    MemoryStream ms = new MemoryStream();
                    bitmap.Save(ms, ImageFormat.Png);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = ms;
                    bitmapImage.EndInit();
                    preview = bitmapImage;
                    RaisePropertyChanged(() => Preview);
                }
            }
        }
        private void RefreshPreview(string propertyName)
        {
            if (propertyName != "Preview" && !string.IsNullOrEmpty(selectedFormat.Trim()))
            {
                DatePrinterLayer datePrinterLayer = new DatePrinterLayer();
                datePrinterLayer.LoadFromViewModel(this);
                using (Bitmap bitmap = new Bitmap(460, 50))
                {
                    PlatformGeoCanvas canvas = new PlatformGeoCanvas();
                    canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.Meter);

                    datePrinterLayer.SafeProcess(() =>
                    {
                        datePrinterLayer.Draw(canvas, new Collection <SimpleCandidate>());
                    });

                    canvas.EndDrawing();
                    MemoryStream ms = new MemoryStream();
                    bitmap.Save(ms, ImageFormat.Png);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = ms;
                    bitmapImage.EndInit();
                    preview = bitmapImage;
                    RaisePropertyChanged(() => Preview);
                }
            }
        }
Ejemplo n.º 9
0
        protected override DrawingRectangleF MeasureTextCore(string text, GeoFont font)
        {
            PlatformGeoCanvas canvas = new PlatformGeoCanvas();

            canvas.BeginDrawing(new Bitmap((int)virtualMapWidth, (int)virtualMapHeight), virtualWorldExtent, MapUnit);

            return(canvas.MeasureText(text, font));
        }
Ejemplo n.º 10
0
        private static void DrawStaticImage(PlatformGeoCanvas canvas, string uri, DrawingRectangleF drawingRectangleF)
        {
            var streamInfo = System.Windows.Application.GetResourceStream(new Uri(uri, UriKind.RelativeOrAbsolute));

            if (streamInfo != null && streamInfo.Stream != null)
            {
                canvas.DrawScreenImage(new GeoImage(streamInfo.Stream), drawingRectangleF.CenterX, drawingRectangleF.CenterY, drawingRectangleF.Width, drawingRectangleF.Height, DrawingLevel.LevelOne, 0, 0, 0);
            }
        }
Ejemplo n.º 11
0
        private static void DrawNormalStyle(this Style style, PlatformGeoCanvas canvas, DrawingRectangleF drawingRectangleF)
        {
            if (style is LineStyle)
            {
                LineStyle lineStyle = (LineStyle)style;

                if (lineStyle.CenterPen.Width <= 2 && lineStyle.InnerPen.Width <= 2 && lineStyle.OuterPen.Width <= 2)
                {
                    lineStyle = (LineStyle)lineStyle.CloneDeep();

                    lineStyle.CenterPen.Width += 1;
                    lineStyle.InnerPen.Width  += 1;
                    lineStyle.OuterPen.Width  += 1;

                    LineShape line = GenerateStraightHorizontalLineShape(canvas.CurrentWorldExtent);
                    line.Rotate(line.GetCenterPoint(), 270);
                    lineStyle.Draw(new BaseShape[] { line }, canvas, new Collection <SimpleCandidate>(), new Collection <SimpleCandidate>());
                }
                else
                {
                    lineStyle.DrawSample(canvas, drawingRectangleF);
                }
            }
            else if (style is FontPointStyle)
            {
                var fontStyle = (FontPointStyle)style;
                var tmpsize   = fontStyle.CharacterFont.Size;
                if (tmpsize > 26)
                {
                    fontStyle.CharacterFont = new GeoFont(fontStyle.CharacterFont.FontName, 26, fontStyle.CharacterFont.Style);
                }
                fontStyle.DrawSample(canvas, drawingRectangleF);
                if (tmpsize > 26)
                {
                    fontStyle.CharacterFont = new GeoFont(fontStyle.CharacterFont.FontName, tmpsize, fontStyle.CharacterFont.Style);
                }
            }
            else if (style is PointStyle)
            {
                var pointStyle    = (PointStyle)style;
                var tmpSymbolSize = pointStyle.SymbolSize;
                if (tmpSymbolSize > 22)
                {
                    pointStyle.SymbolSize = 22;
                }
                pointStyle.DrawSample(canvas, drawingRectangleF);
                if (tmpSymbolSize > 22)
                {
                    pointStyle.SymbolSize = tmpSymbolSize;
                }
            }
            else if (style != null)
            {
                style.DrawSample(canvas, drawingRectangleF);
            }
        }
Ejemplo n.º 12
0
        private void ScaleLineElementEntity_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Preview" || (MapPrinterLayer.MapUnit == GeographyUnit.DecimalDegree && !PrinterLayerHelper.CheckDecimalDegreeIsInRange(MapPrinterLayer.MapExtent)))
            {
                return;
            }
            if (!MapPrinterLayer.IsOpen)
            {
                MapPrinterLayer.Open();
            }
            try
            {
                ScaleLinePrinterLayer scaleLinePrinterLayer = new ScaleLinePrinterLayer(MapPrinterLayer);
                scaleLinePrinterLayer.BackgroundMask = BackgroundStyle as AreaStyle;
                scaleLinePrinterLayer.MapUnit        = MapPrinterLayer.MapUnit;
                scaleLinePrinterLayer.UnitSystem     = SelectedUnitSystem;
                var boundingBox = MapPrinterLayer.GetBoundingBox();
                var pageCenter  = boundingBox.GetCenterPoint();
                scaleLinePrinterLayer.SetPosition(1.25, .25, -3.25, -2.25, PrintingUnit.Inch);
                using (Bitmap bitmap = new Bitmap(220, 60))
                {
                    PlatformGeoCanvas canvas = new PlatformGeoCanvas();
                    scaleLinePrinterLayer.SafeProcess(() =>
                    {
                        var scaleLineBoundingBox = scaleLinePrinterLayer.GetBoundingBox();
                        canvas.BeginDrawing(bitmap, scaleLineBoundingBox, GeographyUnit.Meter);
                        scaleLinePrinterLayer.Draw(canvas, new Collection <SimpleCandidate>());
                    });

                    //scaleLinePrinterLayer.Open();
                    //var scaleLineBoundingBox = scaleLinePrinterLayer.GetBoundingBox();
                    //canvas.BeginDrawing(bitmap, scaleLineBoundingBox, GeographyUnit.Meter);
                    //scaleLinePrinterLayer.Draw(canvas, new Collection<SimpleCandidate>());
                    //scaleLinePrinterLayer.Close();
                    canvas.EndDrawing();
                    MemoryStream ms = new MemoryStream();
                    bitmap.Save(ms, ImageFormat.Png);

                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = ms;
                    bitmapImage.EndInit();
                    Preview = bitmapImage;
                }
            }
            catch (Exception ex)
            {
                GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
            }
        }
        public void DrawSample(Stream stream, double imageWidth, double imageHeight)
        {
            TextStyle         textStyle = GetTextStyle();
            PlatformGeoCanvas canvas    = new PlatformGeoCanvas();

            using (Bitmap bitmap = new Bitmap((int)imageWidth, (int)imageHeight))
            {
                canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.DecimalDegree);
                textStyle.DrawSample(canvas, new DrawingRectangleF((float)(imageWidth * 0.5), (float)(imageHeight * 0.5), (float)imageWidth, (float)imageHeight));

                canvas.EndDrawing();
                bitmap.Save(stream, ImageFormat.Png);
            }
        }
Ejemplo n.º 14
0
        public static Bitmap GetPreviewBitmap(GisEditorWpfMap printMap)
        {
            var printerOverlay   = printMap.InteractiveOverlays.OfType <PrinterInteractiveOverlay>().FirstOrDefault();
            var pagePrinterLayer = printerOverlay.PrinterLayers.OfType <PagePrinterLayer>().FirstOrDefault();

            RectangleShape pageBoundingBox = pagePrinterLayer.GetBoundingBox();

            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)pageBoundingBox.Width, (int)pageBoundingBox.Height);
            PlatformGeoCanvas     canvas = new PlatformGeoCanvas();

            canvas.ClippingArea = pageBoundingBox;
            canvas.BeginDrawing(bitmap, pageBoundingBox, printMap.MapUnit);
            try
            {
                SetLegendIsPrinting(true, printerOverlay);
                SetDescriptionLabelVisible(false, printerOverlay);
                printerOverlay.PrinterLayers.OfType <GisEditorLegendPrinterLayer>().ForEach(l => l.IsPrinting = true);
                Collection <SimpleCandidate> labelsInAllLayers = new Collection <SimpleCandidate>();
                foreach (var printerLayer in printerOverlay.PrinterLayers.Where(l => !(l is PagePrinterLayer)))
                {
                    if (printerLayer is SimplifyMapPrinterLayer)
                    {
                        (printerLayer as SimplifyMapPrinterLayer).DrawingMode = MapPrinterDrawingMode.Vector;
                    }
                    printerLayer.IsDrawing = !(printerLayer is SimplifyMapPrinterLayer);
                    if (!printerLayer.IsOpen)
                    {
                        printerLayer.Open();
                    }
                    printerLayer.Draw(canvas, labelsInAllLayers);
                }
                canvas.EndDrawing();
                foreach (var mapPrinterLayer in printerOverlay.PrinterLayers.Where(l => l.GetType() == typeof(SimplifyMapPrinterLayer)).OfType <SimplifyMapPrinterLayer>())
                {
                    mapPrinterLayer.DrawingMode     = MapPrinterDrawingMode.Raster;
                    mapPrinterLayer.DrawDescription = true;
                }
                return(bitmap);
            }
            catch (Exception ex)
            {
                GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                return(bitmap);
            }
            finally
            {
                SetLegendIsPrinting(false, printerOverlay);
                SetDescriptionLabelVisible(true, printerOverlay);
            }
        }
Ejemplo n.º 15
0
        private static void DrawPolygon(PolygonShape p, string f)
        {
            Bitmap            bmp    = new Bitmap(256, 256);
            PlatformGeoCanvas canvas = new PlatformGeoCanvas();

            canvas.BeginDrawing(bmp, new RectangleShape(-30, 30, 30, -30), GeographyUnit.DecimalDegree);
            canvas.DrawArea(p, GeoBrushes.Blue, DrawingLevel.LabelLevel);
            canvas.EndDrawing();

            string resultFilePath = f;

            bmp.Save(resultFilePath);
            Process.Start(resultFilePath);
        }
Ejemplo n.º 16
0
 public static byte[] GetPreviewBinary(this Style style, int width = 23, int height = 23)
 {
     using (var bitmap = new Bitmap(width, height))
     {
         var canvas = new PlatformGeoCanvas();
         canvas.BeginDrawing(bitmap, new RectangleShape(-10, 10, 10, -10), GeographyUnit.DecimalDegree);
         DrawStyleSamples(style, width, height, canvas);
         canvas.EndDrawing();
         using (MemoryStream memoryStream = new MemoryStream())
         {
             bitmap.Save(memoryStream, ImageFormat.Png);
             return(memoryStream.ToArray());
         }
     }
 }
Ejemplo n.º 17
0
        private GeoImage GetCacheImage(PageGeoCanvas pageGeoCanvas, GeographyUnit geographyUnit, RectangleShape adjustedWorldExtent, Collection <SimpleCandidate> labelsInAllLayers, double width, double height)
        {
            RectangleShape currentBoundingBox = GetBoundingBox();

            if (mapImageCache == null && Layers.Count > 0)
            {
                Bitmap       bitmap       = null;
                MemoryStream memoryStream = null;
                try
                {
                    bitmap = new Bitmap((int)width, (int)height);
                    PlatformGeoCanvas tmpCanvas = new PlatformGeoCanvas();
                    tmpCanvas.DrawingQuality = DrawingQuality.HighSpeed;
                    tmpCanvas.BeginDrawing(bitmap, currentBoundingBox, geographyUnit);

                    pageGeoCanvas.BeginDrawing(tmpCanvas, adjustedWorldExtent, MapUnit);

                    lock (Layers)
                    {
                        foreach (Layer layer in Layers)
                        {
                            if (!layer.IsOpen)
                            {
                                layer.Open();
                            }
                            pageGeoCanvas.Flush();
                            layer.Draw(pageGeoCanvas, labelsInAllLayers);
                        }
                    }

                    pageGeoCanvas.EndDrawing();
                    tmpCanvas.EndDrawing();
                    IsDrawing    = false;
                    memoryStream = new MemoryStream();
                    bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
                    mapImageCache = new GeoImage(memoryStream);
                }
                catch (Exception ex)
                {
                    GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                }
                finally
                {
                    bitmap?.Dispose();
                }
            }
            return(mapImageCache);
        }
        private float GetLegendHeight(LegendAdornmentLayer legendAdornmentLayer)
        {
            PlatformGeoCanvas gdiPlusGeoCanvas = new PlatformGeoCanvas();
            LegendItem        title = legendAdornmentLayer.Title;
            float             titleMeasuredHeight = gdiPlusGeoCanvas.MeasureText(title.TextStyle.TextColumnName, new GeoFont("Segoe UI", 12)).Height;
            float             legendHeight = new[] { titleMeasuredHeight, title.ImageHeight, title.Height }.Max();
            float             height = legendHeight + Math.Max(title.ImageTopPadding, title.TextTopPadding) + title.TopPadding + Math.Max(title.ImageBottomPadding, title.TextBottomPadding) + title.BottomPadding;

            foreach (LegendItem legendItem in legendAdornmentLayer.LegendItems)
            {
                float itemLegendHeight = Math.Max(gdiPlusGeoCanvas.MeasureText(legendItem.TextStyle.TextColumnName, new GeoFont("Segoe UI", 10)).Height, legendItem.ImageHeight);
                float itemHeight       = itemLegendHeight + Math.Max(legendItem.ImageTopPadding, legendItem.TextTopPadding) + legendItem.TopPadding + Math.Max(legendItem.ImageBottomPadding, legendItem.TextBottomPadding) + legendItem.BottomPadding;

                height += itemHeight;
            }
            return(height);
        }
Ejemplo n.º 19
0
        public float GetLegendWidth(LegendAdornmentLayer legendAdornmentLayer)
        {
            PlatformGeoCanvas gdiPlusGeoCanvas = new PlatformGeoCanvas();
            LegendItem        title            = legendAdornmentLayer.Title;
            float             width            = gdiPlusGeoCanvas.MeasureText(title.TextStyle.TextColumnName, new GeoFont("Segoe UI", 12)).Width
                                                 + title.ImageWidth + title.ImageRightPadding + title.ImageLeftPadding + title.TextRightPadding + title.TextLeftPadding + title.LeftPadding + title.RightPadding;

            foreach (LegendItem legendItem in legendAdornmentLayer.LegendItems)
            {
                float legendItemWidth = gdiPlusGeoCanvas.MeasureText(legendItem.TextStyle.TextColumnName, new GeoFont("Segoe UI", 10)).Width
                                        + legendItem.ImageWidth + legendItem.ImageRightPadding + legendItem.ImageLeftPadding + legendItem.TextRightPadding + legendItem.TextLeftPadding + legendItem.LeftPadding + legendItem.RightPadding;
                if (width < legendItemWidth)
                {
                    width = legendItemWidth;
                }
            }
            return(width);
        }
Ejemplo n.º 20
0
        private BitmapImage GetImageSource()
        {
            MemoryStream streamSource = null;

            if (Width != 0 && Height != 0)
            {
                PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas
                {
                    CompositingQuality = CompositingQuality.HighSpeed,
                    SmoothingMode      = SmoothingMode.HighSpeed,
                    DrawingQuality     = DrawingQuality.CanvasSettings,
                };
                SizeF  measuredSize = Measure(geoCanvas);
                Bitmap nativeImage  = new Bitmap((int)(measuredSize.Width + LeftPadding + RightPadding + 1), (int)(measuredSize.Height + TopPadding + BottomPadding + 1));
                geoCanvas.BeginDrawing(nativeImage, new RectangleShape(-10, 10, 10, -10), GeographyUnit.Meter);
                simpleCandidates.Clear();

                LegendItem newLegendItem = ToLegendItem();
                newLegendItem.Width  = measuredSize.Width;
                newLegendItem.Height = measuredSize.Height;
                //newLegendItem.Draw(0, 0, 100, geoCanvas, simpleCandidates);
                newLegendItem.Draw(geoCanvas, simpleCandidates, new LegendDrawingParameters {
                    XOffset = 0, YOffset = 0
                });
                geoCanvas.EndDrawing();

                streamSource = new MemoryStream();
                nativeImage.Save(streamSource, ImageFormat.Png);
            }

            BitmapImage previewSource = new BitmapImage();

            if (streamSource != null)
            {
                previewSource.BeginInit();
                previewSource.StreamSource = streamSource;
                previewSource.EndInit();
                previewSource.Freeze();
            }

            return(previewSource);
        }
Ejemplo n.º 21
0
        private HttpResponseMessage DrawTileImage(LayerOverlay layerOverlay, int z, int x, int y)
        {
            using (Bitmap bitmap = new Bitmap(256, 256))
            {
                PlatformGeoCanvas geoCanvas   = new PlatformGeoCanvas();
                RectangleShape    boundingBox = WebApiExtentHelper.GetBoundingBoxForXyz(x, y, z, GeographyUnit.Meter);
                geoCanvas.BeginDrawing(bitmap, boundingBox, GeographyUnit.Meter);
                layerOverlay.Draw(geoCanvas);
                geoCanvas.EndDrawing();

                MemoryStream ms = new MemoryStream();
                bitmap.Save(ms, ImageFormat.Png);

                HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.OK);
                msg.Content = new ByteArrayContent(ms.ToArray());
                msg.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");

                return(msg);
            }
        }
Ejemplo n.º 22
0
        private void ConvertTextToAnnotation(string valueStyleMatchColumnName, TextStyle textStyle, Feature feature, string annotationText)
        {
            PlatformGeoCanvas canvas = new PlatformGeoCanvas
            {
                CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed,
                DrawingQuality     = DrawingQuality.HighSpeed,
                SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed
            };

            double width       = GisEditor.ActiveMap.ActualWidth;
            double height      = GisEditor.ActiveMap.ActualHeight;
            Bitmap nativeImage = new Bitmap((int)width, (int)height);

            canvas.BeginDrawing(nativeImage, GisEditor.ActiveMap.CurrentExtent, GisEditor.ActiveMap.MapUnit);
            DrawingRectangleF rectangle = canvas.MeasureText(annotationText, textStyle.Font);

            Type       type   = textStyle.GetType();
            MethodInfo method = type.GetMethod("GetLabelingCandidates", BindingFlags.Instance | BindingFlags.NonPublic);

            if (method != null)
            {
                Collection <LabelingCandidate> candidates = method.Invoke(textStyle, new object[] { feature, canvas }) as Collection <LabelingCandidate>;
                if (candidates != null)
                {
                    foreach (var candidate in candidates)
                    {
                        foreach (var labelInfo in candidate.LabelInformation)
                        {
                            ScreenPointF point = new ScreenPointF((float)labelInfo.PositionInScreenCoordinates.X + rectangle.Width / 2 + 3, (float)labelInfo.PositionInScreenCoordinates.Y - rectangle.Height / 2);

                            PointShape pointShape   = ExtentHelper.ToWorldCoordinate(GisEditor.ActiveMap.CurrentExtent, point, (float)width, (float)height);
                            Feature    pointFeature = new Feature(pointShape);
                            pointFeature.Id = pointShape.Id;
                            pointFeature.ColumnValues[AnnotationTrackInteractiveOverlay.valueStyleMatchColumnName] = valueStyleMatchColumnName;
                            pointFeature.ColumnValues[AnnotationTrackInteractiveOverlay.AnnotationTextColumnName]  = annotationText;
                            CurrentAnnotationOverlay.TrackShapeLayer.InternalFeatures[pointShape.Id] = pointFeature;
                        }
                    }
                }
            }
        }
 private void RefreshHighlightTile(RectangleShape targetExtent)
 {
     highlightTile.TargetExtent = targetExtent;
     highlightTile.DrawingLayers.Clear();
     highlightTile.DrawingLayers.Add(highlightFeatureLayer);
     highlightTile.DrawingLayers.Add(standOutHighlightFeatureLayer);
     if (MapArguments != null)
     {
         highlightTile.Width          = MapArguments.ActualWidth;
         highlightTile.Height         = MapArguments.ActualHeight;
         highlightTile.ZoomLevelIndex = MapArguments.GetSnappedZoomLevelIndex(targetExtent);
         using (System.Drawing.Bitmap nativeImage = new System.Drawing.Bitmap((int)highlightTile.Width, (int)highlightTile.Height))
         {
             PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas();
             geoCanvas.BeginDrawing(nativeImage, targetExtent, MapArguments.MapUnit);
             highlightTile.Draw(geoCanvas);
             geoCanvas.EndDrawing();
             highlightTile.CommitDrawing(geoCanvas, GetImageSourceFromNativeImage(nativeImage));
         }
     }
 }
Ejemplo n.º 24
0
 private MemoryStream GetImageStream(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers, RectangleShape adjustedWorldExtent, RectangleShape boundingBox)
 {
     using (Bitmap bitmap = new Bitmap((int)boundingBox.Width, (int)boundingBox.Height))
     {
         MemoryStream      ms = new MemoryStream();
         PlatformGeoCanvas gdiPlusGeoCanvas = new PlatformGeoCanvas();
         gdiPlusGeoCanvas.DrawingQuality = DrawingQuality.HighQuality;
         gdiPlusGeoCanvas.BeginDrawing(bitmap, adjustedWorldExtent, MapUnit);
         foreach (Layer layer in Layers)
         {
             gdiPlusGeoCanvas.Flush();
             layer.SafeProcess(() =>
             {
                 layer.Draw(gdiPlusGeoCanvas, labelsInAllLayers);
             });
         }
         gdiPlusGeoCanvas.EndDrawing();
         bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
         return(ms);
     }
 }
Ejemplo n.º 25
0
        private BitmapImage GetImageSource()
        {
            MemoryStream streamSource = null;

            if (PreviewWidth != 0 && PreviewHeight != 0 && Width != 0 && Height != 0 && LegendItems.Count > 0)
            {
                Bitmap            nativeImage = new Bitmap(PreviewWidth, PreviewHeight);
                PlatformGeoCanvas geoCanvas   = new PlatformGeoCanvas
                {
                    CompositingQuality = CompositingQuality.HighSpeed,
                    SmoothingMode      = SmoothingMode.HighSpeed,
                    DrawingQuality     = DrawingQuality.CanvasSettings,
                };

                LegendAdornmentLayer tmpLegendAdornmentLayer = ToLegendAdornmentLayer();
                double left   = -tmpLegendAdornmentLayer.Width * .5;
                double top    = tmpLegendAdornmentLayer.Height * .5;
                double right  = left + tmpLegendAdornmentLayer.Width;
                double bottom = top - tmpLegendAdornmentLayer.Height;

                geoCanvas.BeginDrawing(nativeImage, new RectangleShape(left, top, right, bottom), GeographyUnit.Meter);
                simpleCandidates.Clear();
                tmpLegendAdornmentLayer.Draw(geoCanvas, simpleCandidates);
                geoCanvas.EndDrawing();

                streamSource = new MemoryStream();
                nativeImage.Save(streamSource, ImageFormat.Png);
            }

            BitmapImage previewSource = new BitmapImage();

            if (streamSource != null)
            {
                previewSource.BeginInit();
                previewSource.StreamSource = streamSource;
                previewSource.EndInit();
                previewSource.Freeze();
            }
            return(previewSource);
        }
Ejemplo n.º 26
0
        protected override PrinterLayer GetPrinterLayerFromActiveMapCore(RectangleShape boudingBox)
        {
            if (this.titleAdornmentLayer != null)
            {
                LabelPrinterLayer printerLayer = new LabelPrinterLayer();
                LoadFromActiveMap(printerLayer);
                var newScreenBBox = new PlatformGeoCanvas().MeasureText(printerLayer.Text, printerLayer.Font);
                var scaledWidth   = newScreenBBox.Width * 1.1;
                var scaledHeight  = newScreenBBox.Height * 1.1;

                double width  = PrinterHelper.ConvertLength(scaledWidth, PrintingUnit.Point, PrintingUnit.Inch);
                double height = PrinterHelper.ConvertLength(scaledHeight, PrintingUnit.Point, PrintingUnit.Inch);
                double left   = PrinterHelper.ConvertLength(titleAdornmentLayer.XOffsetInPixel, PrintingUnit.Point, PrintingUnit.Inch);
                double top    = PrinterHelper.ConvertLength(titleAdornmentLayer.YOffsetInPixel, PrintingUnit.Point, PrintingUnit.Inch);
                SetPosition(titleAdornmentLayer.Location, boudingBox, printerLayer, width, height, left, top);
                return(printerLayer);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 27
0
        private static byte[] GetComplicatedStyleSampleImageBinary(IEnumerable <Style> styles, int width, int height)
        {
            int loopCount = styles.Count() > 4 ? 4 : styles.Count();

            using (Bitmap bitmap = new Bitmap(width, height))
            {
                PlatformGeoCanvas canvas = new PlatformGeoCanvas();
                canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.DecimalDegree);

                Collection <Tuple <int, int> > tuples = new Collection <Tuple <int, int> >()
                {
                    new Tuple <int, int>(1, 1), new Tuple <int, int>(3, 1), new Tuple <int, int>(1, 3), new Tuple <int, int>(3, 3)
                };
                float tileWidth        = width * 0.5f;
                float tileHeight       = height * 0.5f;
                float centerXParameter = tileWidth * 0.5f;
                float centerYParameter = tileHeight * 0.5f;

                for (int i = 0; i < loopCount; i++)
                {
                    Style customStyle = styles.ElementAt(i);

                    float centerX = tuples[i].Item1 * centerXParameter;
                    float centerY = tuples[i].Item2 * centerYParameter;
                    if (customStyle != null)
                    {
                        customStyle.DrawSample(canvas, new DrawingRectangleF(centerX, centerY, tileWidth, tileHeight));
                    }
                }
                canvas.EndDrawing();

                using (MemoryStream memoryStream = new MemoryStream())
                {
                    bitmap.Save(memoryStream, ImageFormat.Png);
                    return(memoryStream.ToArray());
                }
            }
        }
Ejemplo n.º 28
0
        private static void PreviewImageChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            FontPicker currentInstance   = (FontPicker)sender;
            int        selectedCharIndex = currentInstance.SelectedCharacterIndex;

            PointStyle pointStyle = new PointStyle(
                new GeoFont(currentInstance.SelectedFontFamily.Source, defaultFontSize, currentInstance.SelectedFontStyle),
                currentInstance.SelectedCharacterIndex,
                new GeoSolidBrush(GeoColor.StandardColors.Black));

            System.Drawing.Bitmap nativeImage = new System.Drawing.Bitmap(defaultPreviewSize, defaultPreviewSize);
            var geoCanvas = new PlatformGeoCanvas();

            try
            {
                geoCanvas.BeginDrawing(nativeImage, new RectangleShape(-90, 90, 90, -90), GeographyUnit.DecimalDegree);
                pointStyle.DrawSample(geoCanvas);
                geoCanvas.EndDrawing();

                MemoryStream streamSource = new MemoryStream();
                nativeImage.Save(streamSource, System.Drawing.Imaging.ImageFormat.Png);

                BitmapImage imageSource = new BitmapImage();
                imageSource.BeginInit();
                imageSource.StreamSource = streamSource;
                imageSource.EndInit();

                currentInstance.PreviewImage = imageSource;
            }
            catch (Exception ex)
            {
                GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
            }
            finally
            {
                nativeImage.Dispose();
            }
        }
Ejemplo n.º 29
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);
            }
        }
        private LayerTile DrawHighlightTile(RectangleShape targetExtent, LayerTile tile)
        {
            tile.DrawingLayers.Clear();
            if (highlightFeatureLayer.InternalFeatures.Count > 0)
            {
                tile.DrawingLayers.Add(highlightFeatureLayer);
            }

            GeoCanvas geoCanvas = new PlatformGeoCanvas()
            {
                CompositingQuality = CompositingQuality.HighSpeed,
                DrawingQuality     = DrawingQuality.HighSpeed,
                SmoothingMode      = SmoothingMode.HighSpeed
            };
            Bitmap bitmap = new Bitmap((int)tile.Width, (int)tile.Height);

            geoCanvas.BeginDrawing(bitmap, targetExtent, MapArguments.MapUnit);
            tile.Draw(geoCanvas);
            geoCanvas.EndDrawing();
            tile.CommitDrawing(geoCanvas, MapSuiteSampleHelper.GetImageSourceFromNativeImage(bitmap));

            return(tile);
        }