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
This commit is contained in:
crschmidt
2008-02-08 16:04:00 +00:00
parent 49e0bff93d
commit 3f7bbdfa9c

View File

@@ -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