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;
}