Instead of throwing an exception, return false if the layer can't be added to the map.

This commit is contained in:
fredj
2011-12-01 16:13:35 +01:00
parent 3844b91cd6
commit 1135c771b7
2 changed files with 12 additions and 10 deletions

View File

@@ -938,16 +938,18 @@ OpenLayers.Map = OpenLayers.Class({
*
* Parameters:
* layer - {<OpenLayers.Layer>}
*
* Returns:
* {Boolean} True if the layer has been added to the map.
*/
addLayer: function (layer) {
for(var i = 0, len = this.layers.length; i < len; i++) {
if (this.layers[i] == layer) {
throw new Error("You tried to add the layer: " + layer.name +
" to the map, but it has already been added");
return false;
}
}
if (this.events.triggerEvent("preaddlayer", {layer: layer}) === false) {
return;
return false;
}
if(this.allOverlays) {
layer.isBaseLayer = false;
@@ -979,6 +981,8 @@ OpenLayers.Map = OpenLayers.Class({
this.events.triggerEvent("addlayer", {layer: layer});
layer.events.triggerEvent("added", {map: this, layer: layer});
layer.afterAdd();
return true;
},
/**