OpenLayers OpenLayers

Ticket #716: layerswitcher.patch

File layerswitcher.patch, 5.6 kB (added by crschmidt, 1 year ago)
  • examples/layerswitcher.html

    old new  
    1717 
    1818            var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
    1919                "http://labs.metacarta.com/wms/vmap0", 
    20                 {layers: 'basic'} ); 
     20                {layers: 'basic'}, {'displayInLayerSwitcher':false} ); 
    2121 
    2222            var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic", 
    2323                "http://wms.jpl.nasa.gov/wms.cgi",  
    24                 {layers: "modis,global_mosaic"}); 
     24                {layers: "modis,global_mosaic"}, {'isBaseLayer': false}); 
    2525 
    2626            var dm_wms = new OpenLayers.Layer.WMS( "DM Solutions Demo", 
    2727                "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap", 
     
    4242    <h1>OpenLayers Example</h1> 
    4343    <div id="layerswitcher" style="float:right; width: 20em;"></div> 
    4444    <div id="map"></div> 
     45    <div id="docs"> 
     46      <p>This demonstrates use of the LayerSwitcher outside the map div. It also shows use  
     47         of the displayInLayerSwitcher option on the Layer to cause it to not display in the 
     48         LayerSwitcher.</p> 
     49   </div>       
    4550  </body> 
    4651</html> 
  • lib/OpenLayers/Control/LayerSwitcher.js

    old new  
    187187        this.clearLayersArray("data"); 
    188188         
    189189        var containsOverlays = false; 
     190        var containsBaseLayers = false; 
    190191         
    191192        var layers = this.map.layers.slice(); 
    192193        if (!this.ascending) { layers.reverse(); } 
     
    194195            var layer = layers[i]; 
    195196            var baseLayer = layer.isBaseLayer; 
    196197 
    197             if (baseLayer || layer.displayInLayerSwitcher) { 
     198            if (layer.displayInLayerSwitcher) { 
    198199 
    199200                if (!baseLayer) { 
    200201                    containsOverlays = true; 
    201                 } 
     202                } else { 
     203                    containsBaseLayers = true; 
     204                }     
    202205 
    203206                // only check a baselayer if it is *the* baselayer, check data 
    204207                //  layers if they are visible 
     
    258261 
    259262        // if no overlays, dont display the overlay label 
    260263        this.dataLbl.style.display = (containsOverlays) ? "" : "none";         
     264         
     265        // if no overlays, dont display the overlay label 
     266        this.baseLbl.style.display = (containsBaseLayers) ? "" : "none";         
    261267 
    262268        return this.div; 
    263269    }, 
     
    428434        this.layersDiv.style.height = "100%"; 
    429435 
    430436 
    431         var baseLbl = document.createElement("div"); 
    432         baseLbl.innerHTML = "<u>Base Layer</u>"; 
    433         baseLbl.style.marginTop = "3px"; 
    434         baseLbl.style.marginLeft = "3px"; 
    435         baseLbl.style.marginBottom = "3px"; 
     437        this.baseLbl = document.createElement("div"); 
     438        this.baseLbl.innerHTML = "<u>Base Layer</u>"; 
     439        this.baseLbl.style.marginTop = "3px"; 
     440        this.baseLbl.style.marginLeft = "3px"; 
     441        this.baseLbl.style.marginBottom = "3px"; 
    436442         
    437443        this.baseLayersDiv = document.createElement("div"); 
    438444        this.baseLayersDiv.style.paddingLeft = "10px"; 
     
    451457        this.dataLayersDiv.style.paddingLeft = "10px"; 
    452458 
    453459        if (this.ascending) { 
    454             this.layersDiv.appendChild(baseLbl); 
     460            this.layersDiv.appendChild(this.baseLbl); 
    455461            this.layersDiv.appendChild(this.baseLayersDiv); 
    456462            this.layersDiv.appendChild(this.dataLbl); 
    457463            this.layersDiv.appendChild(this.dataLayersDiv); 
    458464        } else { 
    459465            this.layersDiv.appendChild(this.dataLbl); 
    460466            this.layersDiv.appendChild(this.dataLayersDiv); 
    461             this.layersDiv.appendChild(baseLbl); 
     467            this.layersDiv.appendChild(this.baseLbl); 
    462468            this.layersDiv.appendChild(this.baseLayersDiv); 
    463469        }     
    464470  
  • tests/Control/test_LayerSwitcher.html

    old new  
    115115        t.ok(control2.div.childNodes[1].childNodes[2].innerHTML.match("Base Layer"), "Base Layers last in LayerSwitcher with ascending false"); 
    116116        t.ok(control2.div.childNodes[1].childNodes[0].innerHTML.match("Overlays"), "Base Layers last in LayerSwitcher with ascending false"); 
    117117    } 
     118     
     119    function test_Control_LayerSwitcher_displayInLayerSwitcher (t) { 
    118120 
     121        t.plan( 2 ); 
    119122 
     123        map = new OpenLayers.Map('map'); 
     124        var layer = new OpenLayers.Layer.WMS("WMS",  
     125            "http://octo.metacarta.com/cgi-bin/mapserv?", 
     126            {map: "/mapdata/vmap_wms.map", layers: "basic"}, {'displayInLayerSwitcher': false}); 
     127        map.addLayer(layer); 
     128 
     129        control = new OpenLayers.Control.LayerSwitcher(); 
     130        map.addControl(control); 
     131        t.eq(control.div.childNodes[1].childNodes[0].style.display, "none" , "Base layer display off when no visble base layer"); 
     132         
     133        map = new OpenLayers.Map('map'); 
     134        var layer = new OpenLayers.Layer.WMS("WMS",  
     135            "http://octo.metacarta.com/cgi-bin/mapserv?", 
     136            {map: "/mapdata/vmap_wms.map", layers: "basic"}); 
     137        map.addLayer(layer); 
     138 
     139        control = new OpenLayers.Control.LayerSwitcher(); 
     140        map.addControl(control); 
     141        t.eq(control.div.childNodes[1].childNodes[0].style.display, "" , "Base layer display on when visble base layer"); 
     142    } 
     143 
     144 
    120145  // --> 
    121146  </script> 
    122147</head>