Search code examples
openlayers-3

Changing opacity for layers in ol3


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?


Solution

  • 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