Swiftpack.co - h0shy/Pytheas as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by h0shy.
h0shy/Pytheas 1.3.0
GeoJSON Serializer and Deserializer for MapKit and GoogleMaps
⭐️ 3
🕓 3 weeks ago
.package(url: "https://github.com/h0shy/Pytheas.git", from: "1.3.0")

Pytheas

CocoaPods compatible Carthage compatible CI Swift Version License MIT

GeoJSON Serializer and Deserializer for MapKit and GoogleMaps.

Features

The output model is generic, so you can instantiate MapKit and GoogleMaps points, lines, and polygons. 100% test coverage.

Getting Started

Swift Package Manger

Add git@github.com:h0shy/Pytheas.git via File -> Swift Packages -> Add Package Dependency

CocoaPods

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.

Usage

GoogleMaps Point

if let point = try? Pytheas.shape(from: json) as? Pytheas.Point {
let googleMapsPoint = GMSMapPoint(x: point.coordinate.latitude, y: point.coordinate.longitude)
}

GoogleMaps Line

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)
}

GoogleMaps Polygon

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)
}

MapKit Point

if let point = try? Pytheas.shape(from: json) as? Pytheas.Point {
let mapPoint = MKMapPoint(point.coordinate)
}

MapKit Line

if let line = try? Pytheas.shape(from: json) as? Pytheas.Line {
let mapLine = MKPolyline(coordinates: line.coordinates, count: line.coordinates.count)
}

MapKit Polygon

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)
}

FeatureCollections

let points / lines / polygons = try? Pytheas.shapes(from: json) as? [Point] / [Line] / [Polygon]

Serialization

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
})

License

Pytheas is released under an MIT license. See License.md for more information.

GitHub

link
Stars: 3
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

Release Notes

1.3.0
2 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics