summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Control/Pan.html
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2014-08-12 21:56:44 +0200
committerChris Schlaeger <chris@linux.com>2014-08-12 21:56:44 +0200
commitea346a785dc1b3f7c156f6fc33da634e1f1a627b (patch)
treeaf67530553d20b6e82ad60fd79593e9c4abf5565 /misc/openlayers/tests/Control/Pan.html
parent59741cd535c47f25971bf8c32b25da25ceadc6d5 (diff)
downloadpostrunner-0.0.4.zip
Adding jquery, flot and openlayers to be included with the GEM.v0.0.4
Diffstat (limited to 'misc/openlayers/tests/Control/Pan.html')
-rw-r--r--misc/openlayers/tests/Control/Pan.html201
1 files changed, 201 insertions, 0 deletions
diff --git a/misc/openlayers/tests/Control/Pan.html b/misc/openlayers/tests/Control/Pan.html
new file mode 100644
index 0000000..0c9dfaf
--- /dev/null
+++ b/misc/openlayers/tests/Control/Pan.html
@@ -0,0 +1,201 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script src="../OLLoader.js"></script>
+ <script type="text/javascript">
+
+function test_Pan_constructor (t) {
+ t.plan( 2 );
+
+ // setup
+ var control = new OpenLayers.Control.Pan(
+ "Gargoyle" // the direction, here mocked up
+ );
+
+ // tests
+ //
+ t.ok(
+ control instanceof OpenLayers.Control.Pan,
+ "new OpenLayers.Control.Pan returns object"
+ );
+ t.eq(
+ control.displayClass, "olControlPanGargoyle",
+ "displayClass is correct"
+ );
+
+ // tear down
+ control.destroy();
+}
+
+function test_Pan_type (t) {
+ t.plan( 1 );
+
+ // setup
+ var control = new OpenLayers.Control.Pan();
+
+ // tests
+ //
+ t.eq(
+ control.type,
+ OpenLayers.Control.TYPE_BUTTON,
+ "Pan control is of type OpenLayers.Control.TYPE_BUTTON"
+ );
+
+ // tear down
+ control.destroy();
+}
+
+function test_Pan_constants (t) {
+ var dirs = [
+ 'North',
+ 'East',
+ 'South',
+ 'West'
+ ],
+ numDirs = dirs.length,
+ dir, uc_dir;
+
+ t.plan(numDirs);
+
+ for ( ; numDirs > 0; numDirs-- ) {
+ dir = dirs[numDirs - 1 ];
+ uc_dir = dir.toUpperCase();
+
+ t.eq(
+ OpenLayers.Control.Pan[ uc_dir ],
+ dir,
+ "A constant 'OpenLayers.Control.Pan." + uc_dir + "' is defined "+
+ "and has the correct value of '" + dir + "'."
+ );
+ }
+}
+
+function test_Pan_trigger (t) {
+ t.plan( 12 );
+
+ // set up
+ var controls = {
+ n: new OpenLayers.Control.Pan(OpenLayers.Control.Pan.NORTH),
+ e: new OpenLayers.Control.Pan(OpenLayers.Control.Pan.EAST),
+ s: new OpenLayers.Control.Pan(OpenLayers.Control.Pan.SOUTH),
+ w: new OpenLayers.Control.Pan(OpenLayers.Control.Pan.WEST)
+ },
+ controlKey, control,
+ zoomlevel = 5,
+ center = new OpenLayers.LonLat(25,25),
+ log = {
+ dx: null,
+ dy: null
+ },
+ map = new OpenLayers.Map("map", {
+ allOverlays: true,
+ layers: [
+ new OpenLayers.Layer.Vector()
+ ],
+ center: center,
+ zoom: zoomlevel
+ }),
+ oldZoom;
+
+ // overwrite native Map::pan
+ map.pan = function(dx, dy) {
+ log = {
+ dx: dx,
+ dy: dy
+ };
+ OpenLayers.Map.prototype.pan.apply(map, arguments);
+ };
+
+ oldCenter = map.getCenter().toString();
+
+ for (controlKey in controls) {
+ if (controls.hasOwnProperty(controlKey)) {
+ control = controls[controlKey];
+ // trigger the control; nothing should change, we aren't added yet.
+ control.trigger();
+
+ t.ok(
+ log.dx === null && log.dy === null,
+ 'Calling trigger on a non added control doesn\'t do anything.'
+ );
+
+ // reset log object
+ log = {
+ dx: null,
+ dy: null
+ };
+ }
+ }
+
+ // now lets add the controls, and trigger them again
+ for (controlKey in controls) {
+ if (controls.hasOwnProperty(controlKey)) {
+ control = controls[controlKey];
+ map.addControl(control);
+ // trigger again, now ...
+ control.trigger();
+
+ // ... the center should change ...
+ t.ok(
+ log.dx !== null && log.dy !== null,
+ 'Calling trigger on an added pan control calls map.pan()... '
+ );
+
+ // ... with sane arguments according to the passed direction.
+ switch (control.direction) {
+ case OpenLayers.Control.Pan.NORTH:
+ t.ok(
+ log.dx === 0 && log.dy < 0,
+ '... with sane arguments: pan north only results in ' +
+ 'negative delta y'
+ );
+ break;
+ case OpenLayers.Control.Pan.SOUTH:
+ t.ok(
+ log.dx === 0 && log.dy > 0,
+ '... with sane arguments: pan south only results in ' +
+ 'positive delta y'
+ );
+ break;
+ case OpenLayers.Control.Pan.WEST:
+ t.ok(
+ log.dx < 0 && log.dy === 0,
+ '... with sane arguments: pan west only results in ' +
+ 'negative delta x'
+ );
+ break;
+ case OpenLayers.Control.Pan.EAST:
+ t.ok(
+ log.dx > 0 && log.dy === 0,
+ '... with sane arguments: pan east only results in ' +
+ 'positive delta x'
+ );
+ break;
+ }
+
+ // reset log-object
+ log = {
+ dx: null,
+ dy: null
+ };
+ // always set to initial center and zoom:
+ map.setCenter(center, zoomlevel);
+ }
+ }
+
+ // tear down
+ for (controlKey in controls) {
+ if (controls.hasOwnProperty(controlKey)) {
+ control = controls[controlKey];
+ control.destroy();
+ }
+ }
+ map.destroy();
+}
+
+ </script>
+ </head>
+ <body>
+ <div id="map" style="width: 1000px; height: 1000px;"></div>
+ </body>
+</html>