Beispiel #1
0
        //
        // GET: /Wmts/


        //wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=layer_id&STYLE=default&TILEMATRIXSET=matrix_id&TILEMATRIX=3&TILEROW=2&TILECOL=0&FORMAT=image%2Fjpeg
        public ActionResult Index(string service, string request, string version, string layer, string style, string matrixset, int tileMatrix, int tileRow, int tileCol, string format)
        {
            var ymax    = 1 << tileMatrix;
            var tiyleY2 = ymax - tileMatrix - 1;
            var quadKey = TileSystemHelper.TileXYToQuadKey(tileRow, tileCol, tileMatrix);

            var lonlat = TileSystemHelper.PixelXYToLatLong(new Point(tileRow * 256, tileCol * 256), tileMatrix);

            var memoryStream = new MemoryStream();

            using (var bitmap = new Bitmap(256, 256))
                using (var graphics = Graphics.FromImage(bitmap))
                    using (var fontBrush = new SolidBrush(Color.Blue))
                        using (var font = new Font(FontFamily.GenericMonospace, 10))
                        {
                            graphics.DrawLine(Pens.Red, 0, 0, 256, 256);

                            graphics.DrawString(string.Format("TMS {0},{1} Zoom:{2}", tileRow, tileCol, tileMatrix), font, fontBrush,
                                                new PointF(0, 0));
                            graphics.DrawString(string.Format("Lon {0}:{1}", lonlat.X, lonlat.Y), font, fontBrush,
                                                new PointF(0, 15));
                            bitmap.Save(memoryStream, ImageFormat.Png);
                        }
            return(File(memoryStream.ToArray(), "image/png"));
        }
Beispiel #2
0
        public RectangleF GetBoundingBoxInLatLngWithMargin(int tileX, int tileY, int zoom)
        {
            var lonlat1 = TileSystemHelper.PixelXYToLatLong(new Point((tileX * 256), (tileY * 256)), zoom);
            var lonlat2 = TileSystemHelper.PixelXYToLatLong(new Point(((tileX + 1) * 256), ((tileY + 1) * 256)), zoom);

            return(RectangleF.FromLTRB(lonlat1.X, lonlat2.Y, lonlat2.X, lonlat1.Y));
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            RectangleF       rectf = gen.GeoEnvelope2Viewport(new Envelope(-180, -90, 180, 90));
            RectangleF       fullRect = new RectangleF(-20037510f, -19993420, 40075020f, 39986840f);
            TileSystemHelper h = new TileSystemHelper(rectf, new Size(256, 256), 20);
            int totalWidth = 0, totalHeight = 0;

            TileDef[] tiles = h.ComputeTiles(2, new RectangleF(-20037510f, -19993420, 40075020f, 39986840f), out totalWidth, out totalHeight);;
            foreach (TileDef tile in tiles)
            {
                Size       size = new Size(256, 256);
                Image      img  = new Bitmap(size.Width, size.Height);
                RectangleF rect = gen.GetMapImage(tile.Rect, size, ref img);
                img.Save("d:\\temp\\" + tile.Quadkey + ".png", ImageFormat.Png);
            }
        }
Beispiel #4
0
        private Envelope GetBoundingBoxInLatLngWithMargin(int tileX, int tileY, int zoom)
        {
            Point px1 = new Point((tileX * 256), (tileY * 256));
            Point px2 = new Point(((tileX + 1) * 256), ((tileY + 1) * 256));

            PointF ll1 = TileSystemHelper.PixelXYToLatLong(px1, zoom);
            PointF ll2 = TileSystemHelper.PixelXYToLatLong(px2, zoom);

            double[] prj1 = this.projection.MathTransform.Transform(new double[] { ll1.X, ll1.Y });
            double[] prj2 = this.projection.MathTransform.Transform(new double[] { ll2.X, ll2.Y });

            Envelope bbox = new Envelope();

            bbox.ExpandToInclude(prj1[0], prj1[1]);
            bbox.ExpandToInclude(prj2[0], prj2[1]);
            return(bbox);
        }
Beispiel #5
0
        public ActionResult IndexInfo(string version, string layer, int x, int y, int z)
        {
            var lonlat = TileSystemHelper.PixelXYToLatLong(new Point(x * 256, y * 256), z);

            var memoryStream = new MemoryStream();

            using (var bitmap = new Bitmap(256, 256))
                using (var graphics = Graphics.FromImage(bitmap))
                    using (var fontBrush = new SolidBrush(Color.Blue))
                        using (var font = new Font(FontFamily.GenericMonospace, 10))
                        {
                            graphics.DrawLine(Pens.Red, 0, 0, 256, 256);

                            graphics.DrawString(string.Format("TMS {0},{1} Zoom:{2}", x, y, z), font, fontBrush,
                                                new PointF(0, 0));
                            graphics.DrawString(string.Format("Lon {0}:{1}", lonlat.X, lonlat.Y), font, fontBrush,
                                                new PointF(0, 15));
                            bitmap.Save(memoryStream, ImageFormat.Png);
                        }
            return(File(memoryStream.ToArray(), "image/png"));
        }