OpenLayers OpenLayers

Changeset 3853

Show
Ignore:
Timestamp:
08/04/07 08:14:32 (1 year ago)
Author:
crschmidt
Message:

Commiting fix for #716, "Make LayerSwitcher support displayInLayerSwitcher
for Base Layers", reviewed by Erik, tested by tschaub.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/examples/layerswitcher.html

    r3285 r3853  
    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", 
     
    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> 
  • trunk/openlayers/lib/OpenLayers/Control/LayerSwitcher.js

    r3829 r3853  
    186186         
    187187        var containsOverlays = false; 
     188        var containsBaseLayers = false; 
    188189         
    189190        var layers = this.map.layers.slice(); 
     
    193194            var baseLayer = layer.isBaseLayer; 
    194195 
    195             if (baseLayer || layer.displayInLayerSwitcher) { 
    196  
    197                 if (!baseLayer) { 
     196            if (layer.displayInLayerSwitcher) { 
     197 
     198                if (baseLayer) { 
     199                    containsBaseLayers = true; 
     200                } else { 
    198201                    containsOverlays = true; 
    199                 } 
     202                }     
    200203 
    201204                // only check a baselayer if it is *the* baselayer, check data 
     
    257260        // if no overlays, dont display the overlay label 
    258261        this.dataLbl.style.display = (containsOverlays) ? "" : "none";         
     262         
     263        // if no baselayers, dont display the baselayer label 
     264        this.baseLbl.style.display = (containsBaseLayers) ? "" : "none";         
    259265 
    260266        return this.div; 
     
    427433 
    428434 
    429         var baseLbl = document.createElement("div"); 
    430         baseLbl.innerHTML = "<u>Base Layer</u>"; 
    431         baseLbl.style.marginTop = "3px"; 
    432         baseLbl.style.marginLeft = "3px"; 
    433         baseLbl.style.marginBottom = "3px"; 
     435        this.baseLbl = document.createElement("div"); 
     436        this.baseLbl.innerHTML = "<u>Base Layer</u>"; 
     437        this.baseLbl.style.marginTop = "3px"; 
     438        this.baseLbl.style.marginLeft = "3px"; 
     439        this.baseLbl.style.marginBottom = "3px"; 
    434440         
    435441        this.baseLayersDiv = document.createElement("div"); 
     
    450456 
    451457        if (this.ascending) { 
    452             this.layersDiv.appendChild(baseLbl); 
     458            this.layersDiv.appendChild(this.baseLbl); 
    453459            this.layersDiv.appendChild(this.baseLayersDiv); 
    454460            this.layersDiv.appendChild(this.dataLbl); 
     
    457463            this.layersDiv.appendChild(this.dataLbl); 
    458464            this.layersDiv.appendChild(this.dataLayersDiv); 
    459             this.layersDiv.appendChild(baseLbl); 
     465            this.layersDiv.appendChild(this.baseLbl); 
    460466            this.layersDiv.appendChild(this.baseLayersDiv); 
    461467        }     
  • trunk/openlayers/tests/Control/test_LayerSwitcher.html

    r3534 r3853  
    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) { 
     120 
     121        t.plan( 2 ); 
     122 
     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    } 
    118143 
    119144