Search code examples
iosswiftcrashmapboxbounding-box

Mapbox iOS SDK dynamic styling coordinate bounds crash


I am trying to work out of the watercolor raster layer example in Mapbox examples and add an extra bounding box parameter as per documentation. The app always crashes with NSException and no further insights.

  func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
    let bounds = MGLCoordinateBounds(sw: CLLocationCoordinate2D(latitude: -180, longitude: -85.05112877980659), ne: CLLocationCoordinate2D(latitude: 180, longitude: 85.0511287798066))
    let source = MGLRasterTileSource(identifier: "stamen-watercolor", tileURLTemplates: ["https://stamen-tiles.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg"], options: [ .tileSize: 256, .coordinateBounds: bounds])
    let rasterLayer = MGLRasterStyleLayer(identifier: "stamen-watercolor", source: source)

    style.addSource(source)
    style.addLayer(rasterLayer) }

Is this option parameter unsupported? Or am I doing something wrong?


Solution

  • Figured out the issue was not adding the bounds as an NSValue and instead just adding them as an MGLCoordinateBounds.