diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index ca90260c68..4df77a5d06 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -137,10 +137,17 @@ OpenLayers.Layer.prototype = { /** * Destroy is a destructor: this is to alleviate cyclic references which * the Javascript garbage cleaner can not take care of on its own. + * + * @param {Boolean} setNewBaseLayer Should a new baselayer be selected when + * this has been removed? + * Default is true */ - destroy: function() { + destroy: function(setNewBaseLayer) { + if (setNewBaseLayer == null) { + setNewBaseLayer = true; + } if (this.map != null) { - this.map.removeLayer(this); + this.map.removeLayer(this, setNewBaseLayer); } this.map = null; this.name = null; diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 2ca3dec334..da3238ae27 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -213,7 +213,9 @@ OpenLayers.Map.prototype = { destroy:function() { if (this.layers != null) { for(var i=0; i< this.layers.length; i++) { - this.layers[i].destroy(); + //pass 'false' to destroy so that map wont try to set a new + // baselayer after each baselayer is removed + this.layers[i].destroy(false); } this.layers = null; } @@ -356,8 +358,13 @@ OpenLayers.Map.prototype = { * its own personal list of popups, removing them from the map. * * @param {OpenLayers.Layer} layer + * @param {Boolean} setNewBaseLayer Default is true */ - removeLayer: function(layer) { + removeLayer: function(layer, setNewBaseLayer) { + if (setNewBaseLayer == null) { + setNewBaseLayer = true; + } + if (layer.isFixed) { this.viewPortDiv.removeChild(layer.div); } else { @@ -367,7 +374,7 @@ OpenLayers.Map.prototype = { OpenLayers.Util.removeItem(this.layers, layer); // if we removed the base layer, need to set a new one - if (this.baseLayer == layer) { + if (setNewBaseLayer && (this.baseLayer == layer)) { this.baseLayer = null; for(i=0; i < this.layers.length; i++) { var iLayer = this.layers[i];