Reputation: 217
Hi–I'm trying to set the opacity of a map to 0.6
, so I could draw a polygon with 1.0
opacity on it.
Now, setting the polygon's opacity is simple. Is there a way to alter the map style's opacity (streets-v10
, in this case)?
Thanks.
Upvotes: 2
Views: 1427
Reputation: 3047
A style is just a list of layers, you'd need to iterate over all the layers and set their opacity. Something like this:
map.getStyle().layers.map((layer) => {
if (layer.type === 'symbol') {
map.setPaintProperty(layer.id, `icon-opacity`, 0.5);
map.setPaintProperty(layer.id, `text-opacity`, 0.5);
} else {
map.setPaintProperty(layer.id, `${layer.type}-opacity`, 0.5);
}
})
Upvotes: 2