Esempio n. 1
0
        public Path AsBitmapUsingOpenTK(List <SqlGeometry> geometries, List <string> labels, double mapScale, sb.BoundingBox boundingBox, double width, double height, Func <Point, Point> mapToScreen, RectangleGeometry area)
        {
            if (geometries == null)
            {
                return(null);
            }

            //Pen pen = new Pen(this.VisualParameters.Stroke, this.VisualParameters.StrokeThickness);
            var pen = this.VisualParameters.GetGdiPlusPen();

            Brush brush = this.VisualParameters.Fill;

            //var color = ((SolidColorBrush)this.VisualParameters.Stroke)?.Color ?? ((SolidColorBrush)this.VisualParameters.Fill).Color;

            //var image = new SqlSpatialToOpenTKBitmap().ParseSqlGeometry(
            //    geometries,
            //    width,
            //    height,
            //    mapToScreen,
            //    new System.Drawing.Pen(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B), (int)this.VisualParameters.StrokeThickness),
            //    System.Drawing.Brushes.SkyBlue);

            var image = new SqlSpatialToOpenTKBitmap().ParseSqlGeometry(
                geometries,
                width,
                height,
                mapToScreen,
                pen,
                System.Drawing.Brushes.SkyBlue);

            if (image == null)
            {
                return(null);
            }

            if (labels != null)
            {
                SqlSpatialToGdiBitmap.DrawLabels(labels, geometries, image, mapToScreen, Labels);
            }

            BitmapImage bitmapImage = IRI.Jab.Common.Helpers.ImageUtility.AsBitmapImage(image, System.Drawing.Imaging.ImageFormat.Png);

            //Try #3
            Path path = new Path()
            {
                Data = area,
                Tag  = new Model.LayerTag(mapScale)
                {
                    Layer = this, Tile = null, IsDrawn = true, IsNew = true
                }
            };

            this.Element = path;

            path.Fill = new ImageBrush(bitmapImage);


            return(path);
        }
Esempio n. 2
0
        //OpenTK Approach
        public Path AsTileUsinOpenTK(List <SqlGeometry> geometries, List <string> labels, double mapScale, TileInfo region, double tileWidth, double tileHeight, RectangleGeometry area, Func <Point, Point> viewTransform, sb.BoundingBox totalExtent)
        {
            if (geometries == null)
            {
                return(null);
            }

            //Brush brush = this.VisualParameters.Fill;

            //var color = ((SolidColorBrush)this.VisualParameters.Stroke)?.Color ?? ((SolidColorBrush)this.VisualParameters.Fill).Color;

            //var pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B), (int)this.VisualParameters.StrokeThickness);

            //if (this.VisualParameters.DashStyle != null)
            //{
            //    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
            //}
            var pen = this.VisualParameters.GetGdiPlusPen();

            var brush = this.VisualParameters.GetGdiPlusFillBrush();

            var transform = MapToTileScreenWpf(totalExtent, region.WebMercatorExtent, viewTransform);

            var image = new SqlSpatialToOpenTKBitmap().ParseSqlGeometry(
                geometries,
                tileWidth,
                tileHeight,
                transform,
                pen,
                brush);

            if (image == null)
            {
                return(null);
            }

            if (labels != null)
            {
                SqlSpatialToGdiBitmap.DrawLabels(labels, geometries, image, transform, this.Labels);
            }

            BitmapImage bitmapImage = IRI.Jab.Common.Helpers.ImageUtility.AsBitmapImage(image, System.Drawing.Imaging.ImageFormat.Png);

            Path path = new Path()
            {
                Data = area,
                Tag  = new LayerTag(mapScale)
                {
                    Layer = this, IsTiled = true, Tile = region, IsDrawn = true, IsNew = true
                }
            };

            this.Element = path;

            path.Fill = new ImageBrush(bitmapImage);

            return(path);
        }
Esempio n. 3
0
        public Path AsBitmapUsingGdiPlus(List <SqlGeometry> geometries, List <string> labels, double mapScale, sb.BoundingBox boundingBox, double width, double height, Func <Point, Point> mapToScreen, RectangleGeometry area)
        {
            if (geometries == null)
            {
                return(null);
            }

            var borderBrush = this.VisualParameters.Stroke.AsGdiBrush();

            var pen = this.VisualParameters.GetGdiPlusPen();

            var image = SqlSpatialToGdiBitmap.ParseSqlGeometry(
                geometries,
                width,
                height,
                mapToScreen,
                pen,
                this.VisualParameters.Fill.AsGdiBrush(),
                this.VisualParameters.PointSize,
                this.PointSymbol);

            if (image == null)
            {
                return(null);
            }

            if (labels != null)
            {
                SqlSpatialToGdiBitmap.DrawLabels(labels, geometries, image, mapToScreen, this.Labels);
            }

            BitmapImage bitmapImage = Common.Helpers.ImageUtility.AsBitmapImage(image, System.Drawing.Imaging.ImageFormat.Png);

            image.Dispose();

            Path path = new Path()
            {
                Data = area,
                Tag  = new Model.LayerTag(mapScale)
                {
                    Layer = this, Tile = null, IsDrawn = true, IsNew = true
                }
            };

            this.Element = path;

            path.Fill = new ImageBrush(bitmapImage);

            bitmapImage.Freeze();

            return(path);
        }
Esempio n. 4
0
        public void SaveAsGoogleTiles(string outputFolderPath, int minLevel = 1, int maxLevel = 13)
        {
            if (maxLevel < minLevel)
            {
                throw new NotImplementedException("(ERROR IN VECTOR LAYER): minLevel must be less than maxLevel");
            }

            var zoomLevels = Enumerable.Range(minLevel, maxLevel - minLevel + 1);

            foreach (var zoom in zoomLevels)
            {
                var googleTiles = WebMercatorUtility.WebMercatorBoundingBoxToGoogleTileRegions(this.Extent, zoom);

                var scale = GoogleScale.Scales.Single(i => i.ZoomLevel == zoom).InverseScale;

                var directory = $"{outputFolderPath}\\{zoom}";

                if (!System.IO.Directory.Exists(directory))
                {
                    System.IO.Directory.CreateDirectory(directory);
                }

                foreach (var tile in googleTiles)
                {
                    var geometries = this.GetGeometries(scale, tile.WebMercatorExtent);

                    var transform = IRI.Ham.SpatialBase.Mapping.MapUtility.GetMapToScreen(tile.WebMercatorExtent, 256, 256);

                    Func <Point, Point> mapToScreen = p =>
                    {
                        return(transform(p.AsPoint()).AsWpfPoint());
                    };

                    var pen = this.VisualParameters.GetGdiPlusPen();
                    pen.Width = 2;
                    var image = SqlSpatialToGdiBitmap.ParseSqlGeometry(
                        geometries,
                        256,
                        256,
                        mapToScreen,
                        pen,
                        this.VisualParameters.Fill.AsGdiBrush(),
                        this.VisualParameters.PointSize,
                        this.PointSymbol);

                    image.Save($"{directory}\\{tile.ZoomLevel}, {tile.RowNumber}, {tile.ColumnNumber}.jpg");
                }
            }
        }
Esempio n. 5
0
        //Gdi+ Approach
        public Path AsTileUsingGdiPlusAsync(List <SqlGeometry> geometries, List <string> labels, double mapScale, TileInfo region, double tileWidth, double tileHeight, RectangleGeometry area, Func <Point, Point> transform, sb.BoundingBox totalExtent)
        {
            if (geometries == null)
            {
                return(null);
            }

            //var pen = this.VisualParameters.Stroke != null ? new System.Drawing.Pen(this.VisualParameters.Stroke.AsGdiBrush(), (int)this.VisualParameters.StrokeThickness) : null;

            //if (this.VisualParameters.DashStyle != null)
            //{
            //    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
            //}

            var pen = this.VisualParameters.GetGdiPlusPen();

            var shiftX = region.WebMercatorExtent.Center.X - totalExtent.TopLeft.X - region.WebMercatorExtent.Width / 2.0;
            var shiftY = region.WebMercatorExtent.Center.Y - totalExtent.TopLeft.Y + region.WebMercatorExtent.Height / 2.0;
            //;

            //var transform = MapToTileScreenWpf(totalExtent, region.MercatorExtent, viewTransform);
            //var mapShift = new Point(region.MercatorExtent.Center.X - totalExtent.TopLeft.X, region.MercatorExtent.Center.Y - totalExtent.BottomRight.Y);
            //var mapShift = (mapBoundingBoxOfTile.Center - new sb.Point(totalExtent.TopLeft.X + mapBoundingBoxOfTile.Width / 2.0, totalExtent.TopLeft.Y - mapBoundingBoxOfTile.Height / 2.0)).AsWpfPoint();


            var image = SqlSpatialToGdiBitmap.ParseSqlGeometry(
                geometries,
                tileWidth,
                tileHeight,
                //transform,
                p => transform(new Point(p.X - shiftX, p.Y - shiftY)),
                pen,
                this.VisualParameters.Fill.AsGdiBrush(),
                this.VisualParameters.PointSize,
                this.PointSymbol);

            if (image == null)
            {
                return(null);
            }

            if (labels != null)
            {
                //96.05.19
                //SqlSpatialToGdiBitmap.DrawLabels(labels, geometries, image, transform, Labels);
            }

            var bitmapImage = IRI.Jab.Common.Helpers.ImageUtility.AsBitmapImage(image, System.Drawing.Imaging.ImageFormat.Png);

            image.Dispose();

            Path path = new Path()
            {
                Data = area,
                Tag  = new LayerTag(mapScale)
                {
                    Layer = this, IsTiled = true, Tile = new TileInfo(region.RowNumber, region.ColumnNumber, region.ZoomLevel), IsDrawn = true, IsNew = true
                }
            };

            this.Element = path;

            path.Fill = new ImageBrush(bitmapImage);

            return(path);
        }