2016-05-23 4 views
1

ViewController.swiftGEOSwiftとMapviewOverlays(SWIFT)

インポートのUIKit インポートMapKit インポートGEOSwift

クラスのViewController:の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() 
}} 

ホールを持つポリゴンを作成したいのでlibaryを使用しようとしています。 しかし私は私の問題を解決する方法を見つけることができません。

私はそれは私の問題を解決する方法と、エラー

Cannot invoke 'addOverlay' with an argument list of type '(MultiPolygon<Polygon>)' 

誰がスローされますaddoverlay

でMULTIPOLYGONを追加しようか?

答えて

0

ここにコードスニペットがあります。 (スイフト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") 
     } 
    } 
}