I have a vague memory of seeing examples of Open Layers 3 where the added layers' opacity could be changed. There are still such examples on the ol3 examples page but they require the webgl-renderer (which rules out vector layers). Is there any way to change the opacity of vector and/or raster layers with the regular canvas renderer?
Changing opacity for layers in ol3
Asked Answered
I don't know if any of the vector examples use it, but all ol3 layers support the setOpacity method:
https://openlayers.org/en/v3.20.1/apidoc/ol.layer.Vector.html#setOpacity
That's true! I had it mixed up with brightness/contrast which only seems to be available in the WebGL renderer! –
Mealtime
Here is how you do it for an image layer. For other layers use the same function:
myimage = new ol.layer.Image({
source: new ol.source.ImageStatic({
url:some_url,
crossOrigin: '',
projection: 'EPSG:26916',
imageExtent: some_extent
}),
opacity: 1.0
});
.
.
.
myimage.setOpacity(0.6);
© 2022 - 2024 — McMap. All rights reserved.