One OL Layer per style-file layer? #1207
-
Hello! First of all, thanks for this amazing tool, it's a real time saver. I have a question though. Would it possible somehow to tell the Currently, if I have a style file with multiple layers declared, after calling the However, I'd really prefer it to create 1 OL Layer for each style-file-declared one. I need this to be able to toggle their visibility independently. Is this somehow achievable? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Layers in a Mapbox Style document are a completely different concept than layers in OpenLayers. If you want to toggle the visibility of a layer from the Mapbox Style document, you can use the updateMapboxLayer() function, setting the |
Beta Was this translation helpful? Give feedback.
-
@ahocevar thanks for the quick response. I tried 2 different approaches, one that you suggested, and another one is removing a layer altogether, instead of trying to hide it. None of them seem to produce any effect. Do I miss something?
Here's the link to the style file, just in case: https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json |
Beta Was this translation helpful? Give feedback.
-
For "building", you won't see much difference because "building_top" is on top of "building". And for "water", you won't see much difference either, because "water_shadow" is on top of it. See https://codesandbox.io/p/sandbox/mapbox-style-forked-8psldc for an example that sets layers whose id starts with |
Beta Was this translation helpful? Give feedback.
For "building", you won't see much difference because "building_top" is on top of "building". And for "water", you won't see much difference either, because "water_shadow" is on top of it.
See https://codesandbox.io/p/sandbox/mapbox-style-forked-8psldc for an example that sets layers whose id starts with
"building"
or"water"
to invisible.