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")); }
private static GraphicsPath CreateGraphicsPath(RectangleF bounds, Bitmap bitmap, SqlGeography geography) { var builder = new GraphicsPathBuilder(bounds, bitmap.Size); var gp = builder.Build(geography); return(gp); }