diff options
author | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
commit | ea346a785dc1b3f7c156f6fc33da634e1f1a627b (patch) | |
tree | af67530553d20b6e82ad60fd79593e9c4abf5565 /misc/openlayers/tests/Control/LayerSwitcher.html | |
parent | 59741cd535c47f25971bf8c32b25da25ceadc6d5 (diff) | |
download | postrunner-ea346a785dc1b3f7c156f6fc33da634e1f1a627b.zip |
Adding jquery, flot and openlayers to be included with the GEM.v0.0.4
Diffstat (limited to 'misc/openlayers/tests/Control/LayerSwitcher.html')
-rw-r--r-- | misc/openlayers/tests/Control/LayerSwitcher.html | 249 |
1 files changed, 249 insertions, 0 deletions
diff --git a/misc/openlayers/tests/Control/LayerSwitcher.html b/misc/openlayers/tests/Control/LayerSwitcher.html new file mode 100644 index 0000000..c81a779 --- /dev/null +++ b/misc/openlayers/tests/Control/LayerSwitcher.html @@ -0,0 +1,249 @@ +<html> +<head> + <script src="../OLLoader.js"></script> + <script type="text/javascript"> + var map; + OpenLayers.Lang.setCode('en'); + + function test_Control_LayerSwitcher_constructor (t) { + t.plan( 2 ); + + control = new OpenLayers.Control.LayerSwitcher(); + t.ok( control instanceof OpenLayers.Control.LayerSwitcher, "new OpenLayers.Control.LayerSwitcher returns object" ); + t.eq( control.displayClass, "olControlLayerSwitcher", "displayClass is correct" ); + } + + function test_Control_LayerSwitcher_draw (t) { + t.plan( 2 ); + + map = new OpenLayers.Map('map'); + control = new OpenLayers.Control.LayerSwitcher(); + map.addControl(control); + + var div = control.draw(); + t.ok( control.div != null, "draw makes a div" ); + t.ok( div != null, "draw returns its div" ); + } + function test_Control_LayerSwitcher_outsideViewport (t) { + t.plan( 4 ); + + map = new OpenLayers.Map('map'); + control = new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')}); + map.addControl(control); + t.eq(control.div.style.width, "250px", "Div is not minimized when added."); + t.ok(control.events.element && control.events.listeners.buttonclick, "[outside] Events instance attached to div and has buttonclick event"); + control = new OpenLayers.Control.LayerSwitcher(); + map.addControl(control); + t.eq(control.div.style.width, "0px", "Div is minimized when added."); + t.ok(!control.events.element && map.events.listeners.buttonclick, "[inside] Events instance not attached to div and buttonclick event registered on map"); + } + + function test_Control_LayerSwitcher_loadContents(t) { + + t.plan( 10 ); + + 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); + + t.ok(control.layersDiv != null, "correctly makes layers div"); + t.ok(OpenLayers.Element.hasClass(control.layersDiv, "layersDiv"), + "layers div has class layersDiv"); + t.ok(control.baseLayersDiv != null, "correctly makes layers div"); + t.ok(OpenLayers.Element.hasClass(control.baseLayersDiv, "baseLayersDiv"), + "base layers div has class baseLayersDiv"); + t.ok(control.dataLayersDiv != null, "correctly makes layers div"); + t.ok(OpenLayers.Element.hasClass(control.dataLayersDiv, "dataLayersDiv"), + "data layers div has class dataLayersDiv"); + t.ok(control.maximizeDiv != null, "correctly makes resize div"); + t.ok(OpenLayers.Element.hasClass(control.maximizeDiv, "maximizeDiv"), + "maximize div has class maximizeDiv"); + t.ok(control.minimizeDiv != null, "correctly makes resize div"); + t.ok(OpenLayers.Element.hasClass(control.minimizeDiv, "minimizeDiv"), + "minimize div has class minmizeDiv"); + } + + + function test_Control_LayerSwitcher_redraw (t) { + + t.plan( (OpenLayers.BROWSER_NAME == "opera" ? 9 : 19 ) ); + + 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); + + var wmsInput = control.div.childNodes[0].childNodes[1].childNodes[0]; + t.ok(wmsInput != null, "correctly makes an input for wms layer"); + t.eq(wmsInput.type, "radio", "wms correctly made a radio button"); + t.eq(wmsInput.name, control.id + "_baseLayers", "wms correctly named"); + t.eq(wmsInput.value, layer.name, "wms correctly valued"); + + var markersInput = control.div.childNodes[0].childNodes[3].childNodes[0]; + t.ok(markersInput != null, "correctly makes an input for markers layer"); + t.eq(markersInput.type, "checkbox", "wms correctly made a radio button"); + t.eq(markersInput.name, markers.name, "wms correctly named"); + t.eq(markersInput.value, markers.name, "wms correctly valued"); + + t.eq(false, control.checkRedraw(), "check redraw is false"); + if (OpenLayers.BROWSER_NAME != "opera") { + control = new OpenLayers.Control.LayerSwitcher(); + var myredraw = control.redraw; + control.redraw = function() { + t.ok(true, "redraw called when setting vis"); + } + map.addControl(control); + var func = OpenLayers.Function.bind(myredraw, control); + func(); + markers.setVisibility(false); + t.eq(control.checkRedraw(), true, "check redraw is true after changing layer and not letting redraw happen."); + map.removeControl(control); + + control = new OpenLayers.Control.LayerSwitcher(); + var myredraw = control.redraw; + control.redraw = function() { + t.ok(true, "redraw called when setting inRange"); + } + map.addControl(control); + var func = OpenLayers.Function.bind(myredraw, control); + func(); + markers.inRange = false; + t.eq(control.checkRedraw(), true, "check redraw is true after changing layer.inRange and not letting redraw happen."); + map.removeControl(control); + + control = new OpenLayers.Control.LayerSwitcher(); + var myredraw = control.redraw; + control.redraw = function() { + t.ok(true, "redraw called when raising base layer "); + } + + map.addControl(control); + var func = OpenLayers.Function.bind(myredraw, control); + func(); + map.raiseLayer(layer, 1); + t.eq(control.checkRedraw(), true, "check redraw is true after changing layer.inRange and not letting redraw happen."); + map.removeControl(control); + } else { + t.debug_print("FIXME: Some LayerSwitcher tests fail in Opera."); + } + + } + function test_Control_LayerSwitcher_ascending (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.ok(control.div.childNodes[0].childNodes[0].innerHTML.match("Base Layer"), "Base Layers first in LayerSwitcher with ascending true"); + t.ok(control.div.childNodes[0].childNodes[2].innerHTML.match("Overlays"), "Overlays in LayerSwitcher with ascending true"); + t.ok(control2.div.childNodes[0].childNodes[2].innerHTML.match("Base Layer"), "Base Layers last in LayerSwitcher with ascending false"); + t.ok(control2.div.childNodes[0].childNodes[0].innerHTML.match("Overlays"), "Base Layers last in LayerSwitcher with ascending false"); + } + + function test_Control_LayerSwitcher_displayInLayerSwitcher (t) { + + t.plan( 2 ); + + 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"}, {'displayInLayerSwitcher': false}); + map.addLayer(layer); + + control = new OpenLayers.Control.LayerSwitcher(); + map.addControl(control); + t.eq(control.div.childNodes[0].childNodes[0].style.display, "none" , "Base layer display off when no visble base layer"); + + 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); + + control = new OpenLayers.Control.LayerSwitcher(); + map.addControl(control); + t.eq(control.div.childNodes[0].childNodes[0].style.display, "" , "Base layer display on when visble base layer"); + } + + // See e.g. https://github.com/openlayers/openlayers/issues/866 + function test_Control_LayerSwitcher_validIds(t){ + t.plan(2); + + // setup + var layername = "Name with spaces & illegal characters * + ~ ` ' ? )", + map = new OpenLayers.Map("map", { + controls: [ + new OpenLayers.Control.LayerSwitcher() + ], + layers: [ + new OpenLayers.Layer.WMS( + layername, + "../../img/blank.gif" + ), + // add another layer with the same name, the generated id + // must be different + new OpenLayers.Layer.WMS( + layername, + "../../img/blank.gif" + ) + ] + }); + + var baselayerDiv = map.controls[0].div.childNodes[0].childNodes[1], + firstGeneratedInputId = baselayerDiv.childNodes[0].id, + secondGeneratedInputId = baselayerDiv.childNodes[1].id, + // legal ids start with a letter and are followed only by word + // characters (letters, digits, and underscores) plus the dash (-) + // This is only a subset of all allowed charcters inside of ids. + allowedIdChars = (/^[a-zA-Z]{1}[\w-]*$/g); + + // tests + // validity + t.ok( + allowedIdChars.test(firstGeneratedInputId), + "id only contains letters, digits, underscores and dashes. It " + + "starts with a letter." + ); + // uniqueness + t.ok( + firstGeneratedInputId !== secondGeneratedInputId, + "generated ids are different even for equal layernames" + ); + + // teardown + map.destroy(); + } + + </script> +</head> +<body> + <div id="map" style="width: 1024px; height: 512px;"/> + <div id="layerswitcher" style="width:250px; height:256px;" /> +</body> +</html> |