From cde39e98aef1941b2cc4bffbca371cb4eb6fc6fb Mon Sep 17 00:00:00 2001 From: crschmidt Date: Wed, 12 Mar 2008 12:53:34 +0000 Subject: [PATCH] Improve the handling of tile events with regard to tiles being unloaded before their load events fire by adding an 'unload' event to the tile, and calling it from the places where we're about to stop listening to events. In the longer term, it might make sense to have this be automatic, but this resolves issues with map resizes screwing with tile events, and reverts a previous, incomplete solution to solve a problem with untiled tiles not resizing when the map size changes. r=ahocevar, checked out by bartvde (Closes #1417) git-svn-id: http://svn.openlayers.org/trunk/openlayers@6495 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Grid.js | 4 ++++ lib/OpenLayers/Layer/WFS.js | 3 +++ lib/OpenLayers/Tile.js | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) 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