diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 4af8ec8423..1e3598bd04 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -138,6 +138,12 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { */ tileQueue: null, + /** + * Property: loading + * {Boolean} Indicates if tiles are being loaded. + */ + loading: false, + /** * Property: backBuffer * {DOMElement} The back buffer. @@ -1050,7 +1056,8 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { tile.onLoadStart = function() { //if that was first tile then trigger a 'loadstart' on the layer - if (this.numLoadingTiles == 0) { + if (this.loading === false) { + this.loading = true; this.events.triggerEvent("loadstart"); } this.events.triggerEvent("tileloadstart", {tile: tile}); @@ -1061,7 +1068,8 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { this.numLoadingTiles--; this.events.triggerEvent("tileloaded", {tile: tile}); //if that was the last tile, then trigger a 'loadend' on the layer - if (this.numLoadingTiles === 0) { + if (this.tileQueue.length === 0 && this.numLoadingTiles === 0) { + this.loading = false; this.events.triggerEvent("loadend"); if(this.backBuffer) { // the removal of the back buffer is delayed to prevent flash