ViewController.swift
导入 UIKit 导入 MapKit 导入 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
我正在尝试使用该库,因为我想创建一个带孔的多边形。但我找不到解决问题的方法。
当我尝试使用 addoverlay 添加 Multipolygon
它抛出一个错误
Cannot invoke 'addOverlay' with an argument list of type '(MultiPolygon<Polygon>)'
有人有办法解决我的问题吗?