Распарсить GeoJSON на Swift в массив полигонов
struct MapView: UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
let mapView = MKMapView()
mapView.delegate = context.coordinator
// Enable user location and request authorization
mapView.showsUserLocation = true
let locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()
//let polygons = getVietnamBorderPolygons()
let polygons = getCountryBorderPolygons()
for polygon in polygons { mapView.addOverlay(polygon) }
// Zoom to fit all polygons and user location on the map
let mapRect = getBoundingRectForPolygons(polygons: polygons)
let paddedRect = mapRect.insetBy(dx: -500000, dy: -500000)
mapView.setVisibleMapRect(paddedRect, animated: true)
return mapView
}
func updateUIView(_ mapView: MKMapView, context: Context) {}
func makeCoordinator() -> Coordinator { Coordinator() }
class Coordinator: NSObject, MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKPolygon {
let renderer = MKPolygonRenderer(overlay: overlay)
renderer.fillColor = UIColor.red.withAlphaComponent(0.3)
renderer.strokeColor = UIColor.red.withAlphaComponent(1)
renderer.lineWidth = 2
return renderer
}
return MKOverlayRenderer(overlay: overlay)
}
}
}