[OpenLayers-Commits] r11537 - in trunk/openlayers: lib/OpenLayers/Control tests/Control

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Feb 25 13:35:55 EST 2011


Author: tschaub
Date: 2011-02-25 10:35:50 -0800 (Fri, 25 Feb 2011)
New Revision: 11537

Modified:
   trunk/openlayers/lib/OpenLayers/Control/Navigation.js
   trunk/openlayers/tests/Control/Navigation.html
Log:
Making it so the navigation control zooms out on two touch taps.  r=erilem (closes #3127)

Modified: trunk/openlayers/lib/OpenLayers/Control/Navigation.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/Navigation.js	2011-02-25 18:14:29 UTC (rev 11536)
+++ trunk/openlayers/lib/OpenLayers/Control/Navigation.js	2011-02-25 18:35:50 UTC (rev 11537)
@@ -163,6 +163,7 @@
         }
 
         var clickCallbacks = { 
+            'click': this.defaultClick,
             'dblclick': this.defaultDblClick, 
             'dblrightclick': this.defaultDblRightClick 
         };
@@ -190,6 +191,18 @@
     },
 
     /**
+     * Method: defaultClick
+     *
+     * Parameters:
+     * evt - {Event}
+     */
+    defaultClick: function (evt) {
+        if (evt.lastTouches && evt.lastTouches.length == 2) {
+            this.map.zoomOut();
+        }
+    },
+
+    /**
      * Method: defaultDblClick 
      * 
      * Parameters:

Modified: trunk/openlayers/tests/Control/Navigation.html
===================================================================
--- trunk/openlayers/tests/Control/Navigation.html	2011-02-25 18:14:29 UTC (rev 11536)
+++ trunk/openlayers/tests/Control/Navigation.html	2011-02-25 18:35:50 UTC (rev 11537)
@@ -118,6 +118,27 @@
         t.eq(nav.zoomWheelEnabled, true, "mouse wheel activated");
         t.eq(wheel.active, true, "mouse wheel handler activated");
     }
+
+    function test_touches_zoom(t) {
+        t.plan(3);
+        var nav = new OpenLayers.Control.Navigation({zoomWheelEnabled: false});
+        var map = new OpenLayers.Map({
+            div: "map",
+            controls: [nav],
+            layers: [
+                new OpenLayers.Layer(null, {isBaseLayer: true})
+            ],
+            center: new OpenLayers.LonLat(0, 0),
+            zoom: 3
+        });
+        t.eq(map.getZoom(), 3, "map zoom starts at 3");
+        nav.handlers.click.callback("click", [{lastTouches: ["foo", "bar"]}]);
+        t.eq(map.getZoom(), 2, "map zooms out with a two touch tap");
+        nav.handlers.click.callback("click", [{}]);
+        t.eq(map.getZoom(), 2, "map doesn't do anything with click");
+        
+        map.destroy();
+    }
     
     function test_documentDrag(t) {
         
@@ -149,5 +170,6 @@
   </script>
 </head>
 <body>
+    <div id="map" style="width: 256px; height: 256px"></div>
 </body>
 </html>



More information about the Commits mailing list