Changing opacity for layers in ol3
Asked Answered
M

2

6

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?

Mealtime answered 22/8, 2015 at 10:19 Comment(0)
P
5

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

Princedom answered 22/8, 2015 at 10:47 Comment(1)
That's true! I had it mixed up with brightness/contrast which only seems to be available in the WebGL renderer!Mealtime
M
4

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);
Mil answered 17/7, 2016 at 2:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.