12

I'm using OpenLayers with mapserver to display a lot of raster images and queryable wms layers. Everything works fine, the layers can be turned on/off in the OpenLayers layer switcher...But now I want to turn on/off the layers by external checkboxes and I don't know how to do this.

I'm little bit new to Javascript-the only thing I know is that I have to pass the checkbox layer value to an OpenLayers function. Till now I tried to call a function with an onClick event

<input type="checkbox" name="ckeckbox_layer1" onClick="layervisibility(this.checked);">

But I don't know how the function 'layervisibility' has to look like so that my layers that are actually placed in the openlayers init() function turn on/off correctly when I check/uncheck the checkboxes.

Mesa
  • 1,492
  • 9
  • 21
Peter
  • 129
  • 1
  • 1
  • 3

1 Answers1

14

OpenLayers 2:

layer.setVisibility(true)

OpenLayers >= 3:

layer.setVisible(true)

Lots of examples here: http://openlayers.org/en/latest/examples/

Specific example: https://openlayers.org/en/latest/examples/layer-group.html

Rayner
  • 3,721
  • 1
  • 23
  • 30