OpenLayers OpenLayers

Ticket #808: loadevents.patch

File loadevents.patch, 6.0 kB (added by crschmidt, 1 year ago)
  • lib/OpenLayers/Layer/GML.js

    old new  
    8383        // loaded after the GML is paited. 
    8484        // See http://trac.openlayers.org/ticket/404 
    8585        if(this.visibility && !this.loaded){ 
     86            this.events.triggerEvent("loadstart"); 
    8687            this.loadGML(); 
    8788        } 
    8889    }, 
     
    115116 
    116117        var gml = this.format ? new this.format() : new OpenLayers.Format.GML(); 
    117118        this.addFeatures(gml.read(doc)); 
     119        this.events.triggerEvent("loadend"); 
    118120    }, 
    119121     
    120122    /** 
     
    127129     */ 
    128130    requestFailure: function(request) { 
    129131        alert("Error in loading GML file "+this.url); 
     132        this.events.triggerEvent("loadend"); 
    130133    }, 
    131134 
    132135    /** @final @type String */ 
  • lib/OpenLayers/Layer/Text.js

    old new  
    4848        OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments); 
    4949        this.features = new Array(); 
    5050        if (this.location != null) { 
     51            this.events.triggerEvent("loadstart"); 
    5152            OpenLayers.loadURL(this.location, null, this, this.parseData); 
    5253        } 
    5354    }, 
     
    151152                } 
    152153            } 
    153154        } 
     155        this.events.triggerEvent("loadend"); 
    154156    }, 
    155157     
    156158    /** 
  • lib/OpenLayers/Layer/WFS.js

    old new  
    3131     */ 
    3232    ratio: 2, 
    3333 
     34    /** 
     35     * Property: numLoadingTiles 
     36     * {Int} The number of tiles outstanding. 
     37     */ 
     38    numLoadingTiles: 0,  
     39 
    3440    /**   
    3541     * Property: DEFAULT_PARAMS 
    3642     * {Object} Hashtable of default key/value parameters 
     
    204210            if (!this.tile) { 
    205211                this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds,  
    206212                                                     url, tileSize); 
     213                this.addTileMonitoringHooks(this.tile); 
    207214                this.tile.draw(); 
    208215            } else { 
    209216                if (this.vectorMode) { 
     
    213220                    this.clearMarkers(); 
    214221                }     
    215222                this.tile.destroy(); 
     223                this.removeTileMonitoringHooks(this.tile); 
    216224                 
    217225                this.tile = null; 
    218226                this.tile = new OpenLayers.Tile.WFS(this, pos, tileBounds,  
     
    222230        } 
    223231    }, 
    224232 
     233    /**  
     234     * Method: addTileMonitoringHooks 
     235     * This function takes a tile as input and adds the appropriate hooks to  
     236     *     the tile so that the layer can keep track of the loading tiles. 
     237     *  
     238     * Parameters:  
     239     * tile - {<OpenLayers.Tile>} 
     240     */ 
     241    addTileMonitoringHooks: function(tile) { 
     242        tile.onLoadStart = function() { 
     243            //if that was first tile then trigger a 'loadstart' on the layer 
     244            if (this.numLoadingTiles == 0) { 
     245                this.events.triggerEvent("loadstart"); 
     246            } 
     247            this.numLoadingTiles++; 
     248        }; 
     249        tile.events.register("loadstart", this, tile.onLoadStart); 
     250       
     251        tile.onLoadEnd = function() { 
     252            this.numLoadingTiles--; 
     253            this.events.triggerEvent("tileloaded"); 
     254            //if that was the last tile, then trigger a 'loadend' on the layer 
     255            if (this.numLoadingTiles == 0) { 
     256                this.events.triggerEvent("loadend"); 
     257            } 
     258        }; 
     259        tile.events.register("loadend", this, tile.onLoadEnd); 
     260    }, 
     261     
     262    /**  
     263     * Method: removeTileMonitoringHooks 
     264     * This function takes a tile as input and removes the tile hooks  
     265     *     that were added in addTileMonitoringHooks() 
     266     *  
     267     * Parameters:  
     268     * tile - {<OpenLayers.Tile>} 
     269     */ 
     270    removeTileMonitoringHooks: function(tile) { 
     271        tile.events.unregister("loadstart", this, tile.onLoadStart); 
     272        tile.events.unregister("loadend", this, tile.onLoadEnd); 
     273    }, 
     274 
    225275    /** 
    226276     * Method: onMapResize 
    227277     * Call the onMapResize method of the appropriate parent class.  
  • lib/OpenLayers/Layer/GeoRSS.js

    old new  
    5561        OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name, options]); 
    5662        this.location = location; 
    5763        this.features = new Array(); 
     64        this.events.triggerEvent("loadstart"); 
    5865        OpenLayers.loadURL(location, null, this, this.parseData); 
    5966    }, 
    6067 
     
    191203            marker.events.register('click', feature, this.markerClick); 
    192204            this.addMarker(marker); 
    193205        } 
     206        this.events.triggerEvent("loadend"); 
    194207    }, 
    195208     
    196209    /** 
  • lib/OpenLayers/Tile/WFS.js

    old new  
    7777     */ 
    7878    draw:function() { 
    7979        if (OpenLayers.Tile.prototype.draw.apply(this, arguments)) { 
     80            if (this.isLoading) { 
     81                //if we're already loading, send 'reload' instead of 'loadstart'. 
     82                this.events.triggerEvent("reload");  
     83            } else { 
     84                this.isLoading = true; 
     85                this.events.triggerEvent("loadstart"); 
     86            } 
    8087            this.loadFeaturesForRegion(this.requestSuccess); 
    8188        } 
    8289    }, 
     
    117124            var resultFeatures = OpenLayers.Ajax.getElementsByTagNameNS(doc, "http://www.opengis.net/gml","gml", "featureMember"); 
    118125            this.addResults(resultFeatures); 
    119126        } 
     127        if (this.isLoading) {  
     128            this.isLoading = false;  
     129            this.events.triggerEvent("loadend");  
     130        } 
    120131    }, 
    121132 
    122133    /**