OpenLayers OpenLayers

Ticket #248: double_addlayer.patch

File double_addlayer.patch, 1.4 kB (added by crschmidt, 2 years ago)
  • tests/test_Map.html

    old new  
    219219 
    220220        t.ok( gotLayer == null, "getLayer correctly returns null when layer not found"); 
    221221    } 
     222     
     223    function test_11_Map_double_addLayer(t) { 
     224        t.plan( 1 );     
     225        map = new OpenLayers.Map($('map')); 
     226        layer = new OpenLayers.Layer.WMS('Test Layer',  
     227                    "http://octo.metacarta.com/cgi-bin/mapserv",  
     228                    {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}  
     229                    ); 
    222230 
     231        map.addLayers([layer,layer]); 
     232         
     233        t.eq( map.layers.length, 1, "Map does not allow double adding of layers." ); 
     234     
     235    } 
     236 
    223237    function test_10_Map_setBaseLayer(t) { 
    224238        t.plan( 4 ); 
    225239         
  • lib/OpenLayers/Map.js

    old new  
    285285    * @param {OpenLayers.Layer} layer 
    286286    */     
    287287    addLayer: function (layer) { 
     288        for(var i=0; i < this.layers.length; i++) { 
     289            if (this.layers[i] == layer) { 
     290                return false; 
     291            } 
     292        }     
     293         
    288294        layer.div.style.overflow = ""; 
    289295        this.setLayerZIndex(layer, this.layers.length); 
    290296