GeoJSON Serializer and Deserializer for MapKit and GoogleMaps.
The output model is generic, so you can instantiate MapKit and GoogleMaps points, lines, and polygons. 100% test coverage.
Add git@github.com:h0shy/Pytheas.git
via File
-> Swift Packages
-> Add Package Dependency
Use this in your Podfile:
pod 'Pytheas'
Then run pod install
.
In any file you'd like to use Pytheas in, don't forget to
import the framework with import Pytheas
.
if let point = try? Pytheas.shape(from: json) as? Pytheas.Point {
let googleMapsPoint = GMSMapPoint(x: point.coordinate.latitude, y: point.coordinate.longitude)
}
if let line = try? Pytheas.shape(from: json) as? Pytheas.Line {
let path = GMSMutablePath()
for coord in line.coordinates {
path.add(coord)
}
let line = GMSPolyline(path: path)
}
if let polygon = try? Pytheas.shape(from: json) as? Pytheas.Polygon {
let path = GMSMutablePath()
for coord in polygon.coordinates {
path.add(coord)
}
let line = GMSPolygon(path: path)
}
if let point = try? Pytheas.shape(from: json) as? Pytheas.Point {
let mapPoint = MKMapPoint(point.coordinate)
}
if let line = try? Pytheas.shape(from: json) as? Pytheas.Line {
let mapLine = MKPolyline(coordinates: line.coordinates, count: line.coordinates.count)
}
if let polygon = try? Pytheas.shape(from: json) as? Pytheas.Polygon {
let interiors = polygon.interiorPolygons.map { MKPolygon(coordinates: $0.coordinates, count: $0.coordinates.count) }
let mapPolygon = MKPolygon(coordinates: polygon.coordinates, count: polygon.coordinates.count, interiorPolygons: interiors)
}
let points / lines / polygons = try? Pytheas.shapes(from: json) as? [Point] / [Line] / [Polygon]
let pointJson = try? Pytheas.geoJson(from: point, properties: properties(from: point))
let lineJson = try? Pytheas.geoJson(from: line, properties: properties(from: line))
let polygonJson = try? Pytheas.geoJson(from: polygonJson, properties: properties(from: polygonJson))
let collectionJson = try? Pytheas.geoJson(from: features, properties: features.map {
var properties: [String: Any] = [:]
properties[Key.title] = $0.title
properties[Key.subtitle] = $0.subtitle
return properties
})
Pytheas is released under an MIT license. See License.md for more information.