Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all labels on Mapbox GL JS?

I'm using the Mapbox Dark v9 style and would like to remove all the labels.

I found a list of labels here.

And have tried the map.removeLayer function to remove some of them, e.g.:

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?

like image 612
cpd Avatar asked May 08 '17 06:05

cpd


People also ask

How do I hide labels in Mapbox?

Hide a label 3:27 - Select the layer containing the label you want to change. 3:30 - Switch to the Data Viewer and select Filter. 3:34 - Add a new data condition. 3:37 - Set the condition to exclude any name values you wish to hide.

Does Mapbox use JavaScript?

Mapbox GL JS is a JavaScript library for vector maps on the Web. Its performance, real-time styling, and interactivity features set the bar for anyone building fast, immersive maps on the web.

What does GL stand for Mapbox?

Mapbox GL maps render at a high frame rate. The abbreviation "GL" comes from OpenGL, the industry-standard Open Graphics Library. Mapbox GL allows you to use custom styles designed in Mapbox Studio.


1 Answers

If you're just looking for a dark basemap without labels — i.e. it's not important for you to remove them programmatically at runtime — you can create a new style in Mapbox Studio using the Dark template and use the style editor to select and delete all label layers. You can then publish the style and use its url in your app.

screenshot

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

map.style.stylesheet.layers.forEach(function(layer) {
    if (layer.type === 'symbol') {
        map.removeLayer(layer.id);
    }
});
like image 195
Lauren Budorick Avatar answered Sep 20 '22 13:09

Lauren Budorick