Pytheas 1.3.0

Pytheas 1.3.0

h0shy 维护。



Pytheas 1.3.0

  • hoshy

Pytheas

CocoaPods compatible Carthage compatible CI Swift Version License MIT

GeoJSON 序列化和反序列化工具,为 MapKit 和 GoogleMaps 提供支持。

特性

输出模型是通用的,因此您可以实例化 MapKit 和 GoogleMaps 的点、线和多边形。100% 测试覆盖率。

入门

CocoaPods

在您的 Podfile 中使用这个

pod 'Pytheas'

然后运行 pod install

在您想使用 Pytheas 的任何文件中,不要忘记使用 import Pytheas 导入框架。

使用

GoogleMaps 点

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

GoogleMaps 线

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 多边形

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 点

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

MapKit 线

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

MapKit 多边形

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 在 MIT 许可证下发布。更多信息请参阅 License.md