Add 'ascending' flag to LayerSwitcher. Update docs. Add Demo. Add tests.
Closes #256 . git-svn-id: http://svn.openlayers.org/trunk/openlayers@1539 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -11,4 +11,4 @@ This control will by default display a small image in the upper right corner of
|
||||
* Parameters
|
||||
position -- (inherited from {OpenLayers.Control}) {OpenLayers.Pixel} to use as the top-left corner of the control div, relative to the map area.
|
||||
activeColor -- The color to use for the background of the layer switcher div.
|
||||
|
||||
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.
|
||||
|
||||
@@ -13,6 +13,11 @@
|
||||
function init(){
|
||||
var map = new OpenLayers.Map('map', { controls: [] });
|
||||
|
||||
map.addControl(new OpenLayers.Control.PanZoomBar());
|
||||
map.addControl(new OpenLayers.Control.MouseToolbar());
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
|
||||
map.addControl(new OpenLayers.Control.Permalink());
|
||||
map.addControl(new OpenLayers.Control.Permalink($('permalink')));
|
||||
var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||
"http://labs.metacarta.com/wms/vmap0",
|
||||
{layers: 'basic'} );
|
||||
@@ -31,11 +36,6 @@
|
||||
dm_wms.setVisibility(false);
|
||||
|
||||
map.addLayers([ol_wms, jpl_wms, dm_wms]);
|
||||
map.addControl(new OpenLayers.Control.PanZoomBar());
|
||||
map.addControl(new OpenLayers.Control.MouseToolbar());
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
map.addControl(new OpenLayers.Control.Permalink());
|
||||
map.addControl(new OpenLayers.Control.Permalink($('permalink')));
|
||||
if (!map.getCenter()) map.zoomToMaxExtent();
|
||||
}
|
||||
// -->
|
||||
|
||||
@@ -43,6 +43,9 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
||||
/** @type DOMElement */
|
||||
maximizeDiv: null,
|
||||
|
||||
/** @type Boolean */
|
||||
ascending: true,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
@@ -99,8 +102,10 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
||||
|
||||
var containsOverlays = false;
|
||||
|
||||
for( var i = 0; i < this.map.layers.length; i++) {
|
||||
var layer = this.map.layers[i];
|
||||
var layers = this.map.layers.slice();
|
||||
if (!this.ascending) { layers.reverse(); }
|
||||
for( var i = 0; i < layers.length; i++) {
|
||||
var layer = layers[i];
|
||||
var baseLayer = layer.isBaseLayer;
|
||||
|
||||
if (baseLayer || layer.displayInLayerSwitcher) {
|
||||
@@ -309,14 +314,12 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
||||
baseLbl.style.marginTop = "3px";
|
||||
baseLbl.style.marginLeft = "3px";
|
||||
baseLbl.style.marginBottom = "3px";
|
||||
this.layersDiv.appendChild(baseLbl);
|
||||
|
||||
this.baseLayersDiv = document.createElement("div");
|
||||
this.baseLayersDiv.style.paddingLeft = "10px";
|
||||
/*Event.observe(this.baseLayersDiv, "click",
|
||||
this.onLayerClick.bindAsEventListener(this));
|
||||
*/
|
||||
this.layersDiv.appendChild(this.baseLayersDiv);
|
||||
|
||||
|
||||
this.dataLbl = document.createElement("div");
|
||||
@@ -324,14 +327,21 @@ OpenLayers.Control.LayerSwitcher.prototype =
|
||||
this.dataLbl.style.marginTop = "3px";
|
||||
this.dataLbl.style.marginLeft = "3px";
|
||||
this.dataLbl.style.marginBottom = "3px";
|
||||
this.layersDiv.appendChild(this.dataLbl);
|
||||
|
||||
this.dataLayersDiv = document.createElement("div");
|
||||
this.dataLayersDiv.style.paddingLeft = "10px";
|
||||
/*Event.observe(this.dataLayersDiv, "click",
|
||||
this.onLayerClick.bindAsEventListener(this));
|
||||
*/
|
||||
|
||||
if (this.ascending) {
|
||||
this.layersDiv.appendChild(baseLbl);
|
||||
this.layersDiv.appendChild(this.baseLayersDiv);
|
||||
this.layersDiv.appendChild(this.dataLbl);
|
||||
this.layersDiv.appendChild(this.dataLayersDiv);
|
||||
} else {
|
||||
this.layersDiv.appendChild(this.dataLbl);
|
||||
this.layersDiv.appendChild(this.dataLayersDiv);
|
||||
this.layersDiv.appendChild(baseLbl);
|
||||
this.layersDiv.appendChild(this.baseLayersDiv);
|
||||
}
|
||||
|
||||
this.div.appendChild(this.layersDiv);
|
||||
|
||||
|
||||
@@ -81,6 +81,28 @@
|
||||
t.eq(markersInput.value, markers.name, "wms correctly valued");
|
||||
|
||||
}
|
||||
function test_05_Control_LayerSwitcher_ascendingw (t) {
|
||||
|
||||
t.plan( 4 );
|
||||
|
||||
map = new OpenLayers.Map('map');
|
||||
var layer = new OpenLayers.Layer.WMS("WMS",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||
map.addLayer(layer);
|
||||
|
||||
markers = new OpenLayers.Layer.Markers("markers");
|
||||
map.addLayer(markers);
|
||||
|
||||
control = new OpenLayers.Control.LayerSwitcher();
|
||||
map.addControl(control);
|
||||
control2 = new OpenLayers.Control.LayerSwitcher({'ascending':false});
|
||||
map.addControl(control2);
|
||||
t.eq(control.div.childNodes[1].childNodes[0].innerHTML, "<u>Base Layer</u>", "Base Layers first in LayerSwitcher with ascending true");
|
||||
t.eq(control.div.childNodes[1].childNodes[2].innerHTML, "<u>Overlays</u>", "Overlays in LayerSwitcher with ascending true");
|
||||
t.eq(control2.div.childNodes[1].childNodes[2].innerHTML, "<u>Base Layer</u>", "Base Layers last in LayerSwitcher with ascending false");
|
||||
t.eq(control2.div.childNodes[1].childNodes[0].innerHTML, "<u>Overlays</u>", "Base Layers last in LayerSwitcher with ascending false");
|
||||
}
|
||||
|
||||
|
||||
// -->
|
||||
|
||||
Reference in New Issue
Block a user