narco narco - 7 months ago 131
iOS Question

MapBox iOS, how do I highlight a country? Or toggle layer visibility?

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:
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?


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.