From a779f0e69a2722c649e4794a4aca40cd7471990e Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Thu, 8 Mar 2007 19:58:20 +0000 Subject: [PATCH] Map.addLayer() will return false when adding duplicate layers. Fixes #248. git-svn-id: http://svn.openlayers.org/trunk/openlayers@2539 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 6 ++++++ tests/test_Map.html | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index d264226cd3..4b3ea26a7b 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -299,6 +299,12 @@ OpenLayers.Map.prototype = { * @param {OpenLayers.Layer} layer */ addLayer: function (layer) { + for(var i=0; i < this.layers.length; i++) { + if (this.layers[i] == layer) { + return false; + } + } + layer.div.style.overflow = ""; this.setLayerZIndex(layer, this.layers.length); diff --git a/tests/test_Map.html b/tests/test_Map.html index 99a17a8a06..e7d5941980 100644 --- a/tests/test_Map.html +++ b/tests/test_Map.html @@ -219,6 +219,20 @@ t.ok( gotLayer == null, "getLayer correctly returns null when layer not found"); } + + function test_11_Map_double_addLayer(t) { + t.plan( 1 ); + map = new OpenLayers.Map($('map')); + layer = new OpenLayers.Layer.WMS('Test Layer', + "http://octo.metacarta.com/cgi-bin/mapserv", + {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'} + ); + + map.addLayers([layer,layer]); + + t.eq( map.layers.length, 1, "Map does not allow double adding of layers." ); + + } function test_10_Map_setBaseLayer(t) { t.plan( 4 );