Mapstache.GraphicsPathBuilder.Build C# (CSharp) Method

Build() public method

public Build ( SqlGeography geography ) : GraphicsPath
geography SqlGeography
return System.Drawing.Drawing2D.GraphicsPath
        public GraphicsPath Build(SqlGeography geography)
        {
            var graphicsPath = new GraphicsPath();
            graphicsPath.FillMode = FillMode.Alternate;
            var geometryType = geography.STGeometryType();
            if (geometryType == "Polygon")
            {
                AddPolygon(geography, graphicsPath);
            }
            else if (geometryType == "MultiPolygon")
            {
                AddMultiPolygon(geography, graphicsPath);
            }
            else if (geometryType == "GeometryCollection")
            {
                for (int i = 0; i < geography.STNumGeometries(); i++)
                {
                    var geom = geography.STGeometryN(i + 1);
                    if (geom.STGeometryType().Value == "Polygon")
                    {
                        AddPolygon(geom, graphicsPath);
                    }
                    else if (geom.STGeometryType().Value == "MultiPolygon")
                    {
                        AddMultiPolygon(geom, graphicsPath);
                    }
                }
            }
            else
            {
                throw new NotSupportedException(string.Format("The geometry type {0} is not supported.", geometryType));
            }
            return graphicsPath;
        }

Usage Example

示例#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");
 }
All Usage Examples Of Mapstache.GraphicsPathBuilder::Build