I have the following problem: by default, you can simply change the opacity of layer by writing for example:


But when I add it to my map SelectFeature controls, my layer is put to a thing like OpenLayers.Vector.RootContainer. From this moment I can't set opacity of my layer. I tried lots of ways but none of them work:


Is there an option for using SelectFeature controls without RootContainers? Or a way to change opacity of a container?


OK, I found the solution. I use deactivate and activate on my SelectFeature controls, when I need to set opacity.


This issue is logged in GitHub, along with the patch to set opacity on a Rootcontainer - see https://github.com/openlayers/ol2/pull/1178

Override code below:

OpenLayers.Layer.Vector.prototype.setOpacity = function (opacity) {
    if (opacity != this.opacity) {
        this.opacity = opacity;
        var element = this.renderer.root;
        OpenLayers.Util.modifyDOMElement(element, null, null, null, null,
                null, null, opacity);
        if (this.map != null) {
            this.map.events.triggerEvent("changelayer", {
                layer: this,
                property: "opacity"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.