From b15e517a777465137a8dbf8711d1a0c13bba6532 Mon Sep 17 00:00:00 2001 From: Greg Pardo Date: Wed, 28 Dec 2016 15:55:58 -0500 Subject: [PATCH 1/4] Add Mapbox support in subspec --- Kml-Mapbox/AppDelegate.swift | 46 +++ .../AppIcon.appiconset/Contents.json | 68 +++++ Kml-Mapbox/Base.lproj/LaunchScreen.storyboard | 27 ++ Kml-Mapbox/Base.lproj/Main.storyboard | 58 ++++ .../Examples/Path/PathViewController.swift | 52 ++++ .../Examples/Path/PathViewController.xib | 37 +++ .../Placemark/PlacemarkViewController.swift | 38 +++ .../Placemark/PlacemarkViewController.xib | 37 +++ Kml-Mapbox/Info.plist | 47 +++ Kml-Mapbox/MainViewController.swift | 58 ++++ Kml-Mapbox/sample.kml | 225 ++++++++++++++ Kml.swift.podspec | 24 +- Kml.xcodeproj/project.pbxproj | 278 +++++++++++++++++- Kml/Base.lproj/Main.storyboard | 19 +- Kml/Examples/Path/PathViewController.swift | 4 +- Kml/Examples/Path/PathViewController.xib | 15 +- .../Placemark/PlacemarkViewController.xib | 15 +- .../AppIcon.appiconset/Contents.json | 25 ++ Kml/Info.plist | 2 + Kml/MainViewController.swift | 5 - Podfile | 7 +- Podfile.lock | 7 +- Source/KML.swift | 240 +++------------ Source/MapKit/KML+MapKit.swift | 207 +++++++++++++ Source/Mapbox/KML+Mapbox.swift | 218 ++++++++++++++ 25 files changed, 1511 insertions(+), 248 deletions(-) create mode 100644 Kml-Mapbox/AppDelegate.swift create mode 100644 Kml-Mapbox/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Kml-Mapbox/Base.lproj/LaunchScreen.storyboard create mode 100644 Kml-Mapbox/Base.lproj/Main.storyboard create mode 100644 Kml-Mapbox/Examples/Path/PathViewController.swift create mode 100644 Kml-Mapbox/Examples/Path/PathViewController.xib create mode 100644 Kml-Mapbox/Examples/Placemark/PlacemarkViewController.swift create mode 100644 Kml-Mapbox/Examples/Placemark/PlacemarkViewController.xib create mode 100644 Kml-Mapbox/Info.plist create mode 100644 Kml-Mapbox/MainViewController.swift create mode 100644 Kml-Mapbox/sample.kml create mode 100644 Source/MapKit/KML+MapKit.swift create mode 100644 Source/Mapbox/KML+Mapbox.swift diff --git a/Kml-Mapbox/AppDelegate.swift b/Kml-Mapbox/AppDelegate.swift new file mode 100644 index 0000000..ab9178e --- /dev/null +++ b/Kml-Mapbox/AppDelegate.swift @@ -0,0 +1,46 @@ +// +// AppDelegate.swift +// Kml-Mapbox +// +// Created by Greg Pardo on 12/28/16. +// Copyright © 2016 asus4. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + func applicationWillResignActive(_ application: UIApplication) { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(_ application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(_ application: UIApplication) { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(_ application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(_ application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/Kml-Mapbox/Assets.xcassets/AppIcon.appiconset/Contents.json b/Kml-Mapbox/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..36d2c80 --- /dev/null +++ b/Kml-Mapbox/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Kml-Mapbox/Base.lproj/LaunchScreen.storyboard b/Kml-Mapbox/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..fdf3f97 --- /dev/null +++ b/Kml-Mapbox/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Kml-Mapbox/Base.lproj/Main.storyboard b/Kml-Mapbox/Base.lproj/Main.storyboard new file mode 100644 index 0000000..7246932 --- /dev/null +++ b/Kml-Mapbox/Base.lproj/Main.storyboard @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Kml-Mapbox/Examples/Path/PathViewController.swift b/Kml-Mapbox/Examples/Path/PathViewController.swift new file mode 100644 index 0000000..1518c26 --- /dev/null +++ b/Kml-Mapbox/Examples/Path/PathViewController.swift @@ -0,0 +1,52 @@ +// +// PathViewController.swift +// Kml +// +// Created by Koki Ibukuro on 8/18/15. +// Copyright (c) 2015 asus4. All rights reserved. +// + +import UIKit +import Mapbox + +// Path to MKPolylineRenderer +// Polygon to MKPolygonRenderer +class PathViewController: UIViewController { + + @IBOutlet weak var mapView: MGLMapView! + + override func viewDidLoad() { + super.viewDidLoad() + mapView.delegate = self + loadKml("sample") + } + + fileprivate func loadKml(_ path: String) { + let url = Bundle.main.url(forResource: path, withExtension: "kml") + KMLDocument.parse(url!, callback: + { [unowned self] (kml) in + self.mapView.add(kml.overlays) + self.mapView.addAnnotations(kml.annotations) + self.mapView.showAnnotations(kml.annotations, animated: true) + } + ) + } +} + +extension PathViewController: MGLMapViewDelegate { + func mapView(_ mapView: MGLMapView, alphaForShapeAnnotation annotation: MGLShape) -> CGFloat { + return annotation.alpha + } + func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColor { + return annotation.strokeColor ?? UIColor.black + } + func mapView(_ mapView: MGLMapView, fillColorForPolygonAnnotation annotation: MGLPolygon) -> UIColor { + return annotation.fillColor ?? UIColor.lightGray + } + func mapView(_ mapView: MGLMapView, lineWidthForPolylineAnnotation annotation: MGLPolyline) -> CGFloat { + return annotation.lineWidth + } + func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { + return true + } +} diff --git a/Kml-Mapbox/Examples/Path/PathViewController.xib b/Kml-Mapbox/Examples/Path/PathViewController.xib new file mode 100644 index 0000000..1268ffa --- /dev/null +++ b/Kml-Mapbox/Examples/Path/PathViewController.xib @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Kml-Mapbox/Examples/Placemark/PlacemarkViewController.swift b/Kml-Mapbox/Examples/Placemark/PlacemarkViewController.swift new file mode 100644 index 0000000..2eb2833 --- /dev/null +++ b/Kml-Mapbox/Examples/Placemark/PlacemarkViewController.swift @@ -0,0 +1,38 @@ +// +// PlacemarkViewController.swift +// Kml +// +// Created by Koki Ibukuro on 8/17/15. +// Copyright (c) 2015 asus4. All rights reserved. +// + +import UIKit +import Mapbox + +// Placemark to MKAnnotation. +class PlacemarkViewController: UIViewController { + + @IBOutlet weak var mapView: MGLMapView! + + override func viewDidLoad() { + super.viewDidLoad() + mapView.delegate = self + loadKml("sample") + } + + fileprivate func loadKml(_ path: String) { + let url = Bundle.main.url(forResource: path, withExtension: "kml") + KMLDocument.parse(url!, callback: + { [unowned self] (kml) in + self.mapView.addAnnotations(kml.annotations) + self.mapView.showAnnotations(kml.annotations, animated: true) + } + ) + } +} + +extension PlacemarkViewController: MGLMapViewDelegate { + func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { + return true + } +} diff --git a/Kml-Mapbox/Examples/Placemark/PlacemarkViewController.xib b/Kml-Mapbox/Examples/Placemark/PlacemarkViewController.xib new file mode 100644 index 0000000..9a243ea --- /dev/null +++ b/Kml-Mapbox/Examples/Placemark/PlacemarkViewController.xib @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Kml-Mapbox/Info.plist b/Kml-Mapbox/Info.plist new file mode 100644 index 0000000..3054e81 --- /dev/null +++ b/Kml-Mapbox/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + NSLocationAlwaysUsageDescription + $(PRODUCT_NAME) wants to use location + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/Kml-Mapbox/MainViewController.swift b/Kml-Mapbox/MainViewController.swift new file mode 100644 index 0000000..5b40f92 --- /dev/null +++ b/Kml-Mapbox/MainViewController.swift @@ -0,0 +1,58 @@ +// +// ViewController.swift +// Kml-Mapbox +// +// Created by Greg Pardo on 12/28/16. +// Copyright © 2016 asus4. All rights reserved. +// + +import UIKit +import Mapbox +import CoreLocation + +let MapboxAccessToken = "<# your Mapbox access token #>" + +class MainViewController: UITableViewController { + + let locationManager = CLLocationManager() + let dataSource: [(label: String, klass: UIViewController.Type, nib: String)] = [ + ("Placemark", PlacemarkViewController.self, "PlacemarkViewController"), + ("Path", PathViewController.self, "PathViewController"), + ] + + override func viewDidLoad() { + super.viewDidLoad() + assert(MapboxAccessToken != "<# your Mapbox access token #>", "You must set `MapboxAccessToken` to your Mapbox access token.") + MGLAccountManager.setAccessToken(MapboxAccessToken) + locationManager.requestAlwaysAuthorization() + } +} + +extension MainViewController { // UITableViewDataSource + + override func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return dataSource.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + if let cell = tableView.dequeueReusableCell(withIdentifier: "Sample") { + cell.textLabel?.text = dataSource[(indexPath as NSIndexPath).row].label + return cell + } + return UITableViewCell() + } +} + +extension MainViewController { // UITableViewDelegate + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let klass = dataSource[(indexPath as NSIndexPath).row].klass + let nibName = dataSource[(indexPath as NSIndexPath).row].nib + let controller: UIViewController = klass.init(nibName: nibName, bundle: nil) + controller.title = dataSource[(indexPath as NSIndexPath).row].label + self.navigationController?.pushViewController(controller, animated: true) + } +} diff --git a/Kml-Mapbox/sample.kml b/Kml-Mapbox/sample.kml new file mode 100644 index 0000000..c55a42a --- /dev/null +++ b/Kml-Mapbox/sample.kml @@ -0,0 +1,225 @@ + + + + sample.kml + + + + + + + normal + #s_ylw-pushpin + + + highlight + #s_ylw-pushpin_hl + + + + + + + normal + #sn_ylw-pushpin0 + + + highlight + #sh_ylw-pushpin + + + + + normal + #sn_ylw-pushpin + + + highlight + #sh_ylw-pushpin0 + + + + AnnotationSample + 1 + + Kaminarimon + + 139.7963334932216 + 35.71116258223716 + 0 + 1.285821014279927 + 0 + 115.8112879038772 + relativeToSeaFloor + + #m_ylw-pushpin + + 1 + 139.7963676213336,35.71109801215431,0 + + + + Shibuya + + 139.7004851892501 + 35.65986468701983 + 0 + 0.3033680304088734 + 30.00034471652417 + 214.7387673158762 + relativeToSeaFloor + + #m_ylw-pushpin + + 1 + 139.7005107613905,35.65946039224136,0 + + + + Harajuku + + 139.7039333529916 + 35.66985885805384 + 0 + -0.005137161495746808 + 25.6578183614213 + 388.809202553402 + relativeToSeaFloor + + #m_ylw-pushpin + + 1 + 139.702684321446,35.67018660227875,0 + + + + Shinjuku + + 139.7016858866769 + 35.68933102090881 + 0 + 0.004357314327384457 + 11.80936639635489 + 2309.816598946616 + relativeToSeaFloor + + #m_ylw-pushpin + + 1 + 139.7007715135468,35.68915252294777,0 + + + + Tsukiji Market + + 139.7706667814911 + 35.66548610103113 + 0 + -1.079159977032294e-08 + 0 + 1000.000052544537 + relativeToSeaFloor + + #m_ylw-pushpin + + 1 + 139.7706667814911,35.66548610103112,0 + + + + Untitled Polygon + #msn_ylw-pushpin0 + + 1 + + + + 139.7416213843898,35.71254699173437,0 139.7416252963524,35.71198732400437,0 139.7416350768698,35.71058904953911,0 139.7416282147725,35.70919148553565,0 139.7416111800425,35.70807348326826,0 139.7415941649307,35.7069557531461,0 139.7415730383121,35.70555898624796,0 139.7419068369385,35.70415740711034,0 139.7419014586558,35.70276315486409,0 139.7425867345183,35.70163625984515,0 139.7429296494568,35.70023795414795,0 139.7432871203354,35.69828662635519,0 139.7439912041231,35.69633206438857,0 139.7443436972431,35.69521715033194,0 139.7446967331429,35.69382592191995,0 139.7446868186361,35.69243827647382,0 139.7450200230982,35.69104521398952,0 139.745012036348,35.68993622932854,0 139.7453469838829,35.68882155487702,0 139.7460226023045,35.68742424263093,0 139.7460190129663,35.68576567083851,0 139.7460311806643,35.68438884911637,0 139.7463591114503,35.68299895017488,0 139.7466614201629,35.68187793046482,0 139.7466381715884,35.68104381999107,0 139.7470194154832,35.67884664009915,0 139.7473493922733,35.67773585093435,0 139.7476748993266,35.67607404253688,0 139.7476574637473,35.67386986095603,0 139.7479870205521,35.67276088707028,0 139.7486804003177,35.67110695963345,0 139.7490184891053,35.67027708544428,0 139.7507242283221,35.67024507644354,0 139.7517514042238,35.67104942170561,0 139.7531204179453,35.6718476905537,0 139.7538072158721,35.67265912096748,0 139.7551773331767,35.67345809343634,0 139.7568913300986,35.67452609008878,0 139.7582637907603,35.67532626538059,0 139.7596437245766,35.67667877785043,0 139.7606842199429,35.67831395548167,0 139.7610312413429,35.67885928056535,0 139.7624156008451,35.68048995142459,0 139.7627630321402,35.68103581959915,0 139.7638058729741,35.68267426632288,0 139.7645137662848,35.6845982982624,0 139.7648726817908,35.68597608027093,0 139.7655716125031,35.68707136315192,0 139.7659342824805,35.68872763627301,0 139.7666570572253,35.69176586872099,0 139.7670137806997,35.69286986012927,0 139.7673706662962,35.6939743461106,0 139.767737857147,35.69591299700047,0 139.7684460662462,35.69756892984948,0 139.7688108607379,35.6992320158358,0 139.7691724319756,35.70061770370021,0 139.7698891593335,35.70283387610401,0 139.7699046918459,35.70422729198486,0 139.769914220692,35.70506378481571,0 139.7699242280998,35.70590067841356,0 139.7682050927757,35.70621039145382,0 139.7668231254945,35.70595591108511,0 139.7644037737177,35.7059985329264,0 139.759547019756,35.70496666199449,0 139.7574634876989,35.70416590937057,0 139.7550405504306,35.7030932977836,0 139.7529651844832,35.70201524432598,0 139.7515825129803,35.70120409432623,0 139.7505455894812,35.7006654195479,0 139.7488175992163,35.69986057639179,0 139.7474378319058,35.69877238066351,0 139.74605452727,35.69851791854603,0 139.7446749048346,35.69770803300461,0 139.742259651742,35.6966383212941,0 139.7405334743425,35.69611222528129,0 139.7388076191303,35.69558622966463,0 139.7370829068619,35.69506034464382,0 139.735710230257,35.6936974087296,0 139.7336498366597,35.69290177975113,0 139.7319335926728,35.69237771358461,0 139.7302178409567,35.69185376729126,0 139.7285045316773,35.69077599827128,0 139.7274776516168,35.68996354146195,0 139.7261080817624,35.68915746243387,0 139.7247403798945,35.68807518620782,0 139.7271446789358,35.68720328541641,0 139.7305907183837,35.68714624967042,0 139.7340220919803,35.68708591235983,0 139.7357356172789,35.68705520001802,0 139.7374492214192,35.68702446745415,0 139.7395056644118,35.68698754978462,0 139.741219449437,35.68695678558585,0 139.743959743772,35.68663062911511,0 139.7463594633236,35.68658761746565,0 139.7490996931289,35.686261325917,0 139.7511566846227,35.68622424319712,0 139.7532137743102,35.6861871226845,0 139.7569853859058,35.68611897886021,0 139.7600715263083,35.68606312071084,0 139.7624720336091,35.68601962011805,0 139.7652156352212,35.68596985443071,0 139.7679594653451,35.68592000435579,0 139.7717357597318,35.68585254658557,0 139.7741389276528,35.68580955965013,0 139.7761988131187,35.68577268855959,0 139.7786020177558,35.6857296101994,0 139.7799752870694,35.68570497995459,0 139.7816918833069,35.68567416211365,0 139.7806824405375,35.68707740510106,0 139.7793248979295,35.68821039701832,0 139.7786458805214,35.68877706225322,0 139.77660021626,35.68992305059827,0 139.7752410142666,35.69105717062464,0 139.7742212009585,35.69190806142577,0 139.7728609183991,35.69304298821275,0 139.7714964457302,35.69390062775837,0 139.7687695532515,35.69589459960383,0 139.7674008789886,35.69647510159987,0 139.7650110698174,35.69790876682042,0 139.7636453700055,35.69876805587794,0 139.7591979586739,35.70107479960227,0 139.7567740282115,35.70222869648408,0 139.7522793767199,35.70481379484856,0 139.7498793398777,35.70653111671367,0 139.7467995508405,35.70882077299506,0 139.7447536277012,35.71053465415575,0 139.743713321403,35.71111191203703,0 139.7419705165019,35.71226107794961,0 139.7416213843898,35.71254699173437,0 + + + + + + + Untitled Path + #msn_ylw-pushpin + + 1 + + 139.7112050866653,35.72796235534361,0 139.7122244515789,35.7262979714291,0 139.7129029721786,35.72518907228218,0 139.7145831399648,35.72351617343138,0 139.7162364999407,35.72211948104986,0 139.7169013434001,35.72156070299504,0 139.7179151989388,35.72044785218866,0 139.718591714012,35.71961490853176,0 139.719944356234,35.71767648080731,0 139.7206204199065,35.71657124503146,0 139.7219711475676,35.71463546922183,0 139.7226456574678,35.7140776592539,0 139.724331556491,35.7118653823393,0 139.7253422874867,35.71021199299879,0 139.7260155832407,35.70965528227484,0 139.7266948422476,35.70828213054325,0 139.7277043596458,35.70663152878268,0 139.7270290766526,35.70609897036768,0 139.7256819788981,35.7061224258854,0 139.7243347275348,35.70641758703432,0 139.7229894823743,35.7064410968192,0 139.7216463656013,35.70646462322915,0 139.7182891473914,35.70706756331568,0 139.7156069846648,35.70711465161054,0 139.7139308445273,35.7071440387675,0 139.7112492129004,35.70719102027513,0 139.7075624969096,35.70725549534595,0 139.7042114831993,35.70731399377759,0 139.7015290852628,35.70736064966809,0 139.6985052205137,35.70741282954044,0 139.6964893304014,35.70744758677294,0 139.694809436977,35.70747653154385,0 139.6934612027706,35.70777166033139,0 139.6907686786623,35.70808990439255,0 139.6897467857995,35.70892355473958,0 139.6904007372973,35.71000102504676,0 139.6907324330955,35.71026761762943,0 139.6920560182886,35.71160694515523,0 139.6927164313182,35.7126860515516,0 139.6947140659782,35.71428845853828,0 139.6957066902285,35.71590954476203,0 139.6970403078322,35.7169794631098,0 139.6980389184286,35.71805576055294,0 139.6987224083005,35.71886405048461,0 139.6997639277935,35.71966558156534,0 139.701120086616,35.72100954081738,0 139.7024628173392,35.7220813233561,0 139.7038068207351,35.72287973209228,0 139.7051513870956,35.72367839223312,0 139.7061591467306,35.72448316826852,0 139.7075022350955,35.72583095968876,0 139.708848484127,35.72663071197847,0 139.7098577441623,35.72743657376567,0 139.7108658506475,35.72824286518446,0 139.7112035300139,35.72823701351384,0 + + + + + + diff --git a/Kml.swift.podspec b/Kml.swift.podspec index c613929..6bc2d24 100644 --- a/Kml.swift.podspec +++ b/Kml.swift.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Kml.swift" - s.version = "0.3.0" + s.version = "0.4.0" s.summary = "Simple KML parser for Swift." s.homepage = "https://github.com/asus4/Kml.swift" @@ -10,9 +10,25 @@ Pod::Spec.new do |s| s.social_media_url = "https://twitter.com/asus4" s.ios.deployment_target = '8.0' - s.source = { :git => 'https://github.com/asus4/Kml.swift.git', :tag => s.version } - s.source_files = 'Source/*.swift' - s.dependency 'AEXML' + s.source = { :git => 'https://github.com/gregpardo/Kml.swift.git', :tag => s.version } + s.default_subspec = "Core" + s.subspec "Core" do |ss| + ss.source_files = "Source/*.swift" + ss.dependency 'AEXML' + ss.frameworks = "Foundation" + end + s.subspec "MapKit" do |ss| + ss.source_files = "Source/MapKit/*.swift" + ss.dependency "Kml.swift/Core" + ss.frameworks = "Foundation", "MapKit" + end + + s.subspec "Mapbox" do |ss| + ss.source_files = "Source/Mapbox/*.swift" + ss.dependency "Kml.swift/Core" + ss.dependency "Mapbox-iOS-SDK", "~> 3.3" + ss.frameworks = "Foundation" + end end diff --git a/Kml.xcodeproj/project.pbxproj b/Kml.xcodeproj/project.pbxproj index d6946f5..b5d98e3 100644 --- a/Kml.xcodeproj/project.pbxproj +++ b/Kml.xcodeproj/project.pbxproj @@ -8,6 +8,20 @@ /* Begin PBXBuildFile section */ 30175AFC733F3AD031F32C0B /* Pods_Kml.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0597E1AC11EBC60AF4E981A1 /* Pods_Kml.framework */; }; + 43FFCB0E1E1439E800148916 /* KML+MapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43FFCB0D1E1439E800148916 /* KML+MapKit.swift */; }; + 43FFCB181E143C9D00148916 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43FFCB171E143C9D00148916 /* AppDelegate.swift */; }; + 43FFCB1A1E143C9D00148916 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43FFCB191E143C9D00148916 /* MainViewController.swift */; }; + 43FFCB1D1E143C9D00148916 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 43FFCB1B1E143C9D00148916 /* Main.storyboard */; }; + 43FFCB1F1E143C9D00148916 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 43FFCB1E1E143C9D00148916 /* Assets.xcassets */; }; + 43FFCB221E143C9D00148916 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 43FFCB201E143C9D00148916 /* LaunchScreen.storyboard */; }; + 43FFCB281E143CE100148916 /* sample.kml in Resources */ = {isa = PBXBuildFile; fileRef = 43FFCB271E143CE100148916 /* sample.kml */; }; + 43FFCB301E143D9800148916 /* PathViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43FFCB2B1E143D9800148916 /* PathViewController.swift */; }; + 43FFCB311E143D9800148916 /* PathViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 43FFCB2C1E143D9800148916 /* PathViewController.xib */; }; + 43FFCB321E143D9800148916 /* PlacemarkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43FFCB2E1E143D9800148916 /* PlacemarkViewController.swift */; }; + 43FFCB331E143D9800148916 /* PlacemarkViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 43FFCB2F1E143D9800148916 /* PlacemarkViewController.xib */; }; + 43FFCB341E143E4000148916 /* KML+Mapbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43FFCB0F1E143B3C00148916 /* KML+Mapbox.swift */; }; + 43FFCB351E14415300148916 /* KML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78FACAA21B81EF0A0078BF26 /* KML.swift */; }; + 43FFCB361E14415500148916 /* KML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78FACAA21B81EF0A0078BF26 /* KML.swift */; }; 784DBC3C1B820575007748FB /* PlacemarkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 784DBC3A1B820575007748FB /* PlacemarkViewController.swift */; }; 784DBC3D1B820575007748FB /* PlacemarkViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 784DBC3B1B820575007748FB /* PlacemarkViewController.xib */; }; 784DBC3F1B82FBD4007748FB /* sample.kml in Resources */ = {isa = PBXBuildFile; fileRef = 784DBC3E1B82FBD4007748FB /* sample.kml */; }; @@ -20,7 +34,7 @@ 78E3D7D21B815BE000170097 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 78E3D7D01B815BE000170097 /* LaunchScreen.xib */; }; 78E3D7DE1B815BE000170097 /* KmlTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E3D7DD1B815BE000170097 /* KmlTests.swift */; }; 78FACAA31B81EF0A0078BF26 /* KML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78FACAA21B81EF0A0078BF26 /* KML.swift */; }; - 78FACAA51B81EF490078BF26 /* KML.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78FACAA21B81EF0A0078BF26 /* KML.swift */; }; + C03FF1026D992E7A788DA791 /* Pods_Kml_Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD4255B4AD0974A3F07E821C /* Pods_Kml_Mapbox.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -35,6 +49,22 @@ /* Begin PBXFileReference section */ 0597E1AC11EBC60AF4E981A1 /* Pods_Kml.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Kml.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 0C813861CBD80225346FB756 /* Pods-Kml-Mapbox.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Kml-Mapbox.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Kml-Mapbox/Pods-Kml-Mapbox.debug.xcconfig"; sourceTree = ""; }; + 43FFCB0D1E1439E800148916 /* KML+MapKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "KML+MapKit.swift"; sourceTree = ""; }; + 43FFCB0F1E143B3C00148916 /* KML+Mapbox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "KML+Mapbox.swift"; sourceTree = ""; }; + 43FFCB151E143C9D00148916 /* Kml-Mapbox.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Kml-Mapbox.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 43FFCB171E143C9D00148916 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 43FFCB191E143C9D00148916 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; + 43FFCB1C1E143C9D00148916 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 43FFCB1E1E143C9D00148916 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 43FFCB211E143C9D00148916 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 43FFCB231E143C9D00148916 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 43FFCB271E143CE100148916 /* sample.kml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = sample.kml; sourceTree = ""; }; + 43FFCB2B1E143D9800148916 /* PathViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PathViewController.swift; sourceTree = ""; }; + 43FFCB2C1E143D9800148916 /* PathViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PathViewController.xib; sourceTree = ""; }; + 43FFCB2E1E143D9800148916 /* PlacemarkViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlacemarkViewController.swift; sourceTree = ""; }; + 43FFCB2F1E143D9800148916 /* PlacemarkViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PlacemarkViewController.xib; sourceTree = ""; }; + 5D8EFAC705FE4BE17DF50577 /* Pods-Kml.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Kml.release.xcconfig"; path = "Pods/Target Support Files/Pods-Kml/Pods-Kml.release.xcconfig"; sourceTree = ""; }; 784DBC3A1B820575007748FB /* PlacemarkViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PlacemarkViewController.swift; path = Examples/Placemark/PlacemarkViewController.swift; sourceTree = ""; }; 784DBC3B1B820575007748FB /* PlacemarkViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = PlacemarkViewController.xib; path = Examples/Placemark/PlacemarkViewController.xib; sourceTree = ""; }; 784DBC3E1B82FBD4007748FB /* sample.kml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = sample.kml; sourceTree = ""; }; @@ -51,12 +81,21 @@ 78E3D7DC1B815BE000170097 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 78E3D7DD1B815BE000170097 /* KmlTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KmlTests.swift; sourceTree = ""; }; 78FACAA21B81EF0A0078BF26 /* KML.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KML.swift; sourceTree = ""; }; - 96833CD4EA7EA91D7D8331B4 /* Pods-Kml.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Kml.release.xcconfig"; path = "Pods/Target Support Files/Pods-Kml/Pods-Kml.release.xcconfig"; sourceTree = ""; }; + AD4255B4AD0974A3F07E821C /* Pods_Kml_Mapbox.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Kml_Mapbox.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B0971BF904C642E2D7B2E88C /* Pods-Kml.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Kml.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Kml/Pods-Kml.debug.xcconfig"; sourceTree = ""; }; B7B3E70349A0F777E14510F3 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + DAA38A73EA50963A6107A224 /* Pods-Kml-Mapbox.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Kml-Mapbox.release.xcconfig"; path = "Pods/Target Support Files/Pods-Kml-Mapbox/Pods-Kml-Mapbox.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 43FFCB121E143C9D00148916 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + C03FF1026D992E7A788DA791 /* Pods_Kml_Mapbox.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 78E3D7BF1B815BE000170097 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -79,16 +118,77 @@ isa = PBXGroup; children = ( B0971BF904C642E2D7B2E88C /* Pods-Kml.debug.xcconfig */, - 96833CD4EA7EA91D7D8331B4 /* Pods-Kml.release.xcconfig */, + 5D8EFAC705FE4BE17DF50577 /* Pods-Kml.release.xcconfig */, + 0C813861CBD80225346FB756 /* Pods-Kml-Mapbox.debug.xcconfig */, + DAA38A73EA50963A6107A224 /* Pods-Kml-Mapbox.release.xcconfig */, ); name = Pods; sourceTree = ""; }; + 43FFCB0B1E1439C800148916 /* Mapbox */ = { + isa = PBXGroup; + children = ( + 43FFCB0F1E143B3C00148916 /* KML+Mapbox.swift */, + ); + path = Mapbox; + sourceTree = ""; + }; + 43FFCB0C1E1439C800148916 /* MapKit */ = { + isa = PBXGroup; + children = ( + 43FFCB0D1E1439E800148916 /* KML+MapKit.swift */, + ); + path = MapKit; + sourceTree = ""; + }; + 43FFCB161E143C9D00148916 /* Kml-Mapbox */ = { + isa = PBXGroup; + children = ( + 43FFCB291E143D9800148916 /* Examples */, + 43FFCB271E143CE100148916 /* sample.kml */, + 43FFCB171E143C9D00148916 /* AppDelegate.swift */, + 43FFCB191E143C9D00148916 /* MainViewController.swift */, + 43FFCB1B1E143C9D00148916 /* Main.storyboard */, + 43FFCB1E1E143C9D00148916 /* Assets.xcassets */, + 43FFCB201E143C9D00148916 /* LaunchScreen.storyboard */, + 43FFCB231E143C9D00148916 /* Info.plist */, + ); + path = "Kml-Mapbox"; + sourceTree = ""; + }; + 43FFCB291E143D9800148916 /* Examples */ = { + isa = PBXGroup; + children = ( + 43FFCB2A1E143D9800148916 /* Path */, + 43FFCB2D1E143D9800148916 /* Placemark */, + ); + path = Examples; + sourceTree = ""; + }; + 43FFCB2A1E143D9800148916 /* Path */ = { + isa = PBXGroup; + children = ( + 43FFCB2B1E143D9800148916 /* PathViewController.swift */, + 43FFCB2C1E143D9800148916 /* PathViewController.xib */, + ); + path = Path; + sourceTree = ""; + }; + 43FFCB2D1E143D9800148916 /* Placemark */ = { + isa = PBXGroup; + children = ( + 43FFCB2E1E143D9800148916 /* PlacemarkViewController.swift */, + 43FFCB2F1E143D9800148916 /* PlacemarkViewController.xib */, + ); + path = Placemark; + sourceTree = ""; + }; 44469B8E6D94BE8E551DF426 /* Frameworks */ = { isa = PBXGroup; children = ( B7B3E70349A0F777E14510F3 /* Pods.framework */, 0597E1AC11EBC60AF4E981A1 /* Pods_Kml.framework */, + AD4255B4AD0974A3F07E821C /* Pods_Kml_Mapbox.framework */, ); name = Frameworks; sourceTree = ""; @@ -126,6 +226,7 @@ 78FACAA11B81EF0A0078BF26 /* Source */, 78E3D7C41B815BE000170097 /* Kml */, 78E3D7DA1B815BE000170097 /* KmlTests */, + 43FFCB161E143C9D00148916 /* Kml-Mapbox */, 78E3D7C31B815BE000170097 /* Products */, 44469B8E6D94BE8E551DF426 /* Frameworks */, 0B203649AAC095C0116C2948 /* Pods */, @@ -137,6 +238,7 @@ children = ( 78E3D7C21B815BE000170097 /* Kml.app */, 78E3D7D71B815BE000170097 /* KmlTests.xctest */, + 43FFCB151E143C9D00148916 /* Kml-Mapbox.app */, ); name = Products; sourceTree = ""; @@ -184,6 +286,8 @@ 78FACAA11B81EF0A0078BF26 /* Source */ = { isa = PBXGroup; children = ( + 43FFCB0B1E1439C800148916 /* Mapbox */, + 43FFCB0C1E1439C800148916 /* MapKit */, 78FACAA21B81EF0A0078BF26 /* KML.swift */, ); path = Source; @@ -192,6 +296,26 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 43FFCB141E143C9D00148916 /* Kml-Mapbox */ = { + isa = PBXNativeTarget; + buildConfigurationList = 43FFCB241E143C9D00148916 /* Build configuration list for PBXNativeTarget "Kml-Mapbox" */; + buildPhases = ( + E37BBBEBF220D2E44BB677C0 /* [CP] Check Pods Manifest.lock */, + 43FFCB111E143C9D00148916 /* Sources */, + 43FFCB121E143C9D00148916 /* Frameworks */, + 43FFCB131E143C9D00148916 /* Resources */, + 6E7BD0CF0B24E25CF3C0E292 /* [CP] Embed Pods Frameworks */, + F884AF2414FE88BF1A357482 /* [CP] Copy Pods Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Kml-Mapbox"; + productName = "Kml-Mapbox"; + productReference = 43FFCB151E143C9D00148916 /* Kml-Mapbox.app */; + productType = "com.apple.product-type.application"; + }; 78E3D7C11B815BE000170097 /* Kml */ = { isa = PBXNativeTarget; buildConfigurationList = 78E3D7E11B815BE000170097 /* Build configuration list for PBXNativeTarget "Kml" */; @@ -239,10 +363,14 @@ isa = PBXProject; attributes = { LastSwiftMigration = 0700; - LastSwiftUpdateCheck = 0700; + LastSwiftUpdateCheck = 0820; LastUpgradeCheck = 0800; ORGANIZATIONNAME = asus4; TargetAttributes = { + 43FFCB141E143C9D00148916 = { + CreatedOnToolsVersion = 8.2; + ProvisioningStyle = Automatic; + }; 78E3D7C11B815BE000170097 = { CreatedOnToolsVersion = 6.4; LastSwiftMigration = 0800; @@ -269,11 +397,25 @@ targets = ( 78E3D7C11B815BE000170097 /* Kml */, 78E3D7D61B815BE000170097 /* KmlTests */, + 43FFCB141E143C9D00148916 /* Kml-Mapbox */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 43FFCB131E143C9D00148916 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 43FFCB221E143C9D00148916 /* LaunchScreen.storyboard in Resources */, + 43FFCB331E143D9800148916 /* PlacemarkViewController.xib in Resources */, + 43FFCB1F1E143C9D00148916 /* Assets.xcassets in Resources */, + 43FFCB311E143D9800148916 /* PathViewController.xib in Resources */, + 43FFCB281E143CE100148916 /* sample.kml in Resources */, + 43FFCB1D1E143C9D00148916 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 78E3D7C01B815BE000170097 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -327,6 +469,21 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Kml/Pods-Kml-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; + 6E7BD0CF0B24E25CF3C0E292 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Kml-Mapbox/Pods-Kml-Mapbox-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; 78E3D7E71B81600D00170097 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -368,15 +525,59 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; + E37BBBEBF220D2E44BB677C0 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; + F884AF2414FE88BF1A357482 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Kml-Mapbox/Pods-Kml-Mapbox-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 43FFCB111E143C9D00148916 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 43FFCB351E14415300148916 /* KML.swift in Sources */, + 43FFCB1A1E143C9D00148916 /* MainViewController.swift in Sources */, + 43FFCB181E143C9D00148916 /* AppDelegate.swift in Sources */, + 43FFCB301E143D9800148916 /* PathViewController.swift in Sources */, + 43FFCB321E143D9800148916 /* PlacemarkViewController.swift in Sources */, + 43FFCB341E143E4000148916 /* KML+Mapbox.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 78E3D7BE1B815BE000170097 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 78FACAA31B81EF0A0078BF26 /* KML.swift in Sources */, 78E3D7CA1B815BE000170097 /* MainViewController.swift in Sources */, + 43FFCB0E1E1439E800148916 /* KML+MapKit.swift in Sources */, 78E3D7C81B815BE000170097 /* AppDelegate.swift in Sources */, 784DBC3C1B820575007748FB /* PlacemarkViewController.swift in Sources */, 784DBC431B82FE94007748FB /* PathViewController.swift in Sources */, @@ -387,7 +588,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 78FACAA51B81EF490078BF26 /* KML.swift in Sources */, + 43FFCB361E14415500148916 /* KML.swift in Sources */, 78E3D7DE1B815BE000170097 /* KmlTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -403,6 +604,22 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ + 43FFCB1B1E143C9D00148916 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 43FFCB1C1E143C9D00148916 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 43FFCB201E143C9D00148916 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 43FFCB211E143C9D00148916 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; 78E3D7CB1B815BE000170097 /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -422,6 +639,40 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 43FFCB251E143C9D00148916 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 0C813861CBD80225346FB756 /* Pods-Kml-Mapbox.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + INFOPLIST_FILE = "Kml-Mapbox/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.asus4.Kml-Mapbox"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + 43FFCB261E143C9D00148916 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = DAA38A73EA50963A6107A224 /* Pods-Kml-Mapbox.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ANALYZER_NONNULL = YES; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + INFOPLIST_FILE = "Kml-Mapbox/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.asus4.Kml-Mapbox"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; 78E3D7DF1B815BE000170097 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -521,7 +772,7 @@ INFOPLIST_FILE = Kml/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.4; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.github.asus4.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = com.github.asus4.Kml; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 3.0; }; @@ -529,7 +780,7 @@ }; 78E3D7E31B815BE000170097 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 96833CD4EA7EA91D7D8331B4 /* Pods-Kml.release.xcconfig */; + baseConfigurationReference = 5D8EFAC705FE4BE17DF50577 /* Pods-Kml.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -537,7 +788,7 @@ INFOPLIST_FILE = Kml/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.4; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.github.asus4.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = com.github.asus4.Kml; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 3.0; }; @@ -545,7 +796,6 @@ }; 78E3D7E51B815BE000170097 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 96833CD4EA7EA91D7D8331B4 /* Pods-Kml.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; DEVELOPMENT_TEAM = ""; @@ -568,7 +818,6 @@ }; 78E3D7E61B815BE000170097 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 96833CD4EA7EA91D7D8331B4 /* Pods-Kml.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; DEVELOPMENT_TEAM = ""; @@ -588,6 +837,15 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 43FFCB241E143C9D00148916 /* Build configuration list for PBXNativeTarget "Kml-Mapbox" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 43FFCB251E143C9D00148916 /* Debug */, + 43FFCB261E143C9D00148916 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 78E3D7BD1B815BE000170097 /* Build configuration list for PBXProject "Kml" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/Kml/Base.lproj/Main.storyboard b/Kml/Base.lproj/Main.storyboard index 6e1d726..38bb335 100644 --- a/Kml/Base.lproj/Main.storyboard +++ b/Kml/Base.lproj/Main.storyboard @@ -1,7 +1,12 @@ - + + + + - + + + @@ -9,20 +14,22 @@ - + - + - + + diff --git a/Kml/Examples/Path/PathViewController.swift b/Kml/Examples/Path/PathViewController.swift index 7cb4e3e..0dc89e1 100644 --- a/Kml/Examples/Path/PathViewController.swift +++ b/Kml/Examples/Path/PathViewController.swift @@ -43,11 +43,11 @@ extension PathViewController: MKMapViewDelegate { func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { if let overlayPolyline = overlay as? KMLOverlayPolyline { // return MKPolylineRenderer - return overlayPolyline.renderer() + return overlayPolyline.renderer() as! MKOverlayRenderer } if let overlayPolygon = overlay as? KMLOverlayPolygon { // return MKPolygonRenderer - return overlayPolygon.renderer() + return overlayPolygon.renderer() as! MKOverlayRenderer } return MKOverlayRenderer(overlay: overlay) } diff --git a/Kml/Examples/Path/PathViewController.xib b/Kml/Examples/Path/PathViewController.xib index 9009618..fd1f271 100644 --- a/Kml/Examples/Path/PathViewController.xib +++ b/Kml/Examples/Path/PathViewController.xib @@ -1,7 +1,12 @@ - + + + + - + + + @@ -12,14 +17,14 @@ - + - + - + diff --git a/Kml/Examples/Placemark/PlacemarkViewController.xib b/Kml/Examples/Placemark/PlacemarkViewController.xib index 27b67dc..0b3ab64 100644 --- a/Kml/Examples/Placemark/PlacemarkViewController.xib +++ b/Kml/Examples/Placemark/PlacemarkViewController.xib @@ -1,7 +1,12 @@ - + + + + - + + + @@ -12,14 +17,14 @@ - + - + - + diff --git a/Kml/Images.xcassets/AppIcon.appiconset/Contents.json b/Kml/Images.xcassets/AppIcon.appiconset/Contents.json index 36d2c80..1d060ed 100644 --- a/Kml/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Kml/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -59,6 +79,11 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" } ], "info" : { diff --git a/Kml/Info.plist b/Kml/Info.plist index 40c6215..461c089 100644 --- a/Kml/Info.plist +++ b/Kml/Info.plist @@ -22,6 +22,8 @@ 1 LSRequiresIPhoneOS + NSLocationAlwaysUsageDescription + $(PRODUCT_NAME) wants to use location UILaunchStoryboardName LaunchScreen UIMainStoryboardFile diff --git a/Kml/MainViewController.swift b/Kml/MainViewController.swift index 1f55af7..536ac3c 100644 --- a/Kml/MainViewController.swift +++ b/Kml/MainViewController.swift @@ -21,11 +21,6 @@ class MainViewController: UITableViewController { super.viewDidLoad() locationManager.requestAlwaysAuthorization() } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } } extension MainViewController { // UITableViewDataSource diff --git a/Podfile b/Podfile index b46c45c..b5d5190 100644 --- a/Podfile +++ b/Podfile @@ -2,7 +2,10 @@ platform :ios, "8.0" use_frameworks! target 'Kml' do - pod 'AEXML' +end -end \ No newline at end of file +target 'Kml-Mapbox' do + pod 'Mapbox-iOS-SDK', '~> 3.3' + pod 'AEXML' +end diff --git a/Podfile.lock b/Podfile.lock index 15e7a96..866d7e2 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,12 +1,15 @@ PODS: - AEXML (4.0.1) + - Mapbox-iOS-SDK (3.3.7) DEPENDENCIES: - AEXML + - Mapbox-iOS-SDK (~> 3.3) SPEC CHECKSUMS: AEXML: 905e50474c0a261d335aa8be4ee32d22d69b6fd5 + Mapbox-iOS-SDK: 142301fa63a6719cbd2eacc0f9e8bf36c65930d9 -PODFILE CHECKSUM: d876e1098c89a2104d761a2bd6f1b57a93c1ada1 +PODFILE CHECKSUM: d3f597b5fe709f2095e78f5e1ce8f86375e1d300 -COCOAPODS: 1.1.0.rc.3 +COCOAPODS: 1.1.1 diff --git a/Source/KML.swift b/Source/KML.swift index cb118da..be7edc8 100644 --- a/Source/KML.swift +++ b/Source/KML.swift @@ -74,9 +74,17 @@ open class KMLElement { class func parseCoordinates(_ element: AEXMLElement) -> [CLLocationCoordinate2D] { var coordinates: [CLLocationCoordinate2D] = [] - let lines: [String] = element.string.characters.split(omittingEmptySubsequences: true, whereSeparator: {$0 == "\n" || $0 == " "}).map { String($0) } + let lines: [String] = + element.string.characters + .split(omittingEmptySubsequences: true, + whereSeparator: ({$0 == "\n" || $0 == " "})) + .map({ String($0) }) for line: String in lines { - let points: [String] = line.characters.split(omittingEmptySubsequences: true, whereSeparator: {$0 == ","}).map { String($0) } + let points: [String] = + line.characters + .split(omittingEmptySubsequences: true, + whereSeparator: ({$0 == ","})) + .map({ String($0) }) assert(points.count >= 2, "points lenth is \(points)") coordinates.append(CLLocationCoordinate2DMake(atof(points[1]), atof(points[0]))) } @@ -125,8 +133,17 @@ open class KMLElement { // MARK: - Style +public protocol KMLOverlayRenderer { + var alpha: CGFloat { get set } +} +public protocol KMLOverlayPathRenderer: KMLOverlayRenderer { + var fillColor: UIColor? { get set } + var strokeColor: UIColor? { get set } + var lineWidth: CGFloat { get set } +} + protocol KMLApplyStyle { - func applyStyle(_ renderer: MKOverlayPathRenderer) + func applyStyle(_ renderer: KMLOverlayRenderer) } open class KMLStyle: KMLElement, KMLApplyStyle { @@ -148,7 +165,7 @@ open class KMLStyle: KMLElement, KMLApplyStyle { } } - func applyStyle(_ renderer: MKOverlayPathRenderer) { + func applyStyle(_ renderer: KMLOverlayRenderer) { if let style: KMLPolyStyle = findElement(KMLPolyStyle.self) { style.applyStyle(renderer) } @@ -179,7 +196,7 @@ open class KMLStyleMap: KMLStyle { pairsRef[key] = style } - override func applyStyle(_ renderer: MKOverlayPathRenderer) { + override func applyStyle(_ renderer: KMLOverlayRenderer) { normalStyle?.applyStyle(renderer) } } @@ -220,8 +237,10 @@ open class KMLPolyStyle: KMLColorStyleGroup, KMLApplyStyle { super.init(element) } - func applyStyle(_ renderer: MKOverlayPathRenderer) { - renderer.fillColor = self.color + func applyStyle(_ renderer: KMLOverlayRenderer) { + if var renderer = renderer as? KMLOverlayPathRenderer { + renderer.fillColor = self.color + } } } @@ -240,9 +259,11 @@ open class KMLLineStyle: KMLColorStyleGroup, KMLApplyStyle { super.init(element) } - func applyStyle(_ renderer: MKOverlayPathRenderer) { - renderer.strokeColor = self.color - renderer.lineWidth = CGFloat(self.width) * 0.5 + func applyStyle(_ renderer: KMLOverlayRenderer) { + if var renderer = renderer as? KMLOverlayPathRenderer { + renderer.strokeColor = self.color + renderer.lineWidth = CGFloat(self.width) * 0.5 + } } } @@ -306,9 +327,7 @@ open class KMLIcon: KMLElement { } - // MARK: - Drawings - open class KMLMultiGeometry: KMLElement { } @@ -338,7 +357,6 @@ open class KMLPolygon: KMLElement { } } - open class KMLLineString: KMLElement { open var tessellate: Bool = false @@ -377,15 +395,14 @@ open class KMLPoint: KMLElement { } open class func parseCoordinate(_ str: String) -> CLLocationCoordinate2D { - let points: [String] = str.characters.split(omittingEmptySubsequences: true, whereSeparator: {$0 == ","}).map { String($0) } + let points: [String] = str.characters.split(omittingEmptySubsequences: true, + whereSeparator: {$0 == ","}).map { String($0) } assert(points.count >= 2, "points length is \(points)") return CLLocationCoordinate2DMake(atof(points[1]), atof(points[0])) } } - // MARK: - Placemark - open class KMLPlacemark: KMLElement { open var styleUrl: String = "" open var description: String = "" @@ -412,197 +429,6 @@ open class KMLPlacemark: KMLElement { } } -// MARK: - MapKit bridge - -public protocol KMLOverlay: MKOverlay { - var style: KMLStyle? { get set } - func renderer() -> MKOverlayRenderer -} - -open class KMLAnnotation: NSObject, MKAnnotation { - open var coordinate: CLLocationCoordinate2D - open var title: String? - open var subtitle: String? - open var style: KMLStyle? - - init(_ coordinate: CLLocationCoordinate2D) { - self.coordinate = coordinate - } -} - -open class KMLOverlayPolygon: MKPolygon, KMLOverlay { - - open var style: KMLStyle? = nil - - open func renderer() -> MKOverlayRenderer { - let renderer: MKPolygonRenderer = MKPolygonRenderer(polygon: self) - - if style != nil { - style?.applyStyle(renderer) - } else { - renderer.fillColor = UIColor(red: 0.6, green: 1.0, blue: 0.5, alpha: 0.2) - renderer.strokeColor = UIColor(red: 1.0, green: 0.6, blue: 0.5, alpha: 0.8) - renderer.lineWidth = 2.0 - } - - return renderer - } -} - -open class KMLOverlayPolyline: MKPolyline, KMLOverlay { - - open var style: KMLStyle? = nil - - open func renderer() -> MKOverlayRenderer { - let renderer: MKPolylineRenderer = MKPolylineRenderer(polyline: self) - - if style != nil { - style?.applyStyle(renderer) - } else { - renderer.strokeColor = UIColor(red: 0.6, green: 0.6, blue: 1.0, alpha: 0.8) - renderer.lineWidth = 2.0 - } - - return renderer - } -} - -// MARK: - Document - -open class KMLDocument: KMLElement { - open var overlays: [MKOverlay] = [] - open var annotations: [KMLAnnotation] = [] - open var styles: Dictionary = [:] - open var placemarks: [KMLPlacemark] = [] - - public required init(_ element: AEXMLElement) { - super.init(element) - initStyle() - placemarks = findElements(KMLPlacemark.self) - for placemark in placemarks { - if let foundStyle = findStyle(forPlacemark: placemark) { - placemark.style = foundStyle - } - } - } - - public convenience init? (url: URL, generateMapKitClasses: Bool=true) { - var element: AEXMLElement? - - if let data = try? Data(contentsOf: url) { - do { - let xmlDoc = try AEXMLDocument(xml: data) - element = xmlDoc.root["Document"] - } catch _ { - print("Could not parse XML.") - return nil - } - self.init(element!, generateMapKitClasses:generateMapKitClasses) - } else { - print("Doesn't exist file at path - \(url)") - let errorElement = AEXMLElement(name: "AEXMLError", value: "Doesn't exist file at path \(url)") - errorElement.error = AEXMLError.parsingFailed - self.init(errorElement, generateMapKitClasses:generateMapKitClasses) - } - - } - - public convenience init(_ element: AEXMLElement, generateMapKitClasses: Bool) { - self.init(element) - if generateMapKitClasses { - initOverlay() - initAnnotation() - } - } - - open var isError: Bool { - get { - return self.children.count == 0 - } - } - - fileprivate func initStyle() { - if let _styles: [KMLStyle] = findElements(KMLStyle.self) { - for style: KMLStyle in _styles { - self.styles[style.styleId] = style - } - } - if let _styles: [KMLStyleMap] = findElements(KMLStyleMap.self) { - for style: KMLStyleMap in _styles { - for (key, value): (String, String) in style.pairs { - style.addPairsRef(key, style: self.styles[value]!) - } - self.styles[style.styleId] = style - } - } - } - - fileprivate func initOverlay() { - for placemark: KMLPlacemark in placemarks { - - var overlays: [KMLOverlay] = [] - - let polygons: [KMLPolygon] = placemark.findElements(KMLPolygon.self) - for poligon: KMLPolygon in polygons { - overlays.append(KMLOverlayPolygon(coordinates: &poligon.coordinates, count: poligon.coordinates.count)) - } - - let lines: [KMLLineString] = placemark.findElements(KMLLineString.self) - for line: KMLLineString in lines { - overlays.append(KMLOverlayPolyline(coordinates: &line.coordinates, count: line.coordinates.count)) - } - - for overlay: KMLOverlay in overlays { - overlay.style = placemark.style - - self.overlays.append(overlay) - } - } - } - - fileprivate func findStyle(forPlacemark placemark: KMLPlacemark) -> KMLStyle? { - var foundStyle: KMLStyle? - if let style: KMLStyle = styles[placemark.styleUrl] { - foundStyle = style - } else if let style: KMLStyle = placemark.findElement(KMLStyle.self) { - foundStyle = style - } else { - foundStyle = nil - } - if let foundStyleMap = foundStyle as? KMLStyleMap, - let normalStyle = foundStyleMap.normalStyle { - foundStyle = normalStyle - } - return foundStyle - } - - fileprivate func initAnnotation() { - for pointPlacemark: KMLPlacemark in placemarks { - if let point: KMLPoint = pointPlacemark.point { - let annotation = KMLAnnotation(point.coordinates) - annotation.title = pointPlacemark.name - annotation.subtitle = pointPlacemark.description - annotation.style = pointPlacemark.style - - self.annotations.append(annotation) - } - } - } - - open class func parse(_ url: URL, generateMapKitClasses: Bool=true, callback: @escaping (KMLDocument) -> Void) { - // Background Task - let bgQueue = DispatchQueue.global(qos: .default) - let mainQueue: DispatchQueue = DispatchQueue.main - bgQueue.async(execute: { - if let doc: KMLDocument = KMLDocument(url: url, generateMapKitClasses:generateMapKitClasses) { - mainQueue.async(execute: { - callback(doc) - }) - } - }) - } -} - // MARK: - Private extensions private extension String { diff --git a/Source/MapKit/KML+MapKit.swift b/Source/MapKit/KML+MapKit.swift new file mode 100644 index 0000000..b36e1cf --- /dev/null +++ b/Source/MapKit/KML+MapKit.swift @@ -0,0 +1,207 @@ +// +// KML+MapKit.swift +// Kml +// +// Created by Greg Pardo on 12/28/16. +// Copyright © 2016 asus4. All rights reserved. +// + +import MapKit +import AEXML + +// MARK: - MapKit bridge +public protocol KMLOverlay: MKOverlay { + var style: KMLStyle? { get set } + func renderer() -> KMLOverlayRenderer +} + +open class KMLMapKitOverlayRenderer: MKOverlayRenderer, KMLOverlayRenderer { +} +open class KMLMapKitPolygonRenderer: MKPolygonRenderer, KMLOverlayPathRenderer { +} +open class KMLMapKitPolylineRenderer: MKPolylineRenderer, KMLOverlayPathRenderer { +} + +open class KMLAnnotation: NSObject, MKAnnotation { + open var coordinate: CLLocationCoordinate2D + open var title: String? + open var subtitle: String? + open var style: KMLStyle? + + init(_ coordinate: CLLocationCoordinate2D) { + self.coordinate = coordinate + } +} + +open class KMLOverlayPolygon: MKPolygon, KMLOverlay { + + open var style: KMLStyle? = nil + + open func renderer() -> KMLOverlayRenderer { + let renderer: KMLMapKitPolygonRenderer = KMLMapKitPolygonRenderer(polygon: self) + + if style != nil { + style?.applyStyle(renderer) + } else { + renderer.fillColor = UIColor(red: 0.6, green: 1.0, blue: 0.5, alpha: 0.2) + renderer.strokeColor = UIColor(red: 1.0, green: 0.6, blue: 0.5, alpha: 0.8) + renderer.lineWidth = 2.0 + } + + return renderer + } +} + +open class KMLOverlayPolyline: MKPolyline, KMLOverlay { + + open var style: KMLStyle? = nil + + open func renderer() -> KMLOverlayRenderer { + let renderer: KMLMapKitPolylineRenderer = KMLMapKitPolylineRenderer(polyline: self) + + if style != nil { + style?.applyStyle(renderer) + } else { + renderer.strokeColor = UIColor(red: 0.6, green: 0.6, blue: 1.0, alpha: 0.8) + renderer.lineWidth = 2.0 + } + + return renderer + } +} + +// MARK: - Document + +open class KMLDocument: KMLElement { + open var overlays: [KMLOverlay] = [] + open var annotations: [KMLAnnotation] = [] + open var styles: Dictionary = [:] + open var placemarks: [KMLPlacemark] = [] + + public required init(_ element: AEXMLElement) { + super.init(element) + initStyle() + placemarks = findElements(KMLPlacemark.self) + for placemark in placemarks { + if let foundStyle = findStyle(forPlacemark: placemark) { + placemark.style = foundStyle + } + } + } + + public convenience init? (url: URL, generateMapKitClasses: Bool=true) { + var element: AEXMLElement? + + if let data = try? Data(contentsOf: url) { + do { + let xmlDoc = try AEXMLDocument(xml: data) + element = xmlDoc.root["Document"] + } catch _ { + print("Could not parse XML.") + return nil + } + self.init(element!, generateMapKitClasses:generateMapKitClasses) + } else { + print("Doesn't exist file at path - \(url)") + let errorElement = AEXMLElement(name: "AEXMLError", value: "Doesn't exist file at path \(url)") + errorElement.error = AEXMLError.parsingFailed + self.init(errorElement, generateMapKitClasses:generateMapKitClasses) + } + + } + + public convenience init(_ element: AEXMLElement, generateMapKitClasses: Bool) { + self.init(element) + if generateMapKitClasses { + initOverlay() + initAnnotation() + } + } + + open var isError: Bool { + get { + return self.children.count == 0 + } + } + + fileprivate func initStyle() { + if let _styles: [KMLStyle] = findElements(KMLStyle.self) { + for style: KMLStyle in _styles { + self.styles[style.styleId] = style + } + } + if let _styles: [KMLStyleMap] = findElements(KMLStyleMap.self) { + for style: KMLStyleMap in _styles { + for (key, value): (String, String) in style.pairs { + style.addPairsRef(key, style: self.styles[value]!) + } + self.styles[style.styleId] = style + } + } + } + + fileprivate func initOverlay() { + for placemark: KMLPlacemark in placemarks { + + var overlays: [KMLOverlay] = [] + + let polygons: [KMLPolygon] = placemark.findElements(KMLPolygon.self) + for polygon: KMLPolygon in polygons { + overlays.append(KMLOverlayPolygon(coordinates: &polygon.coordinates, count: polygon.coordinates.count)) + } + + let lines: [KMLLineString] = placemark.findElements(KMLLineString.self) + for line: KMLLineString in lines { + overlays.append(KMLOverlayPolyline(coordinates: &line.coordinates, count: line.coordinates.count)) + } + + for overlay: KMLOverlay in overlays { + overlay.style = placemark.style + + self.overlays.append(overlay) + } + } + } + + fileprivate func findStyle(forPlacemark placemark: KMLPlacemark) -> KMLStyle? { + var foundStyle: KMLStyle? + if let style: KMLStyle = styles[placemark.styleUrl] { + foundStyle = style + } else if let style: KMLStyle = placemark.findElement(KMLStyle.self) { + foundStyle = style + } else { + foundStyle = nil + } + if let foundStyleMap = foundStyle as? KMLStyleMap, + let normalStyle = foundStyleMap.normalStyle { + foundStyle = normalStyle + } + return foundStyle + } + + fileprivate func initAnnotation() { + for pointPlacemark: KMLPlacemark in placemarks { + if let point: KMLPoint = pointPlacemark.point { + let annotation = KMLAnnotation(point.coordinates) + annotation.title = pointPlacemark.name + annotation.subtitle = pointPlacemark.description + annotation.style = pointPlacemark.style + + self.annotations.append(annotation) + } + } + } + + open class func parse(_ url: URL, generateMapKitClasses: Bool=true, callback: @escaping (KMLDocument) -> Void) { + // Background Task + let bgQueue = DispatchQueue.global(qos: .default) + let mainQueue: DispatchQueue = DispatchQueue.main + bgQueue.async(execute: { + if let doc: KMLDocument = KMLDocument(url: url, generateMapKitClasses:generateMapKitClasses) { + mainQueue.async(execute: { + callback(doc) + }) + } + }) + } +} diff --git a/Source/Mapbox/KML+Mapbox.swift b/Source/Mapbox/KML+Mapbox.swift new file mode 100644 index 0000000..ab0d991 --- /dev/null +++ b/Source/Mapbox/KML+Mapbox.swift @@ -0,0 +1,218 @@ +// +// KML+Mapbox.swift +// Kml +// +// Created by Greg Pardo on 12/28/16. +// Copyright © 2016 asus4. All rights reserved. +// + +import Mapbox +import AEXML + +// MARK: - Mapbox bridge +public protocol KMLOverlay: MGLOverlay { + var style: KMLStyle? { get set } + func renderer() -> KMLOverlayRenderer +} +open class KMLMapboxOverlayRenderer: KMLOverlayRenderer { + public var alpha: CGFloat = 1.0 +} +open class KMLMapboxOverlayPathRenderer: KMLOverlayRenderer { + public var alpha: CGFloat = 1.0 + public var fillColor: UIColor? = UIColor(red: 0.6, green: 1.0, blue: 0.5, alpha: 0.2) + public var strokeColor: UIColor? = UIColor(red: 1.0, green: 0.6, blue: 0.5, alpha: 0.8) + public var lineWidth: CGFloat = 2.0 +} +open class KMLMapboxPolygonRenderer: KMLMapboxOverlayPathRenderer { +} +open class KMLMapboxPolylineRenderer: KMLMapboxOverlayPathRenderer { +} +open class KMLAnnotation: NSObject, MGLAnnotation { + open var coordinate: CLLocationCoordinate2D + open var title: String? + open var subtitle: String? + open var style: KMLStyle? + init(_ coordinate: CLLocationCoordinate2D) { + self.coordinate = coordinate + } +} + +open class KMLOverlayPolygon: MGLPolygon, KMLOverlay { + open var style: KMLStyle? = nil + open func renderer() -> KMLOverlayRenderer { + let renderer: KMLMapboxPolygonRenderer = KMLMapboxPolygonRenderer() + if style != nil { + style?.applyStyle(renderer) + } else { + renderer.fillColor = UIColor(red: 0.6, green: 1.0, blue: 0.5, alpha: 0.2) + renderer.strokeColor = UIColor(red: 1.0, green: 0.6, blue: 0.5, alpha: 0.8) + renderer.lineWidth = 2.0 + } + return renderer + } +} + +open class KMLOverlayPolyline: MGLPolyline, KMLOverlay { + open var style: KMLStyle? = nil + open func renderer() -> KMLOverlayRenderer { + let renderer: KMLMapboxPolylineRenderer = KMLMapboxPolylineRenderer() + if style != nil { + style?.applyStyle(renderer) + } else { + renderer.strokeColor = UIColor(red: 0.6, green: 0.6, blue: 1.0, alpha: 0.8) + renderer.lineWidth = 2.0 + } + return renderer + } +} + +// MARK: - Document + +open class KMLDocument: KMLElement { + open var overlays: [KMLOverlay] = [] + open var annotations: [KMLAnnotation] = [] + open var styles: Dictionary = [:] + open var placemarks: [KMLPlacemark] = [] + public required init(_ element: AEXMLElement) { + super.init(element) + initStyle() + placemarks = findElements(KMLPlacemark.self) + for placemark in placemarks { + if let foundStyle = findStyle(forPlacemark: placemark) { + placemark.style = foundStyle + } + } + } + public convenience init? (url: URL, generateMapKitClasses: Bool=true) { + var element: AEXMLElement? + if let data = try? Data(contentsOf: url) { + do { + let xmlDoc = try AEXMLDocument(xml: data) + element = xmlDoc.root["Document"] + } catch _ { + print("Could not parse XML.") + return nil + } + self.init(element!, generateMapKitClasses:generateMapKitClasses) + } else { + print("Doesn't exist file at path - \(url)") + let errorElement = AEXMLElement(name: "AEXMLError", value: "Doesn't exist file at path \(url)") + errorElement.error = AEXMLError.parsingFailed + self.init(errorElement, generateMapKitClasses:generateMapKitClasses) + } + } + public convenience init(_ element: AEXMLElement, generateMapKitClasses: Bool) { + self.init(element) + if generateMapKitClasses { + initOverlay() + initAnnotation() + } + } + open var isError: Bool { + get { + return self.children.count == 0 + } + } + fileprivate func initStyle() { + if let _styles: [KMLStyle] = findElements(KMLStyle.self) { + for style: KMLStyle in _styles { + self.styles[style.styleId] = style + } + } + if let _styles: [KMLStyleMap] = findElements(KMLStyleMap.self) { + for style: KMLStyleMap in _styles { + for (key, value): (String, String) in style.pairs { + style.addPairsRef(key, style: self.styles[value]!) + } + self.styles[style.styleId] = style + } + } + } + fileprivate func initOverlay() { + for placemark: KMLPlacemark in placemarks { + var overlays: [KMLOverlay] = [] + let polygons: [KMLPolygon] = placemark.findElements(KMLPolygon.self) + for polygon: KMLPolygon in polygons { + let poly = KMLOverlayPolygon(coordinates: &polygon.coordinates, count: UInt(polygon.coordinates.count)) + overlays.append(poly) + } + let lines: [KMLLineString] = placemark.findElements(KMLLineString.self) + for line: KMLLineString in lines { + let polyLine = KMLOverlayPolyline(coordinates: &line.coordinates, count: UInt(line.coordinates.count)) + overlays.append(polyLine) + } + for overlay: KMLOverlay in overlays { + overlay.style = placemark.style + self.overlays.append(overlay) + } + } + } + fileprivate func findStyle(forPlacemark placemark: KMLPlacemark) -> KMLStyle? { + var foundStyle: KMLStyle? + if let style: KMLStyle = styles[placemark.styleUrl] { + foundStyle = style + } else if let style: KMLStyle = placemark.findElement(KMLStyle.self) { + foundStyle = style + } else { + foundStyle = nil + } + if let foundStyleMap = foundStyle as? KMLStyleMap, + let normalStyle = foundStyleMap.normalStyle { + foundStyle = normalStyle + } + return foundStyle + } + fileprivate func initAnnotation() { + for pointPlacemark: KMLPlacemark in placemarks { + if let point: KMLPoint = pointPlacemark.point { + let annotation = KMLAnnotation(point.coordinates) + annotation.title = pointPlacemark.name + annotation.subtitle = pointPlacemark.description + annotation.style = pointPlacemark.style + self.annotations.append(annotation) + } + } + } + open class func parse(_ url: URL, generateMapKitClasses: Bool=true, callback: @escaping (KMLDocument) -> Void) { + // Background Task + let bgQueue = DispatchQueue.global(qos: .default) + let mainQueue: DispatchQueue = DispatchQueue.main + bgQueue.async(execute: { + if let doc: KMLDocument = KMLDocument(url: url, generateMapKitClasses:generateMapKitClasses) { + mainQueue.async(execute: { + callback(doc) + }) + } + }) + } +} + +// MARK: Mapbox extensions for easy use +extension MGLShape { + var alpha: CGFloat { + if let annotation = self as? KMLOverlay { + return annotation.renderer().alpha + } + return 1.0 + } + var fillColor: UIColor? { + if let annotation = self as? KMLOverlay { + return annotation.style?.polyStyle?.color + } + return UIColor.blue + } + var strokeColor: UIColor? { + if let annotation = self as? KMLOverlay { + return annotation.style?.lineStyle?.color + } + return UIColor.black + } + var lineWidth: CGFloat { + if let annotation = self as? KMLOverlay { + if let width = annotation.style?.lineStyle?.width { + return CGFloat(width) + } + } + return 2.0 + } +} From 2a73b79e4b55037d9690772f7c8ecebb5da7434c Mon Sep 17 00:00:00 2001 From: Greg Pardo Date: Wed, 28 Dec 2016 15:59:36 -0500 Subject: [PATCH 2/4] Update readme with subspecs --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e1d96c..85fe818 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,22 @@ Simple KML parser for Swift. +## Installation + +``` +pod 'Kml.swift/MapKit' +``` +or +``` +pod 'Kml.swift/Mapbox' +``` + ## Libraries - [AEXML](https://github.com/tadija/AEXML) via cocoapods - [UIColor-Hex-Swift](https://github.com/yeahdongcn/UIColor-Hex-Swift) includes + ## Supporting TAGs - Style @@ -25,4 +36,4 @@ Simple KML parser for Swift. ## License -MIT \ No newline at end of file +MIT From 15bb4250a3ac13bb78531a7d6371719ee806722d Mon Sep 17 00:00:00 2001 From: Greg Pardo Date: Wed, 28 Dec 2016 16:03:37 -0500 Subject: [PATCH 3/4] Make sure podspec source is right --- Kml.swift.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kml.swift.podspec b/Kml.swift.podspec index 6bc2d24..dbc1059 100644 --- a/Kml.swift.podspec +++ b/Kml.swift.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.social_media_url = "https://twitter.com/asus4" s.ios.deployment_target = '8.0' - s.source = { :git => 'https://github.com/gregpardo/Kml.swift.git', :tag => s.version } + s.source = { :git => 'https://github.com/asus4/Kml.swift.git', :tag => s.version } s.default_subspec = "Core" s.subspec "Core" do |ss| From 89d90542a71a3d2ebd7351a91434b613584315a0 Mon Sep 17 00:00:00 2001 From: Greg Pardo Date: Wed, 28 Dec 2016 16:08:19 -0500 Subject: [PATCH 4/4] Update README.md and clarify flavors --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 85fe818..4ccec44 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,15 @@ Simple KML parser for Swift. ## Installation - +For just the parsing library +``` +pod 'Kml.swift/Core' +``` +Or for parsing with MapKit integration ``` pod 'Kml.swift/MapKit' ``` -or +Or for parsing with Mapbox integration ``` pod 'Kml.swift/Mapbox' ```