applying (yet another) patch for #549. this one eliminates the double-destruction of the map due to the unload of window

git-svn-id: http://svn.openlayers.org/trunk/openlayers@2874 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-03-24 01:37:28 +00:00
parent d10b4a37df
commit 177215befc

View File

@@ -33,6 +33,12 @@ OpenLayers.Map.prototype = {
/** @type OpenLayers.Events */
events: null,
/** function that is called to destroy the map on page unload. stored
* here so that if map is manually destroyed, we can unregister this.
*
* @type Function */
unloadDestroy: null,
/** the div that our map lives in
*
* @type DOMElement */
@@ -212,10 +218,11 @@ OpenLayers.Map.prototype = {
this.popups = new Array();
this.unloadDestroy = this.destroy.bindAsEventListener(this);
// always call map.destroy()
OpenLayers.Event.observe(window,
'unload',
this.destroy.bindAsEventListener(this));
OpenLayers.Event.observe(window, 'unload', this.unloadDestroy);
},
@@ -223,6 +230,11 @@ OpenLayers.Map.prototype = {
* @private
*/
destroy:function() {
// map has been destroyed. dont do it again!
OpenLayers.Event.stopObserving(window, 'unload', this.unloadDestroy);
this.unloadDestroy = null;
if (this.layers != null) {
for(var i=0; i< this.layers.length; i++) {
//pass 'false' to destroy so that map wont try to set a new
@@ -241,6 +253,10 @@ OpenLayers.Map.prototype = {
this.div.removeChild(this.viewPortDiv);
}
this.viewPortDiv = null;
this.events.destroy();
this.events = null;
},
/**