From 3f7bbdfa9cfb8dfc7efdea715bea3c7e701a07c1 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Fri, 8 Feb 2008 16:04:00 +0000 Subject: [PATCH] Fix for map destroy doesn't clean up all listeners r=tschaub (Closes #1301) git-svn-id: http://svn.openlayers.org/trunk/openlayers@6108 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index b7b4dbdff4..4fc3386618 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -373,8 +373,10 @@ OpenLayers.Map = OpenLayers.Class({ // Else updateSize on catching the window's resize // Note that this is ok, as updateSize() does nothing if the // map's size has not actually changed. + this.updateSizeDestroy = OpenLayers.Function.bind(this.updateSize, + this); OpenLayers.Event.observe(window, 'resize', - OpenLayers.Function.bind(this.updateSize, this)); + this.updateSizeDestroy); } // only append link stylesheet if the theme property is set @@ -434,6 +436,14 @@ OpenLayers.Map = OpenLayers.Class({ * so that if map is manually destroyed, we can unregister this. */ unloadDestroy: null, + + /** + * Method: updateSizeDestroy + * When the map is destroyed, we need to stop listening to updateSize + * events: this method stores the function we need to unregister in + * non-IE browsers. + */ + updateSizeDestroy: null, /** * APIMethod: destroy @@ -449,6 +459,13 @@ OpenLayers.Map = OpenLayers.Class({ OpenLayers.Event.stopObserving(window, 'unload', this.unloadDestroy); this.unloadDestroy = null; + if (this.updateSizeDestroy) { + OpenLayers.Event.stopObserving(window, 'resize', + this.updateSizeDestroy); + } else { + this.events.unregister("resize", this, this.updateSize); + } + if (this.layers != null) { for (var i = this.layers.length - 1; i>=0; --i) { //pass 'false' to destroy so that map wont try to set a new