[OpenLayers-Users] BUG - WFS.setOpacity() cannot work reliably

Estanislao Gonzalez estanislao.gonzalez at isst.fraunhofer.de
Mon Dec 8 11:35:29 EST 2008


Hi,

I couldn't fill a bug for it, and don't have currently the time to find 
out why... sorry.

But if someone is kind enough, please do fill it.

The bug is caused because of the multiple inheritance of Layer.WFS 
(inheriting from Layer.Vector and Layer.Markers). I presume the 
intention is to fall back in case the browser doesn't support vector 
rendering.

The method setOpacity for Layer.Markers is different from that of Layer 
(which is the parent class of Layer.Vector) and depends on the markers 
attribute. If WFS is on vectors (myWFS.isVector == true), the 
overwritten setOpacity method tries to access 'markers' which happen to 
be empty. And the nasty bugs prevents the rest of the script from 
running normally.

The solution might be to decide which of the two methods should be used 
(yep, redundant methods... yikes, but inheriting from more than one 
class tends to do that). So here is my proposal which seems to run 
perfect, at least as far as I could test.


            OpenLayers.Layer.WFS.prototype.setOpacity = function(opacity){
                if (this.isVector) {
                    //Sets the opacity to the whole layer
                    //from OpenLayers.Layer.Vector
                    if (opacity != this.opacity) {
                        this.opacity = opacity;
                        for (var i = 0, len = 
this.div.childNodes.length; i < len; ++i) {
                            var element = this.div.childNodes[i].firstChild;
                            OpenLayers.Util.modifyDOMElement(element, 
null, null, null, null, null, null, opacity);
                        }
                    }
                }
                else {
                    // Sets the opacity for all the markers.
                    // from OpenLayers.Layer.Markers
                    if (opacity != this.opacity) {
                        this.opacity = opacity;
                        for (var i = 0, len = this.markers.length; i < 
len; i++) {
                            this.markers[i].setOpacity(this.opacity);
                        }
                    }
                }
            };


As I'm not in the OpenLayers architecture I might have forgotten to do 
something, or neglected to take something into consideration. So if 
someone is kind enough to point the bug and solution to the right 
people, we all will get a better 2.8 version ;-)

Regards,
Estani

-- 
Dipl.-Kfm. Estanislao Gonzalez, Fraunhofer-Institut für Software- und Systemtechnik ISST
Location-based Services, Steinplatz 2, 10623 Berlin, Germany
Telefon: +49 (0) 30 / 2 43 06-3 36
mailto:estanislao.gonzalez at isst.fraunhofer.de
www.isst.fraunhofer.de




More information about the Users mailing list