public void WritePlacemark(Placemark pm) { if (pm != null) { WriteStartElement("Placemark"); WriteComment("Placemark Guid: " + pm.CN); WriteElementString("name", pm.Name); WriteKmlDescription(pm.Desctription); if (pm.View != null && pm.View.Coordinates != null) { WriteView(pm.View); } else { View v = new View(); if (pm.Polygons != null && pm.Polygons.Count > 0) { Polygon poly = pm.Polygons[0]; if (poly.HasOuterBoundary) { v.Coordinates = poly.GetOBAveragedCoords(); v.AltMode = poly.AltMode; WriteView(v); } else if (poly.HasInnerBoundary) { v.Coordinates = poly.GetIBAveragedCoords(); v.AltMode = poly.AltMode; WriteView(v); } } else if (pm.Points != null && pm.Points.Count > 0) { v.Coordinates = pm.Points[0].Coordinates; v.AltMode = pm.Points[0]._AltMode; WriteView(v); } } if (pm.StyleUrl != null && pm.StyleUrl != "") { WriteElementString("styleUrl", pm.StyleUrl); } if (pm.Visibility != null) { WriteElementString("visibility", ConvertBool((bool)pm.Visibility).ToString()); } if (pm.Open != null) { WriteElementString("open", ConvertBool((bool)pm.Open).ToString()); } WriteProperties(pm); if ((pm.Points.Count + pm.Polygons.Count) > 1) { WriteStartElement("MultiGeometry"); foreach (Polygon poly in pm.Polygons) { WritePolygon(poly); } foreach (KmlPoint point in pm.Points) { WritePoint(point); } //end MultiGeo WriteEndElement(); } else { if (pm.Polygons.Count > 0) { WritePolygon(pm.Polygons[0]); } else if (pm.Points.Count > 0) { WritePoint(pm.Points[0]); } } //end placemark WriteEndElement(); } }
private static Placemark ParsePlacemark(XmlNode xnode) { Placemark placemark = new Placemark(xnode.Attributes[ATTR_ID]?.FirstChild.Value); foreach (XmlNode node in xnode.ChildNodes) { string name = node.Name.ToLower(); switch (name) { case "lookat": placemark.View = ParseView(node); break; case "point": { KmlPoint point = ParsePoint(node); if (point != null) { placemark.Points.Add(point); } break; } case "polygon": case "linestring": { Polygon poly = ParsePolygon(node); if (poly != null) { placemark.Polygons.Add(poly); } break; } case "multigeometry": { foreach (XmlNode inode in node.ChildNodes) { switch (inode.Name.ToLower()) { case "point": { KmlPoint point = ParsePoint(node); if (point != null) { placemark.Points.Add(point); } break; } case "polygon": case "linestring": { Polygon poly = ParsePolygon(node); if (poly != null) { placemark.Polygons.Add(poly); } break; } } } break; } default: ParseProperties(placemark, name, node); break; } } return(placemark); }