コード例 #1
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);
        }
コード例 #2
0
        private void DrawInternal(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers)
        {
            RectangleShape currentBoundingBox = GetBoundingBox();

            AreaStyle brushStyle = BackgroundMask.CloneDeep() as AreaStyle;

            brushStyle.OutlinePen.Width = 0;
            brushStyle.Draw(new BaseShape[] { currentBoundingBox }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers);

            // Clear Cache images
            if (LastmapExtent != null)
            {
                if (LastmapExtent.UpperLeftPoint.X != MapExtent.UpperLeftPoint.X ||
                    LastmapExtent.UpperLeftPoint.Y != MapExtent.UpperLeftPoint.Y ||
                    LastmapExtent.LowerRightPoint.X != MapExtent.LowerRightPoint.X ||
                    LastmapExtent.LowerRightPoint.Y != MapExtent.LowerRightPoint.Y ||
                    IsDrawing)
                {
                    mapImageCache = null;
                }
            }

            //For adjusting the world extent of the map to the ratio of the drawing area.
            RectangleShape adjustedWorldExtent = ExtentHelper.GetDrawingExtent(MapExtent, (float)currentBoundingBox.Width, (float)currentBoundingBox.Height);
            RectangleShape boundingBox         = GetBoundingBox();
            PointShape     ajustedWorldCenter  = adjustedWorldExtent.GetCenterPoint();
            PageGeoCanvas  pageGeoCanvas       = new PageGeoCanvas(new RectangleShape(0, boundingBox.Height, boundingBox.Width, 0), currentBoundingBox);

            //if (EnableClipping)
            //{
            //    pageGeoCanvas.EnableCliping = true;
            //    pageGeoCanvas.ClipingArea = adjustedWorldExtent;
            //}

            //if (canvas is GdiPlusGeoCanvas && DrawingMode != Core.DrawingMode.Vector)
            // only display on map.
            if (DrawingMode != MapPrinterDrawingMode.Vector && !(canvas is PrinterGeoCanvas))
            {
                double   width  = boundingBox.Width / canvas.CurrentWorldExtent.Width * canvas.Width;
                double   height = boundingBox.Height / canvas.CurrentWorldExtent.Height * canvas.Height;
                GeoImage image  = GetCacheImage(pageGeoCanvas, canvas.MapUnit, adjustedWorldExtent, labelsInAllLayers, width, height);

                pageGeoCanvas.BeginDrawing(canvas, adjustedWorldExtent, MapUnit);
                if (image != null)
                {
                    pageGeoCanvas.DrawWorldImage(image, ajustedWorldCenter.X, ajustedWorldCenter.Y, (float)boundingBox.Width - 0.5f, (float)boundingBox.Height - 0.5f, DrawingLevel.LabelLevel);
                }
                if (DrawDescription)
                {
                    DrawDescriptionText(pageGeoCanvas);
                }
                //pageGeoCanvas.EnableCliping = false;
                pageGeoCanvas.EndDrawing();
            }
            // display on map or printer.
            else
            {
                pageGeoCanvas.BeginDrawing(canvas, adjustedWorldExtent, MapUnit);
                double increase = 0;
                if (BackgroundMask.OutlinePen != null)
                {
                    float haflPenWidth = BackgroundMask.OutlinePen.Width / 2;
                    increase = haflPenWidth * canvas.CurrentWorldExtent.Width / canvas.Width;
                }
                canvas.ClippingArea = new RectangleShape(
                    currentBoundingBox.UpperLeftPoint.X - increase,
                    currentBoundingBox.UpperLeftPoint.Y + increase,
                    currentBoundingBox.LowerRightPoint.X + increase,
                    currentBoundingBox.LowerRightPoint.Y - increase);
                if (canvas is PrinterGeoCanvas)
                {
                    foreach (Layer layer in Layers)
                    {
                        pageGeoCanvas.Flush();

                        float        savedDrawingMarginPercentage = 0;
                        FeatureLayer featureLayer = layer as FeatureLayer;
                        if (featureLayer != null)
                        {
                            savedDrawingMarginPercentage      = featureLayer.DrawingMarginInPixel;
                            featureLayer.DrawingMarginInPixel = 0;
                        }
                        layer.SafeProcess(() =>
                        {
                            layer.Draw(pageGeoCanvas, labelsInAllLayers);
                        });
                        if (featureLayer != null && savedDrawingMarginPercentage != 0)
                        {
                            featureLayer.DrawingMarginInPixel = savedDrawingMarginPercentage;
                        }
                    }
                }
                else
                {
                    using (MemoryStream ms = GetImageStream(canvas, labelsInAllLayers, adjustedWorldExtent, boundingBox))
                    {
                        pageGeoCanvas.DrawWorldImage(new GeoImage(ms), ajustedWorldCenter.X, ajustedWorldCenter.Y, (float)boundingBox.Width - 0.5f, (float)boundingBox.Height - 0.5f, DrawingLevel.LabelLevel);
                    }
                    //foreach (Layer layer in Layers)
                    //{
                    //    pageGeoCanvas.Flush();
                    //    layer.SafeProcess(() =>
                    //    {
                    //        layer.Draw(pageGeoCanvas, labelsInAllLayers);
                    //    });
                    //}
                }
                if (DrawDescription)
                {
                    DrawDescriptionText(pageGeoCanvas);
                }
                //pageGeoCanvas.EnableCliping = false;
                var areaStyle = new AreaStyle(BackgroundMask.OutlinePen)
                {
                    DrawingLevel = DrawingLevel.LabelLevel
                };
                areaStyle.Draw(new BaseShape[1] {
                    currentBoundingBox
                }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers);
                canvas.ClippingArea = null;
            }

            AreaStyle lineStyle = new AreaStyle(BackgroundMask.OutlinePen.CloneDeep());

            lineStyle.DrawingLevel = DrawingLevel.LabelLevel;
            lineStyle.Draw(new BaseShape[] { currentBoundingBox }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers);
            LastmapExtent = new RectangleShape(MapExtent.UpperLeftPoint.X, MapExtent.UpperLeftPoint.Y, MapExtent.LowerRightPoint.X, MapExtent.LowerRightPoint.Y);
        }