From 76a420b2784ac4f239f5f5c801c6d0b13df829f5 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 25 Feb 2011 18:35:50 +0000 Subject: [PATCH] Making it so the navigation control zooms out on two touch taps. r=erilem (closes #3127) git-svn-id: http://svn.openlayers.org/trunk/openlayers@11537 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Control/Navigation.js | 13 +++++++++++++ tests/Control/Navigation.html | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) 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 @@ +