/// <summary> /// Converts a Polygon into a Bing Maps MapPolygon with a defined style. /// </summary> /// <param name="polygon">Polygon to convert to a MapPolygon.</param> /// <param name="style">Style to use to render shape</param> /// <returns>A MapElement that represent the Polygon.</returns> public static MapElement GenerateMapShape(Polygon polygon, ShapeStyle style) { if (polygon != null && polygon.ExteriorRing != null && polygon.ExteriorRing.Count >= 3) { var shapes = new Collection <MapElement>(); var locs = polygon.ExteriorRing; //Ensure polygon is closed. locs.Add(locs[0]); //Outline inner rings. foreach (var i in polygon.InteriorRings) { //Ensure inner ring is closed. i.Add(i[0]); //Add inner rings to main list of locations locs.AddRange(i); //Loop back to starting point. locs.Add(locs[0]); } var poly = new MapPolygon(); foreach (var p in locs.ToBMGeometry()) { poly.Path.Add(p); } //Set polygon style ApplyStyle(poly, style); //Add metadata as to Tag property if added in Bing Maps if (poly != null) { poly.SetValue(MapElementExt.TagProperty, polygon.Metadata); } return(poly); } return(null); }
/// <summary> /// Converts a Polygon into a MapPolygon. /// Note that MapPolygon's do not support holes. /// </summary> /// <param name="polygon">A Polygon object</param> /// <returns>A MapPolygon object</returns> public static MapPolygon ToBMGeometry(this Polygon polygon) { var myPoly = new MapPolygon() { Path = polygon.ExteriorRing.ToBMGeometry(), FillColor = new Color() { A = 150, G = 255 }, StrokeColor = new Color() { A = 150, G = 255 }, StrokeThickness = 3 }; myPoly.SetValue(MapElementExt.TagProperty, polygon.Metadata); //TODO: Add support for holes/inner rings in the future. return(myPoly); }
public static List <MapShape> GenerateMapShape(Polygon polygon, ShapeStyle style) { if (polygon != null && polygon.ExteriorRing != null && polygon.ExteriorRing.Count >= 3) { var shapes = new List <MapShape>(); var locs = polygon.ExteriorRing; //Ensure polygon is closed. locs.Add(locs[0]); //This uses a workaround to create outline of polygon if (style == null || style.OutlinePolygon) { var l = GenerateMapShape(locs, style); if (l != null) { shapes.Add(l); } } //Outline inner rings. foreach (var i in polygon.InteriorRings) { //Ensure inner ring is closed. i.Add(i[0]); var l = GenerateMapShape(i, style); if (l != null) { if (style == null || style.OutlinePolygon) { shapes.Add(l); } //Add inner rings to main list of locations locs.AddRange(i); //Loop back to starting point. locs.Add(locs[0]); } } var poly = new MapPolygon() { Locations = locs.ToBMGeometry() }; //Set polygon style ApplyStyle(poly, style); //Add metadata as to Tag property if added in Bing Maps if (poly != null) { poly.SetValue(MapShapeExt.TagProperty, polygon.Metadata); } shapes.Insert(0, poly); return(shapes); } return(null); }