How can I use the LayerPosition.at() method effectively in Mapbox iOS SDK?

40 views Asked by At

Mapbox iOS SDK has a method .at() defined simply as

/// Layer should be positioned at the specified index in the layers stack.
case at(Int)

This seems like an easy use case, but Mapbox seems to have all the layers, names, location, everything also using this same system and it's not clear to me what number I should use to make a route line appear over all that boilerplate and still have granular control.

Now the other methods like .below() and .above() take in a string of the layer ID, which means I can pass around the names of my overlays and add things above and below them. But .at() simply takes an Int, which makes it difficult to easily compare to other layers and make use of it in a clean way.

I'm having trouble finding examples using it effectively, so can someone direct me to what a good use of this API is?

1

There are 1 answers

0
teradyl On

allLayersIdentifiers shows the current order of all layers: https://docs.mapbox.com/ios/maps/api/10.16.1/Classes/Style.html#/s:10MapboxMaps5StyleC19allLayerIdentifiersSayAA0E4InfoVGvp

moveLayer() moves already added layers: https://docs.mapbox.com/ios/maps/api/10.16.1/Classes/Style.html#/s:10MapboxMaps5StyleC9moveLayer6withId2toySS_AA0E8PositionOtKF

These helped me see how everything is organized and makes for easy usage of functions like .at(), .below(), and .above()