I am using mapbox-gl-js to render points from a geojson file onto a map.
For each point I also show a label underneath the marker icon. I currently do this with the following code:
map.addSource("mypoints", {
type: "geojson",
data: "mypoints.geojson",
});
map.addLayer({
"id": "layer-mypoints",
"type": "symbol",
"source": "mypoints",
"layout": {
"icon-image": "marker-15",
"text-field": "{name}",
"text-anchor": "top"
}
});
This works as expected and the points are added to the map and the label is rendered under each point.
To make the map less cluttered I would like to hide the labels when the map is zoomed out past a certain zoom level (and vice versa show the labels when the map is zoomed in). I always want to show the point icons no matter what the zoom level is.
I have no idea how to do this. Any ideas of how to achieve this would be greatly appreciated!