OpenLayers.Control.SelectFeature on Multiple Vector Layers Breaks setOpacity

If you add multiple vector Layers to a select control in OpenLayers, layer.setOpacity() no longer works. So here is a workaround I found useful.
Just deactivate the select control, set the opacity on the layer, and reacitvate the select control.

1
2
3
4
5
6
7
8
9
10
var selectControl =
new OpenLayers.Control.SelectFeature(vectorLayers, {
hover: false,
highlightOnly: false,
toggle: false
});

selectControl.deactivate();
vectorLayer.setOpacity(.5);
selectControl.activate();

This bug took me a while to find so I thought others might find it useful.

Leave a Reply

Your email address will not be published. Required fields are marked *