protected void WriteImage(Document book)
        {
            var map = MapContext?.Map;

            if (map == null)
            {
                throw new Exception("Map is not provided. Please use one of New-Map cmdlets to create a map.");
            }

            if (CenterPoint != null && CenterPoint.Length != 2)
            {
                throw new Exception("CanterPoint shall be array of exactly 2 double values.");
            }

            if (CenterPoint != null)
            {
                map.PublicCenterPoint = MapContext.CreateCoordPoint(CenterPoint[0], CenterPoint[1]);
            }

            int w = Convert.ToInt32(Width * 96.0 / 300.0);
            int h = Convert.ToInt32(Height * 96.0 / 300.0);

            map.ZoomLevel = ZoomLevel;
            map.SetClientRectangle(new Rectangle(0, 0, w, h));

            var mapBitmap = PaintMap(map);

            ExecuteSynchronized(() => DoWriteImage(book, mapBitmap));
        }
Esempio n. 2
0
        protected override void UpdateMap()
        {
            var miniMap = new MiniMap()
            {
                EnableScrolling     = false,
                EnableZooming       = false,
                SetMapCenterOnClick = false
            };

            if (Alignment > 0)
            {
                miniMap.Alignment = Alignment;
            }

            if (Width.HasValue)
            {
                miniMap.Width = Width.Value;
            }
            if (Height.HasValue)
            {
                miniMap.Height = Height.Value;
            }

            if (ZoomLevel != 1.0 || CenterPoint != null)
            {
                var behavior = new FixedMiniMapBehavior();

                if (CenterPoint != null)
                {
                    if (CenterPoint.Length != 2)
                    {
                        throw new Exception("CenterPoint shall be a double array with 2 elements.");
                    }
                    behavior.CenterPoint = MapContext.CreateCoordPoint(CenterPoint[0], CenterPoint[1]);
                }

                if (ZoomLevel != 1.0)
                {
                    behavior.ZoomLevel = ZoomLevel;
                }

                miniMap.Behavior = behavior;
            }

            var backColor = Utils.ColorFromString(BackColor);

            if (backColor != Color.Empty)
            {
                miniMap.ViewportStyle.Fill = backColor;
            }
            var strokeColor = Utils.ColorFromString(StrokeColor);

            if (strokeColor != Color.Empty)
            {
                miniMap.ViewportStyle.Stroke = strokeColor;
            }

            MapContext.Map.MiniMap = miniMap;
            MapContext.Map.PrintOptions.PrintMiniMap = true;
        }
        protected void WriteImage(Document book)
        {
            var map = MapContext?.Map;

            if (map == null)
            {
                throw new Exception("Map is not provided. Please use one of New-Map cmdlets to create a map.");
            }

            var fileName = Project.Current.MapPath(FileName);
            var dir      = Path.GetDirectoryName(fileName);

            if (!Directory.Exists(dir))
            {
                throw new Exception($"Directory '{dir}' does not exist.");
            }

            if (File.Exists(fileName))
            {
                if (Replace)
                {
                    File.Delete(fileName);
                }
                else
                {
                    throw new Exception($"File '{FileName}' already exists.");
                }
            }

            if (CenterPoint != null && CenterPoint.Length != 2)
            {
                throw new Exception("CanterPoint shall be array of exactly 2 double values.");
            }

            if (CenterPoint != null)
            {
                map.PublicCenterPoint = MapContext.CreateCoordPoint(CenterPoint[0], CenterPoint[1]);
            }

            int w = Convert.ToInt32(Width * 96.0 / 300.0);
            int h = Convert.ToInt32(Height * 96.0 / 300.0);

            map.ZoomLevel = ZoomLevel;
            map.SetClientRectangle(new Rectangle(0, 0, w, h));

            var mapBitmap = PaintMap(map);

            DoWriteImage(book, mapBitmap);

            if (Preview)
            {
                PreviewFile(fileName);
            }
        }