Giter Club home page Giter Club logo

pytheas's Introduction

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 [email protected]: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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.