Reputation: 840
I'm trying to highlight specific countries in MapBox iOS.
I have mapbox working correctly to display my own styled maps in my app.
I have followed these instructions: https://www.mapbox.com/help/style-single-country/ and created a new layer that shows highlighted countries correctly in MapBox Studio online, but I can't figure out how to turn this layer on and off in my app's code, and (hopefully) how to pass it arguments so that it knows which country to highlight.
Is this even possible? Or am I not going about this the right way?
Upvotes: 0
Views: 1653
Reputation: 2421
As of Mapbox iOS SDK v3.3.0, it’s not yet possible to modify a style’s layer properties — this is a feature that we call the “runtime styling API” and it’s a longterm project that we’re still working on. You can read more about this future feature and its progress on GitHub.
RobLab’s suggestion of having two different styles is one way to accomplish this today, though not always tenable as you’d need to have a style per highlighted feature. CustomStyleLayer
is not intended for this purpose and is unsupported generally.
Another way would be to add country shapes as annotations using MGLPolygon.
Upvotes: 1
Reputation: 2347
I have two thoughts that may be of use
Swap out your layer by setting the styleURL
property. This requires two Styles (one base layer, one with base layer + country), so may not be ideal.
// Swift code example
self.mapView.styleURL = NSURL(string: self.styleCountry)
Follow the Mapbox iOS demo app model for custom layers. Looks really hard though.
I checked around the Mapbox iOS demo app source code and saw that they have some demo Objective-C code that does a custom layer.
[self.mapView insertCustomStyleLayerWithIdentifier:@"mbx-custom" ...]
Upvotes: 0