diff --git a/lib/OpenLayers/Control/Navigation.js b/lib/OpenLayers/Control/Navigation.js index 6947a6ee04..bb9b49a195 100644 --- a/lib/OpenLayers/Control/Navigation.js +++ b/lib/OpenLayers/Control/Navigation.js @@ -163,6 +163,7 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { } var clickCallbacks = { + 'click': this.defaultClick, 'dblclick': this.defaultDblClick, 'dblrightclick': this.defaultDblRightClick }; @@ -189,6 +190,18 @@ OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { this.mouseWheelOptions ); }, + /** + * Method: defaultClick + * + * Parameters: + * evt - {Event} + */ + defaultClick: function (evt) { + if (evt.lastTouches && evt.lastTouches.length == 2) { + this.map.zoomOut(); + } + }, + /** * Method: defaultDblClick * diff --git a/tests/Control/Navigation.html b/tests/Control/Navigation.html index 4a2507f0c3..e3b6c900aa 100644 --- a/tests/Control/Navigation.html +++ b/tests/Control/Navigation.html @@ -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 @@ +