OpenLayers OpenLayers

Changeset 1539

Show
Ignore:
Timestamp:
10/03/06 08:37:25 (2 years ago)
Author:
crschmidt
Message:

Add 'ascending' flag to LayerSwitcher. Update docs. Add Demo. Add tests.
Closes #256 .

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/doc/Control.LayerSwitcher.txt

    r1424 r1539  
    1212  position -- (inherited from {OpenLayers.Control}) {OpenLayers.Pixel} to use as the top-left corner of the control div, relative to the map area. 
    1313  activeColor -- The color to use for the background of the layer switcher div. 
    14  
     14  ascending -- Ascending determines whether layers are added to the layer switcher in ascending or descending order. If ascending is true, the lowest layer is appended to the list first. If ascending is false, the lowest layer is at the very bottom of the LayerSwitcher. Default is true.   
  • trunk/openlayers/examples/controls.html

    r1424 r1539  
    1414            var map = new OpenLayers.Map('map', { controls: [] }); 
    1515 
     16            map.addControl(new OpenLayers.Control.PanZoomBar()); 
     17            map.addControl(new OpenLayers.Control.MouseToolbar()); 
     18            map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); 
     19            map.addControl(new OpenLayers.Control.Permalink()); 
     20            map.addControl(new OpenLayers.Control.Permalink($('permalink'))); 
    1621            var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
    1722                "http://labs.metacarta.com/wms/vmap0", 
     
    3237 
    3338            map.addLayers([ol_wms, jpl_wms, dm_wms]); 
    34             map.addControl(new OpenLayers.Control.PanZoomBar()); 
    35             map.addControl(new OpenLayers.Control.MouseToolbar()); 
    36             map.addControl(new OpenLayers.Control.LayerSwitcher()); 
    37             map.addControl(new OpenLayers.Control.Permalink()); 
    38             map.addControl(new OpenLayers.Control.Permalink($('permalink'))); 
    3939            if (!map.getCenter()) map.zoomToMaxExtent(); 
    4040        } 
  • trunk/openlayers/lib/OpenLayers/Control/LayerSwitcher.js

    r1528 r1539  
    4444    maximizeDiv: null, 
    4545     
     46    /** @type Boolean */ 
     47    ascending: true, 
     48  
    4649    /** 
    4750    * @constructor 
     
    100103        var containsOverlays = false; 
    101104         
    102         for( var i = 0; i < this.map.layers.length; i++) { 
    103             var layer = this.map.layers[i]; 
     105        var layers = this.map.layers.slice(); 
     106        if (!this.ascending) { layers.reverse(); } 
     107        for( var i = 0; i < layers.length; i++) { 
     108            var layer = layers[i]; 
    104109            var baseLayer = layer.isBaseLayer; 
    105110 
     
    310315        baseLbl.style.marginLeft = "3px"; 
    311316        baseLbl.style.marginBottom = "3px"; 
    312         this.layersDiv.appendChild(baseLbl); 
    313317         
    314318        this.baseLayersDiv = document.createElement("div"); 
     
    317321                      this.onLayerClick.bindAsEventListener(this)); 
    318322        */ 
    319         this.layersDiv.appendChild(this.baseLayersDiv); 
    320323                      
    321324 
     
    325328        this.dataLbl.style.marginLeft = "3px"; 
    326329        this.dataLbl.style.marginBottom = "3px"; 
    327         this.layersDiv.appendChild(this.dataLbl); 
    328330         
    329331        this.dataLayersDiv = document.createElement("div"); 
    330332        this.dataLayersDiv.style.paddingLeft = "10px"; 
    331         /*Event.observe(this.dataLayersDiv, "click",  
    332                       this.onLayerClick.bindAsEventListener(this)); 
    333         */ 
    334         this.layersDiv.appendChild(this.dataLayersDiv); 
    335  
     333 
     334        if (this.ascending) { 
     335            this.layersDiv.appendChild(baseLbl); 
     336            this.layersDiv.appendChild(this.baseLayersDiv); 
     337            this.layersDiv.appendChild(this.dataLbl); 
     338            this.layersDiv.appendChild(this.dataLayersDiv); 
     339        } else { 
     340            this.layersDiv.appendChild(this.dataLbl); 
     341            this.layersDiv.appendChild(this.dataLayersDiv); 
     342            this.layersDiv.appendChild(baseLbl); 
     343            this.layersDiv.appendChild(this.baseLayersDiv); 
     344        }     
     345  
    336346        this.div.appendChild(this.layersDiv); 
    337347 
  • trunk/openlayers/tests/test_Control_LayerSwitcher.html

    r1424 r1539  
    8282 
    8383    } 
     84    function test_05_Control_LayerSwitcher_ascendingw (t) { 
     85 
     86        t.plan( 4 ); 
     87 
     88        map = new OpenLayers.Map('map'); 
     89        var layer = new OpenLayers.Layer.WMS("WMS",  
     90            "http://octo.metacarta.com/cgi-bin/mapserv?", 
     91            {map: "/mapdata/vmap_wms.map", layers: "basic"}); 
     92        map.addLayer(layer); 
     93 
     94        markers = new OpenLayers.Layer.Markers("markers"); 
     95        map.addLayer(markers); 
     96 
     97        control = new OpenLayers.Control.LayerSwitcher(); 
     98        map.addControl(control); 
     99        control2 = new OpenLayers.Control.LayerSwitcher({'ascending':false}); 
     100        map.addControl(control2); 
     101        t.eq(control.div.childNodes[1].childNodes[0].innerHTML, "<u>Base Layer</u>", "Base Layers first in LayerSwitcher with ascending true"); 
     102        t.eq(control.div.childNodes[1].childNodes[2].innerHTML, "<u>Overlays</u>", "Overlays in LayerSwitcher with ascending true"); 
     103        t.eq(control2.div.childNodes[1].childNodes[2].innerHTML, "<u>Base Layer</u>", "Base Layers last in LayerSwitcher with ascending false"); 
     104        t.eq(control2.div.childNodes[1].childNodes[0].innerHTML, "<u>Overlays</u>", "Base Layers last in LayerSwitcher with ascending false"); 
     105    } 
    84106 
    85107