I have a project that uses an OSM2VectorTiles map with Leaflet through the library, mapbox-gl-leaflet, in order to load my own locally-hosted style file. I edited the style file in Mapbox Studio to get it how I wanted it, but now I'm trying to programmatically show and hide certain labels and symbols originating from that file via Leaflet. I thought I had it with

var gl = L.mapboxGL({
    style: 'styles/bright-v9.json',
    accessToken: 'no-token'

gl._glMap.style._layers.place_label_city.layout.visibility = 'none';

but that only has an effect if it's called before the map fully loads in the browser (it does nothing when I stick it inside a jQuery .on handler). My intent is to be able to show and hide the city labels via the Leaflet control. Is it even possible to do this with data contained in the style file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.