ViewController.swift
आयात UIKit आयात मैपकिट आयात GEOSwift
क्लास व्यू कंट्रोलर: UIViewController, MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
mapView.delegate = self
super.viewDidLoad()
addBoundry()
}
func addBoundry()
{
if let geoJSONURL = NSBundle.mainBundle().URLForResource("multipolygon", withExtension: "geojson"),
let geometries = try! Geometry.fromGeoJSON(geoJSONURL),
let geo = geometries[0] as? MultiPolygon
{
geo
}
//mapView.addOverlay(geo)
}
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKPolygon {
let polygonView = MKPolygonRenderer(overlay: overlay)
polygonView.strokeColor = UIColor.magentaColor()
return polygonView
}
return MKOverlayRenderer()
}}
- Multipolygon.geojson इटली की ज्यामिति से भरा है https://github.com/andreacremaschi/GEOSwift/blob/master/GEOSPlayground.playground/Resources/multipolygon.geojson
मैं libary का उपयोग करने की कोशिश कर रहा हूँ क्योंकि मैं छेद के साथ एक बहुभुज बनाना चाहता हूँ। लेकिन मैं अपनी समस्या को हल करने का कोई रास्ता नहीं ढूंढ सकता।
जब मैं addoverlay के साथ मल्टीप्लिगॉन जोड़ने की कोशिश करता हूं
यह एक त्रुटि फेंकता है
Cannot invoke "addOverlay" with an argument list of type "(MultiPolygon<Polygon>)"
मेरी समस्या को हल करने के लिए कोई तरीका है?
उत्तर:
जवाब के लिए 0 № 1कोड स्निपेट यहाँ है। (स्विफ्ट 3.0)
func addBoundry() {
if let geoJSONURL = Bundle.main.url(forResource: "multipolygon", withExtension: "geojson") {
do {
let geometries = try Geometry.fromGeoJSON(geoJSONURL)
if let geo = geometries?[0] as? MultiPolygon {
if let shapesCollection = geo.mapShape() as? MKShapesCollection {
let shapes = shapesCollection.shapes
for shape in shapes {
if let polygon = shape as? MKPolygon {
mapView.add(polygon)
}
}
}
}
} catch {
print("Unable to load geojson data")
}
}
}