Exemplo n.º 1
0
 public ActionResult Index(int x, int y, int z)
 {
     var ymax = 1 << z;
     y = ymax - y - 1;
     var memoryStream = new MemoryStream();
     using (var bitmap = new Bitmap(256, 256))
     using (var g = Graphics.FromImage(bitmap))
     using (var pen = new Pen(Color.Blue, 2.0f))
     {
         g.CompositingMode = CompositingMode.SourceOver;
         g.CompositingQuality = CompositingQuality.HighQuality;
         var boundsGeographyLL = GetBoundingBoxInLatLng(x, y, z);
         if (boundsGeographyLL.Bottom > 0)
         {
             var states = new GeometryDataSource().Query(boundsGeographyLL.ToSqlGeography(), "states");
             var builder = new GraphicsPathBuilder(SphericalMercator.FromLonLat(boundsGeographyLL), new Size(256 ,256));
             foreach (var state in states)
             {
                 var geography = (SqlGeography) state["geom"];
                 {
                     using (var gp = builder.Build(geography))
                     {
                         g.DrawPath(pen, gp);
                     }
                 }
             }
         }
         bitmap.Save(memoryStream, ImageFormat.Png);
     }
     return File(memoryStream.ToArray(), "image/png");
 }
Exemplo n.º 2
0
        public ActionResult Index(int width, int height, string bbox, string layers)
        {
            var bounds = CreateBBox(bbox);
            var boundsLL = SphericalMercator.ToLonLat(bounds);
            var boundsGeographyLL = boundsLL.ToSqlGeography();
            var  states = new GeometryDataSource().Query(boundsGeographyLL, "states");;

            var memoryStream = new MemoryStream();
            using (var bitmap = new Bitmap(width, height))
            using (var g = Graphics.FromImage(bitmap))
            using (var pen = new Pen(Color.Blue,2.0f))
            {
                g.CompositingMode = CompositingMode.SourceOver;
                g.CompositingQuality = CompositingQuality.HighQuality;
                foreach (var state in states)
                {
                    var geography = (SqlGeography)state["geom"];
                    {
                        using (var gp = CreateGraphicsPath(bounds, bitmap, geography))
                        {
                            g.DrawPath(pen, gp);
                        }
                    }
                }
                bitmap.Save(memoryStream, ImageFormat.Png);
            }
            return File(memoryStream.ToArray(), "image/png");
        }