SwiftUI - 1000 Annotations - JSON

Is there somebody who can translate one page of code (Year2014) into actual SwiftUI-Code?

Here is the code:
https://github.com/incanus/PointTest

I do not find any example to read multiple MKMarkerAnnotations from a simple JSON-File stored in the Bundle of project-navigator.
Please help...

Replies


This Code should run in SwiftUI please:



Code Block class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let map = MKMapView(frame: view.bounds)
        map.autoresizingMask = .FlexibleWidth | .FlexibleHeight
        view.addSubview(map)
        var annotations = NSMutableArray()
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
            let pointData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource("3000", ofType: "geojson")!)
            let points = NSJSONSerialization.JSONObjectWithData(pointData!,
                options: nil,
                error: nil) as NSDictionary
            for point in points["features"] as NSArray {
                let coordinate = (point["geometry"] as NSDictionary)["coordinates"] as NSArray
                let lon = coordinate[0] as CLLocationDegrees
                let lat = coordinate[1] as CLLocationDegrees
                let a = MKPointAnnotation()
                a.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lon)
                annotations.addObject(a)
            }
            dispatch_async(dispatch_get_main_queue()) {
                map.addAnnotations(annotations)
                map.showAnnotations(map.annotations, animated: false)
            }
        }
    }
}



This is the sample .geojson-file:



Code Block {
"type": "FeatureCollection",
                                                                                
"features": [
{ "type": "Feature", "id": 0, "properties": { "AssetID": "2430-0051536", "Owner": "PDXTRANS", "MaintResp": "PGE", "LocationID": "BF58671", "ImagePath": null, "PowerSuppl": "PGE", "IsMetered": null, "Engineer": "NotAssigned", "Electricia": "NotAssigned", "LightID": 198761, "ElectricMo": 34481, "StLightCir": 0, "Rotation": 0.0, "LIP": null, "SupplyVolt": null, "Manufactur": null, "SerialNumb": null, "LampCode": "86", "LampCodeDe": "25,500-L,250-W,HPS,COBRA HEAD - POWER DOOR", "MastArmLen": 16, "PoleNumber": 413000054 }, "geometry": { "type": "Point", "coordinates": [ -122.713348173023704, 45.456437213860397 ] } }
}
]
}