private static void FillPlacemarkWithGeometry(ref KmlPlaceMark placeMark, ref SharpKml.Dom.Geometry geo) { if (geo is SharpKml.Dom.Polygon) { SharpKml.Dom.Polygon polygon = geo as SharpKml.Dom.Polygon; if (polygon.OuterBoundary != null) { placeMark.Geometry = new GMapCommonType.Polygon(CoordinatesToPoints(polygon.OuterBoundary.LinearRing.Coordinates)); } } if (geo is SharpKml.Dom.Point) { SharpKml.Dom.Point point = geo as SharpKml.Dom.Point; placeMark.Geometry = new Point2D(point.Coordinate.Longitude, point.Coordinate.Latitude); } if (geo is SharpKml.Dom.LineString) { SharpKml.Dom.LineString str = geo as SharpKml.Dom.LineString; placeMark.Geometry = new Polyline(CoordinatesToPoints(str.Coordinates)); } }
public KmlPlaceMark(KmlPlaceMark mark) { this.Name = mark.Name; this.Description = mark.Description; this.Geometry = mark.Geometry; }
public static List <KmlPlaceMark> GetPlaceMarksFromKmlFile(string kmlFile) { string compatibleXml = GetCompatibleXml(new StreamReader(kmlFile).ReadToEnd()); using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(compatibleXml))) { KmlFile file = KmlFile.Load(stream); List <KmlPlaceMark> list = new List <KmlPlaceMark>(); foreach (Placemark placemark in file.Root.Flatten().OfType <Placemark>()) { try { Geometry geo = placemark.Geometry; if (geo != null) { if (geo is MultipleGeometry) { MultipleGeometry geometry2 = geo as MultipleGeometry; if (geometry2.Geometry != null) { foreach (Geometry geometry3 in geometry2.Geometry) { KmlPlaceMark placeMark = new KmlPlaceMark { Name = placemark.Name, StyleUrl = placemark.StyleUrl.ToString() }; if (placemark.Description != null) { placeMark.Description = placemark.Description.Text; } Geometry geometry4 = geometry3; FillPlacemarkWithGeometry(ref placeMark, ref geometry4); list.Add(placeMark); } } } else { KmlPlaceMark mark2 = new KmlPlaceMark { Name = placemark.Name }; if (placemark.Description != null) { mark2.Description = placemark.Description.Text; } FillPlacemarkWithGeometry(ref mark2, ref geo); list.Add(mark2); } } continue; } catch { continue; } } return(list); } }