Remove all shortcuts on Mapbox GL JS?

I am using a style Mapbox Dark v9

and would like to remove all labels.

I found a list of shortcuts here .

And tried the function to map.removeLayer

remove some of them, for example:

map.removeLayer("place_label");

      

As well as:

map.removeLayer("place-city-lg-n");
map.removeLayer("place-city-lg-s");
map.removeLayer("place-city-md-n");
map.removeLayer("place-city-md-s");
map.removeLayer("place-city-sm");

      

Is there a way to remove labels from a style?

+3


source to share


1 answer


If you're just looking for a dark basemap with no labels - that is, it doesn't matter that you programmatically remove them at runtime - you can create a new style in Mapbox Studio using the Dark template and use the style editor to select and remove all layers of labels. Then you can post this style and use its URL in your application.

screenshot



If it is important for you to remove all label layers at runtime, you can do something like

map.style.stylesheet.layers.forEach(function(layer) {
    if (layer.type === 'symbol') {
        map.removeLayer(layer.id);
    }
});

      

+6


source







All Articles