/// <inheritdoc/>
        public Stream GetImageStream(int x, int y, int zoom)
        {
            // calc rect from tile key
            var rect = GeoTransform.TileToPtvMercatorAtZoom(x, y, zoom);

            return(GetImageStream(rect.Left, rect.Top, rect.Right, rect.Bottom, 256, 256));
        }
        /// <summary> Creates a stream object containing the image at position (<paramref name="x"/>,<paramref name="y"/>)
        /// and zoom level <paramref name="zoom"/>. </summary>
        /// <param name="x"> X-coordinate for the requested tile. </param>
        /// <param name="y"> Y-coordinate for the requested tile. </param>
        /// <param name="zoom"> Zoom level. </param>
        /// <returns> The stream object containing the image of the tile. </returns>
        public Stream GetImageStream(int x, int y, int zoom)
        {
            // Create a bitmap of size 256x256
            using (var bmp = new Bitmap(256, 256))
            {
                // calc rect from tile key
                var rect = GeoTransform.TileToPtvMercatorAtZoom(x, y, zoom);

                // PTV_Mercator to Image function
                Func <double, double, Point> mercatorToImage =
                    (mercatorX, mercatorY) => new Point(
                        x = (int)((mercatorX - rect.Left) / (rect.Right - rect.Left) * 256),
                        y = 256 + (int)-((mercatorY - rect.Top) / (rect.Bottom - rect.Top) * 256));

                // get graphics from bitmap
                using (var graphics = Graphics.FromImage(bmp))
                {
                    // query the provider for the items in the envelope
                    var result = Provider.QueryBBox(rect.Left, rect.Top, rect.Right, rect.Bottom, Theme.RequiredFields);

                    foreach (var item in result)
                    {
                        // create GDI path from wkb
                        var path = WkbToGdi.Parse(item.Wkb, mercatorToImage);

                        // evalutate style
                        var style = Theme.Mapping(item);

                        // fill polyong
                        if (style.Fill != null)
                        {
                            graphics.FillPath(style.Fill, path);
                        }

                        // draw outline
                        if (style.Outline != null)
                        {
                            graphics.DrawPath(style.Outline, path);
                        }
                    }
                }

                // crate a memory stream
                var stream = new MemoryStream();

                // save image to stream
                bmp.Save(stream, ImageFormat.Png);

                // rewind stream
                stream.Seek(0, SeekOrigin.Begin);

                return(stream);
            }
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public Stream GetImageStream(int tileX, int tileY, int zoom)
        {
            Rect rect = GeoTransform.TileToPtvMercatorAtZoom(tileX, tileY, zoom);

            return(GetImageStream(rect.Left, rect.Top, rect.Right, rect.Bottom, 256, 256));
        }