https://github.com/maxvol/geojsonmap
Build maps from GeoJSON with MapKit or SpriteKit
https://github.com/maxvol/geojsonmap
geojson mapkit spritekit
Last synced: 5 months ago
JSON representation
Build maps from GeoJSON with MapKit or SpriteKit
- Host: GitHub
- URL: https://github.com/maxvol/geojsonmap
- Owner: maxvol
- License: mit
- Created: 2018-11-14T19:00:29.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-07-03T12:50:41.000Z (almost 3 years ago)
- Last Synced: 2023-02-27T22:05:37.165Z (about 2 years ago)
- Topics: geojson, mapkit, spritekit
- Language: Swift
- Homepage: https://medium.com/@maxim.volgin/offline-maps-with-geojsonmap-and-spritekitdsl-608d14db2cf3
- Size: 367 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GeoJSONMap
Build maps from GeoJSON with MapKit or SpriteKit.SpriteKit maps can be displayed offline and/or as planes in ARKit.

Basic usage:
```swift
import GeoJSONMapfinal class ViewController: UIViewController {
let map = GJMap()
override func viewDidLoad() {
super.viewDidLoad()
self.map.delegate = self
self.map.add(featureCollection: /* ... */)
let mapRect = self.map.boundingMapRect
let cgSize = mapRect.size.cgSize
let scene = SKScene(size: cgSize)
for node in self.map.nodes {
scene.addChild(node)
}
/* use `scene` */
}
}public struct Properties: Codable {
let prop0: String
let prop1: Int?
}extension ViewController: GJMapDelegate {
typealias P = Propertiesfunc map(_ map: GJMap, nodeFor feature: GJFeature) -> SKNode? {
let mapRect = self.map.boundingMapRect
let cgSize = mapRect.size.cgSize
switch feature.geometry {
case .point(let coordinate):
let point = MKMapPoint(coordinate)
guard let cgPoint = try? point.cgPoint(from: mapRect, to: cgSize) else { return nil }
let node = SKShapeNode(circleOfRadius: /* ... */)
node.position = cgPoint
/* ... */
return node
case .lineString(let coordinates):
do {
var points = try coordinates.map { try MKMapPoint($0).cgPoint(from: mapRect, to: cgSize) }
let node = SKShapeNode(splinePoints: &points, count: points.count)
/* ... */
return node
} catch {
print(error)
return nil
}
}
}
}
```
Carthage setup.```
github "maxvol/GeoJSONMap" ~> 0.1.2
```