Search code examples
mapboxmapbox-gl

Show Two Letter State Code on Mapbox Instead of out of the box Abbreviation Provided


I would like to show the two letter state code on states in the United States of America in mapbox. I've taken a look at the state-label editor shown here:

mapbox screenshot

The closest option is iso_3166_2 but this prepends all the labels with a US- like US-OH. Is there a way to just have OH? any information would be helpful.

Thanks!


Solution

  • I found out that we can use string operators to modify the string as well. https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/

    In your case, slice(coalesce(iso_3166_2), 3, 5) seems to work

    enter image description here