listener function on event "loadend" runs twice

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

listener function on event "loadend" runs twice

Gabriele Seitz
Hi there,

why does listener function on event "loadend" run twice? This is new for 2.11.
I asked before, but narrowed the problem down now.

in 2.10 this code works:

layer1 = new OpenLayers.Layer.Vector("bla", {
        strategies: [new OpenLayers.Strategy.BBOX()],
        filter: myfilter,
        protocol: new OpenLayers.Protocol.WFS({
            url: "http:..geoserver/wfs",
            featureType: "..",
            featureNS: ""
        })
    });

layer1.events.register("loadend", this, function(){
                do something with the features, when features are loaded
});    
   
in 2.11 it works only with this workaround, which does not seem right.

layer1 = new OpenLayers.Layer.Vector("bla",
         ...the same ...
});

var run= 1;
layer1.events.register("loadend", this, function(){
        if (run > 1){
                do something with the features, when features are loaded
        }
        run++;
});  

Whats wrong with my code or with 2.11?

Thanks for your answers.

Gabriele  
Reply | Threaded
Open this post in threaded view
|

Re: listener function on event "loadend" runs twice

Steffen G
Hi,
got the same problem.

Overwriting the triggerRead() method solve it.

OpenLayers.Strategy.BBOX.prototype.triggerRead = function(options) {
/*
    if (this.response) { // in my option not correct mybe this.response.error
       this.layer.protocol.abort(this.response);
       this.layer.events.triggerEvent("loadend"); // raise without error
    }*/
    this.layer.events.triggerEvent("loadstart");
    this.response = this.layer.protocol.read(
        OpenLayers.Util.applyDefaults({
            filter: this.createFilter(),
            callback: this.merge,
            scope: this
    }, options));
};