From d175b07ef29ef40cbfac026325792f5cf4ff9d12 Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Thu, 16 Mar 2017 13:01:57 +1030 Subject: [PATCH 1/3] Add support for reading simple ExtendedData tag --- Source/KML.swift | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/Source/KML.swift b/Source/KML.swift index d8786f3..ef4add3 100644 --- a/Source/KML.swift +++ b/Source/KML.swift @@ -29,6 +29,8 @@ public enum KMLTag: String { case Folder case Placemark case Icon + case ExtendedData + case Data public var str: String { return self.rawValue @@ -50,7 +52,9 @@ public struct KMLConfig { KMLTag.Folder.str: KMLElement.self, KMLTag.Placemark.str: KMLPlacemark.self, KMLTag.Icon.str: KMLIcon.self, - KMLTag.IconStyle.str: KMLIconStyle.self + KMLTag.IconStyle.str: KMLIconStyle.self, + KMLTag.ExtendedData.str: KMLExtendedData.self, + KMLTag.Data.str: KMLData.self ] } @@ -390,6 +394,7 @@ open class KMLPlacemark: KMLElement { open var lineString: KMLLineString? open var polygon: KMLPolygon? open var style: KMLStyle? + open var extendedData: KMLExtendedData? public required init(_ element: AEXMLElement) { let style = element["styleUrl"].string @@ -409,6 +414,43 @@ open class KMLPlacemark: KMLElement { } else if let polygonGeometry = findElement(KMLPolygon.self) { polygon = polygonGeometry } + + extendedData = findElement(KMLExtendedData.self) + } +} + +// MARK: - Extended Data + +open class KMLExtendedData: KMLElement { + open var data: [String: KMLData] = [:] + + public required init(_ element: AEXMLElement) { + super.init(element) + for dataElement in findElements(KMLData.self) { + self.data[dataElement.dataName] = dataElement + } + } +} + +open class KMLData: KMLElement { + open var dataName: String = "" + open var displayName: String? + open var value: String? + + public required init(_ element: AEXMLElement) { + self.dataName = element.attributes["name"] ?? "" + + for child: AEXMLElement in element.children { + switch child.name { + case "displayName": + displayName = child.string + case "value": + value = child.string + default: + break + } + } + super.init(element) } } From 9b353c47ee146e0e7f82b714925bb823be2ae0ed Mon Sep 17 00:00:00 2001 From: Shane Woolcock Date: Fri, 17 Mar 2017 08:53:57 +1030 Subject: [PATCH 2/3] Add a reference from the KMLAnnotation viewmodel class to the associated KMLPlacemark model class --- Source/KML.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/KML.swift b/Source/KML.swift index ef4add3..3e679f1 100644 --- a/Source/KML.swift +++ b/Source/KML.swift @@ -466,6 +466,7 @@ open class KMLAnnotation: NSObject, MKAnnotation { open var title: String? open var subtitle: String? open var style: KMLStyle? + open var placemark: KMLPlacemark? init(_ coordinate: CLLocationCoordinate2D) { self.coordinate = coordinate @@ -622,6 +623,7 @@ open class KMLDocument: KMLElement { annotation.title = pointPlacemark.name annotation.subtitle = pointPlacemark.description annotation.style = pointPlacemark.style + annotation.placemark = pointPlacemark self.annotations.append(annotation) } From 268a62f0c568e556ecf3cf0466e6a94c980e94cc Mon Sep 17 00:00:00 2001 From: Andreas Wulf Date: Wed, 15 Nov 2017 14:17:02 +1030 Subject: [PATCH 3/3] Ignore invalid coordinates --- Source/KML.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/KML.swift b/Source/KML.swift index 3e679f1..00b4fe0 100644 --- a/Source/KML.swift +++ b/Source/KML.swift @@ -81,8 +81,9 @@ open class KMLElement { let lines: [String] = element.string.components(separatedBy: CharacterSet.whitespacesAndNewlines) for line in lines { let points: [String] = line.components(separatedBy: ",") - assert(points.count >= 2, "points lenth is \(points)") - coordinates.append(CLLocationCoordinate2DMake(atof(points[1]), atof(points[0]))) + if points.count >= 2 { + coordinates.append(CLLocationCoordinate2DMake(atof(points[1]), atof(points[0]))) + } } return coordinates }