1

ViewController.swift

import UIKit import MapKit import GEOSwift

class 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()
}}

I'm trying to use the libary because i want to create A Polygon with holes. But i cant find a way to solve my problem.

when i try to add the Multipolygon with addoverlay

it throws a error

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

anyone with a method to solve my problem ?

1 Answers1

0

Here is the code snippet. (swift 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")
        }
    }
}
Yi-Hsiu Lee
  • 176
  • 2
  • 5