lundi 2 février 2015

OpenLayers setOpacity fails with multiple layers in selectFeature

Using OpenLayers 2.13. I have a map with 2 vector layers, and a JQuery slider which allows adjustment of the layer opacity.


If I set up a selector to include both layers (for highlighting and popups), my JQuery slider to adjust the opacity doesn't work (layername.setOpacity(x) fails to set the opacity of the layer). If only one layer participates in the selector then setOpacity works fine. Both layers use the same styleMap.



$("#slider-id").slider({
value: 70,
min: 10,
max: 100,
step: 10,
slide: function(e, ui) {
layer1.setOpacity(ui.value / 100);
layer2.setOpacity(ui.value / 100);
} });


This selector allows the opacity to be set for both layers:



var selector = new OpenLayers.Control.SelectFeature(layer1,{
hover:false
});


But this selector does not (setOpacity() fails no matter what):



var selector = new OpenLayers.Control.SelectFeature([layer1, layer2],{
hover:false
});


The Selector is added and activated.



map.addControl(selector);
selector.handlers.feature.stopDown = false; //allow dragging on map
selector.activate();


Is there some way to have multiple layers participate in the selector, while allowing the opacity to be changed?


Aucun commentaire:

Enregistrer un commentaire