fix for #500 - destroying a layer now has an option to not set a new baselayer. we use this in map.destroy()

git-svn-id: http://svn.openlayers.org/trunk/openlayers@2233 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-02-16 20:59:18 +00:00
parent 1d06490b2c
commit 795d6b4d20
2 changed files with 19 additions and 5 deletions

View File

@@ -137,10 +137,17 @@ OpenLayers.Layer.prototype = {
/** /**
* Destroy is a destructor: this is to alleviate cyclic references which * Destroy is a destructor: this is to alleviate cyclic references which
* the Javascript garbage cleaner can not take care of on its own. * 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) { if (this.map != null) {
this.map.removeLayer(this); this.map.removeLayer(this, setNewBaseLayer);
} }
this.map = null; this.map = null;
this.name = null; this.name = null;

View File

@@ -213,7 +213,9 @@ OpenLayers.Map.prototype = {
destroy:function() { destroy:function() {
if (this.layers != null) { if (this.layers != null) {
for(var i=0; i< this.layers.length; i++) { 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; this.layers = null;
} }
@@ -356,8 +358,13 @@ OpenLayers.Map.prototype = {
* its own personal list of popups, removing them from the map. * its own personal list of popups, removing them from the map.
* *
* @param {OpenLayers.Layer} layer * @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) { if (layer.isFixed) {
this.viewPortDiv.removeChild(layer.div); this.viewPortDiv.removeChild(layer.div);
} else { } else {
@@ -367,7 +374,7 @@ OpenLayers.Map.prototype = {
OpenLayers.Util.removeItem(this.layers, layer); OpenLayers.Util.removeItem(this.layers, layer);
// if we removed the base layer, need to set a new one // if we removed the base layer, need to set a new one
if (this.baseLayer == layer) { if (setNewBaseLayer && (this.baseLayer == layer)) {
this.baseLayer = null; this.baseLayer = null;
for(i=0; i < this.layers.length; i++) { for(i=0; i < this.layers.length; i++) {
var iLayer = this.layers[i]; var iLayer = this.layers[i];