In MapBox, I am trying to highlight an area of GeoJSON in the map, for example this 'Manhattan, NYC' GeoJSON I found as an example. Below is my ViewDidLoad() function, but the FillLayer doesn't seem to be rendering on the map, and I'm not sure why...
override public func viewDidLoad() {
super.viewDidLoad()
let myResourceOptions = ResourceOptions(accessToken: "my_key_here")
let myMapInitOptions = MapInitOptions(resourceOptions: myResourceOptions, styleURI: StyleURI(url: URL(string: "mapbox://styles/custom_URL_here")!)!)
mapView = MapView(frame: view.bounds, mapInitOptions: myMapInitOptions)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let geoJSONDataSourceIdentifier = "SOURCE_ID"
var geoJSONSource = GeoJSONSource()
geoJSONSource.data = .url(URL(string: "https://raw.githubusercontent.com/codeforgermany/click_that_hood/main/public/data/manhattan.geojson")!)
try! mapView.mapboxMap.style.addSource(geoJSONSource, id: geoJSONDataSourceIdentifier)
mapView.mapboxMap.onNext(event: .mapLoaded) { _ in
var polygonLayer = FillLayer(id: "LAYER_ID")
polygonLayer.source = "SOURCE_ID"
polygonLayer.fillColor = .constant(StyleColor(.green))
polygonLayer.fillOpacity = .constant(1)
try! self.mapView.mapboxMap.style.addLayer(polygonLayer)
}
self.view.addSubview(mapView)
}
I'm getting an error: 'Failed to set data for source with id: SOURCE_ID, error: StyleError(rawValue: "Source SOURCE_ID is not in style")' but after doing research haven't found anything related to that error online.