3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
7 function test_Control_LayerSwitcher_constructor (t) {
10 control = new OpenLayers.Control.LayerSwitcher();
11 t.ok( control instanceof OpenLayers.Control.LayerSwitcher, "new OpenLayers.Control.LayerSwitcher returns object" );
12 t.eq( control.displayClass, "olControlLayerSwitcher", "displayClass is correct" );
15 function test_Control_LayerSwitcher_draw (t) {
18 map = new OpenLayers.Map('map');
19 control = new OpenLayers.Control.LayerSwitcher();
20 map.addControl(control);
22 var div = control.draw();
23 t.ok( control.div != null, "draw makes a div" );
24 t.ok( div != null, "draw returns its div" );
26 function test_Control_LayerSwitcher_outsideViewport (t) {
29 map = new OpenLayers.Map('map');
30 control = new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')});
31 map.addControl(control);
32 t.eq(control.div.style.width, "250px", "Div is not minimized when added.");
33 control = new OpenLayers.Control.LayerSwitcher();
34 map.addControl(control);
35 t.eq(control.div.style.width, "0px", "Div is minimized when added.");
38 function test_Control_LayerSwitcher_loadContents(t) {
42 map = new OpenLayers.Map('map');
43 var layer = new OpenLayers.Layer.WMS("WMS",
44 "http://octo.metacarta.com/cgi-bin/mapserv?",
45 {map: "/mapdata/vmap_wms.map", layers: "basic"});
48 markers = new OpenLayers.Layer.Markers("markers");
49 map.addLayer(markers);
51 control = new OpenLayers.Control.LayerSwitcher();
52 map.addControl(control);
54 t.ok(control.layersDiv != null, "correctly makes layers div");
55 t.ok(control.baseLayersDiv != null, "correctly makes layers div");
56 t.ok(control.dataLayersDiv != null, "correctly makes layers div");
58 t.ok(control.maximizeDiv != null, "correctly makes resize div");
59 t.ok(control.minimizeDiv != null, "correctly makes resize div");
66 function test_Control_LayerSwitcher_redraw (t) {
68 t.plan( (OpenLayers.Util.getBrowserName() == "opera" ? 9 : 19 ) );
70 map = new OpenLayers.Map('map');
71 var layer = new OpenLayers.Layer.WMS("WMS",
72 "http://octo.metacarta.com/cgi-bin/mapserv?",
73 {map: "/mapdata/vmap_wms.map", layers: "basic"});
76 markers = new OpenLayers.Layer.Markers("markers");
77 map.addLayer(markers);
79 control = new OpenLayers.Control.LayerSwitcher();
80 map.addControl(control);
82 var wmsInput = OpenLayers.Util.getElement(control.id + "_input_" + layer.name);
83 t.ok(wmsInput != null, "correctly makes an input for wms layer");
84 t.eq(wmsInput.type, "radio", "wms correctly made a radio button");
85 t.eq(wmsInput.name, "baseLayers", "wms correctly named");
86 t.eq(wmsInput.value, layer.name, "wms correctly valued");
88 var markersInput = OpenLayers.Util.getElement(control.id + "_input_" + markers.name);
89 t.ok(markersInput != null, "correctly makes an input for markers layer");
90 t.eq(markersInput.type, "checkbox", "wms correctly made a radio button");
91 t.eq(markersInput.name, markers.name, "wms correctly named");
92 t.eq(markersInput.value, markers.name, "wms correctly valued");
94 t.eq(false, control.checkRedraw(), "check redraw is false");
95 if (OpenLayers.Util.getBrowserName() != "opera") {
96 control = new OpenLayers.Control.LayerSwitcher();
97 var myredraw = control.redraw;
98 control.redraw = function() {
99 t.ok(true, "redraw called when setting vis");
101 map.addControl(control);
102 var func = myredraw.bind(control);
104 markers.setVisibility(false);
105 t.eq(control.checkRedraw(), true, "check redraw is true after changing layer and not letting redraw happen.");
106 map.removeControl(control);
108 control = new OpenLayers.Control.LayerSwitcher();
109 var myredraw = control.redraw;
110 control.redraw = function() {
111 t.ok(true, "redraw called when setting inRange");
113 map.addControl(control);
114 var func = myredraw.bind(control);
116 markers.inRange = false;
117 t.eq(control.checkRedraw(), true, "check redraw is true after changing layer.inRange and not letting redraw happen.");
118 map.removeControl(control);
120 control = new OpenLayers.Control.LayerSwitcher();
121 var myredraw = control.redraw;
122 control.redraw = function() {
123 t.ok(true, "redraw called when raising base layer ");
126 map.addControl(control);
127 var func = myredraw.bind(control);
129 map.raiseLayer(layer, 1);
130 t.eq(control.checkRedraw(), true, "check redraw is true after changing layer.inRange and not letting redraw happen.");
131 map.removeControl(control);
133 t.debug_print("FIXME: Some LayerSwitcher tests fail in Opera.");
137 function test_Control_LayerSwitcher_ascendingw (t) {
141 map = new OpenLayers.Map('map');
142 var layer = new OpenLayers.Layer.WMS("WMS",
143 "http://octo.metacarta.com/cgi-bin/mapserv?",
144 {map: "/mapdata/vmap_wms.map", layers: "basic"});
147 markers = new OpenLayers.Layer.Markers("markers");
148 map.addLayer(markers);
150 control = new OpenLayers.Control.LayerSwitcher();
151 map.addControl(control);
152 control2 = new OpenLayers.Control.LayerSwitcher({'ascending':false});
153 map.addControl(control2);
154 t.ok(control.div.childNodes[1].childNodes[0].innerHTML.match("Base Layer"), "Base Layers first in LayerSwitcher with ascending true");
155 t.ok(control.div.childNodes[1].childNodes[2].innerHTML.match("Overlays"), "Overlays in LayerSwitcher with ascending true");
156 t.ok(control2.div.childNodes[1].childNodes[2].innerHTML.match("Base Layer"), "Base Layers last in LayerSwitcher with ascending false");
157 t.ok(control2.div.childNodes[1].childNodes[0].innerHTML.match("Overlays"), "Base Layers last in LayerSwitcher with ascending false");
160 function test_Control_LayerSwitcher_displayInLayerSwitcher (t) {
164 map = new OpenLayers.Map('map');
165 var layer = new OpenLayers.Layer.WMS("WMS",
166 "http://octo.metacarta.com/cgi-bin/mapserv?",
167 {map: "/mapdata/vmap_wms.map", layers: "basic"}, {'displayInLayerSwitcher': false});
170 control = new OpenLayers.Control.LayerSwitcher();
171 map.addControl(control);
172 t.eq(control.div.childNodes[1].childNodes[0].style.display, "none" , "Base layer display off when no visble base layer");
174 map = new OpenLayers.Map('map');
175 var layer = new OpenLayers.Layer.WMS("WMS",
176 "http://octo.metacarta.com/cgi-bin/mapserv?",
177 {map: "/mapdata/vmap_wms.map", layers: "basic"});
180 control = new OpenLayers.Control.LayerSwitcher();
181 map.addControl(control);
182 t.eq(control.div.childNodes[1].childNodes[0].style.display, "" , "Base layer display on when visble base layer");
190 <div id="map" style="width: 1024px; height: 512px;"/>
191 <div id="layerswitcher" style="width:250px; height:256px;" />