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));
        }
Exemple #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);
            }
        }
        protected override void EndProcessing()
        {
            Utils.StartProfile("MapCmdlet");

            var map = new InnerMap()
            {
                EnableAnimation        = false,
                EnableScrolling        = false,
                EnableZooming          = false,
                EnableDelayedScrolling = false
            };

            map.NavigationPanelOptions.ShowCoordinates     = false;
            map.NavigationPanelOptions.ShowKilometersScale = false;
            map.NavigationPanelOptions.ShowMilesScale      = false;

            switch (CoordinateSystem)
            {
            case MapCoordinateSystem.Geo:
                map.CoordinateSystem = new GeoMapCoordinateSystem();
                break;

            case MapCoordinateSystem.Cartesian:
                map.CoordinateSystem = new CartesianMapCoordinateSystem();
                break;
            }

            if (map.CoordinateSystem is GeoMapCoordinateSystem geoCoordSystem)
            {
                switch (Projection ?? MapProjection.Default)
                {
                case MapProjection.Default:
                    //Leave projection as is
                    break;

                case MapProjection.BraunStereographic:
                    geoCoordSystem.Projection = new BraunStereographicProjection();
                    break;

                case MapProjection.EllipticalMercator:
                    geoCoordSystem.Projection = new EllipticalMercatorProjection();
                    break;

                case MapProjection.EqualArea:
                    geoCoordSystem.Projection = new EqualAreaProjection();
                    break;

                case MapProjection.Equidistant:
                    geoCoordSystem.Projection = new EquidistantProjection();
                    break;

                case MapProjection.Equirectangular:
                    geoCoordSystem.Projection = new EquirectangularProjection();
                    break;

                case MapProjection.Kavrayskiy:
                    geoCoordSystem.Projection = new KavrayskiyProjection();
                    break;

                case MapProjection.LambertCylindricalEqualArea:
                    geoCoordSystem.Projection = new LambertCylindricalEqualAreaProjection();
                    break;

                case MapProjection.Miller:
                    geoCoordSystem.Projection = new MillerProjection();
                    break;

                case MapProjection.Sinusoidal:
                    geoCoordSystem.Projection = new SinusoidalProjection();
                    break;

                case MapProjection.SphericalMercator:
                    geoCoordSystem.Projection = new SphericalMercatorProjection();
                    break;
                }
            }
            else if ((Projection ?? MapProjection.Default) != MapProjection.Default)
            {
                throw new Exception("Projection can be set only in Geo coordinate system.");
            }

            if (ImageList != null && ImageList.Length > 0)
            {
                ExecuteLocked(() =>
                {
                    var images = new ImageCollection();
                    if (ImageSize.HasValue)
                    {
                        images.ImageSize = ImageSize.Value;
                    }
                    foreach (var imageFile in ImageList)
                    {
                        var imagePath = Project.Current.MapPath(imageFile);
                        if (string.IsNullOrWhiteSpace(imagePath) || !System.IO.File.Exists(imagePath))
                        {
                            throw new Exception($"Cannot find image: '{imagePath}'.");
                        }
                        var bmp = new Bitmap(imagePath);
                        images.AddImage(bmp);
                    }
                    map.ImageList = images;
                }, LockFiles ? LockObject : null);
            }

            var backColor = Utils.ColorFromString(BackColor);

            if (backColor != Color.Empty)
            {
                map.BackColor = backColor;
            }

            var context = new MapContext()
            {
                Map = map
            };

            WriteObject(context);
        }