diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index b21f1650b7..b827a6a666 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -547,6 +547,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { } }; tile.events.register("loadend", this, tile.onLoadEnd); + tile.events.register("unload", this, tile.onLoadEnd); }, /** @@ -558,9 +559,11 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { * tile - {} */ removeTileMonitoringHooks: function(tile) { + tile.unload() tile.events.un({ "loadstart": tile.onLoadStart, "loadend": tile.onLoadEnd, + "unload": tile.onLoadEnd, scope: this }); }, @@ -700,6 +703,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { */ onMapResize: function() { if (this.singleTile) { + this.clearGrid(); this.setTileSize(); } }, diff --git a/lib/OpenLayers/Layer/WFS.js b/lib/OpenLayers/Layer/WFS.js index f7f9c950ec..6860d38aca 100644 --- a/lib/OpenLayers/Layer/WFS.js +++ b/lib/OpenLayers/Layer/WFS.js @@ -341,6 +341,7 @@ OpenLayers.Layer.WFS = OpenLayers.Class( } }; tile.events.register("loadend", tile, tile.onLoadEnd); + tile.events.register("unload", tile, tile.onLoadEnd); }, /** @@ -352,9 +353,11 @@ OpenLayers.Layer.WFS = OpenLayers.Class( * tile - {} */ removeTileMonitoringHooks: function(tile) { + tile.unload(); tile.events.un({ "loadstart": tile.onLoadStart, "loadend": tile.onLoadEnd, + "unload": tile.onLoadEnd, scope: tile }); }, diff --git a/lib/OpenLayers/Tile.js b/lib/OpenLayers/Tile.js index 06dda8896a..9836d6d677 100644 --- a/lib/OpenLayers/Tile.js +++ b/lib/OpenLayers/Tile.js @@ -25,7 +25,7 @@ OpenLayers.Tile = OpenLayers.Class({ * Constant: EVENT_TYPES * {Array(String)} Supported application event types */ - EVENT_TYPES: [ "loadstart", "loadend", "reload"], + EVENT_TYPES: [ "loadstart", "loadend", "reload", "unload"], /** * APIProperty: events @@ -137,6 +137,20 @@ OpenLayers.Tile = OpenLayers.Class({ this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES); }, + + /** + * Method: unload + * Call immediately before destroying if you are listening to tile + * events, so that counters are properly handled if tile is still + * loading at destroy-time. Will only fire an event if the tile is + * still loading. + */ + unload: function() { + if (this.isLoading) { + this.isLoading = false; + this.events.triggerEvent("unload"); + } + }, /** * APIMethod: destroy