I have a geojson file containing a FeatureCollection of Features. I parse the json with GEOSwift and end up having MKPolygon objects.
I have managed to draw the polygons as overlay to the MKMapView, but the performance is really poor!
The geojson file I have contains a path to every country in the world. So I actually don't need the map since I just want to draw the polygons directly to a UIView. Here's my code to getting the MKPolygon:
func drawPolygonsFromFeatures(_ features: Features) {
var i = 0
for feature in features {
if let geometries = feature.geometries {
for geometry in geometries {
if let shapesCollection = geometry.mapShape() as? MKShapesCollection {
let shapes = shapesCollection.shapes
for shape in shapes {
if let polygon = shape as? MKPolygon {
if let identifier = feature.id as? String, self.countryDict.count > 0 {
// Set title in order to set color on country
polygon.title = self.countryDict[identifier]
}
main {
// TODO: Draw polygons on view
}
}
}
}
}
}
i += 1
}
}
I know it's possible to draw shapes with UIBeizerPath, but I don't know how to convert my MKPolygon to something that could show a shape on an UIView.