/// <summary> /// Extracts a polygon from the input element and applies style information to the placemark descriptor. /// </summary> /// <param name="kmlStyle">KML Style information.</param> /// <param name="geomElement">Polygon geometry information.</param> /// <returns>A PlacemarkDescriptor object representing the feature.</returns> private static PlacemarkDescriptor ExtractPolygon(KMLStyle kmlStyle, XElement geomElement) { XNamespace kmlNS = geomElement.Name.Namespace; ESRI.ArcGIS.Client.Geometry.Polygon polygon = new Polygon(); // Extract outer polygon boundary XElement boundary; boundary = geomElement.Element(kmlNS + "outerBoundaryIs"); if (boundary != null) { ESRI.ArcGIS.Client.Geometry.PointCollection pts = ExtractRing(boundary); if (pts != null && pts.Count > 0) { polygon.Rings.Add(pts); } } // Extract holes (if any) IEnumerable<XElement> holes = from e in geomElement.Descendants(kmlNS + "innerBoundaryIs") select e; foreach (XElement hole in holes) { ESRI.ArcGIS.Client.Geometry.PointCollection pts = ExtractRing(hole); if (pts != null && pts.Count > 0) { polygon.Rings.Add(pts); } } // Create symbol and use style information PolygonSymbolDescriptor sym = new PolygonSymbolDescriptor(); sym.style = kmlStyle; if (polygon.Rings.Count > 0) { // Create feature descriptor from geometry and other information return new PlacemarkDescriptor() { Geometry = polygon, Symbol = sym }; } return null; }
/// <summary> /// Extracts a polygon from the input element and applies style information to the placemark descriptor. /// </summary> /// <param name="kmlStyle">KML Style information.</param> /// <param name="geomElement">Polygon geometry information.</param> /// <returns>A PlacemarkDescriptor object representing the feature.</returns> private static PlacemarkDescriptor ExtractLatLonBox(KMLStyle kmlStyle, XElement geomElement) { XNamespace kmlNS = geomElement.Name.Namespace; ESRI.ArcGIS.Client.Geometry.Polygon polygon = new Polygon(); double? north = null, south = null, east = null, west = null; double temp; XElement boundary; // Extract box values boundary = geomElement.Element(kmlNS + "north"); if (boundary != null) { if (double.TryParse(boundary.Value, System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture, out temp)) north = temp; } boundary = geomElement.Element(kmlNS + "south"); if (boundary != null) { if (double.TryParse(boundary.Value, System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture, out temp)) south = temp; } boundary = geomElement.Element(kmlNS + "east"); if (boundary != null) { if (double.TryParse(boundary.Value, System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture, out temp)) east = temp; } boundary = geomElement.Element(kmlNS + "west"); if (boundary != null) { if (double.TryParse(boundary.Value, System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture, out temp)) west = temp; } if (north.HasValue && south.HasValue && east.HasValue && west.HasValue) { ESRI.ArcGIS.Client.Geometry.PointCollection pts = new PointCollection(); MapPoint mp1 = new MapPoint(west.Value, north.Value); pts.Add(mp1); MapPoint mp2 = new MapPoint(east.Value, north.Value); pts.Add(mp2); MapPoint mp3 = new MapPoint(east.Value, south.Value); pts.Add(mp3); MapPoint mp4 = new MapPoint(west.Value, south.Value); pts.Add(mp4); polygon.Rings.Add(pts); // Create symbol and use style information PolygonSymbolDescriptor sym = new PolygonSymbolDescriptor(); sym.style = kmlStyle; // Create feature descriptor from geometry and other information return new PlacemarkDescriptor() { Geometry = polygon, Symbol = sym }; } return null; }