From a076ce92281441afb3c6753ea17577fe999152d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Junod?= Date: Fri, 25 Feb 2011 15:18:02 +0000 Subject: [PATCH] Handler.Feature: fix mobile support. p=fredj,erilem r=erilem (closes #3106) git-svn-id: http://svn.openlayers.org/trunk/openlayers@11510 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Handler/Feature.js | 16 +++++++++++++- tests/Handler/Feature.html | 36 ++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Handler/Feature.js b/lib/OpenLayers/Handler/Feature.js index eaa39c5620..9d02fff4bf 100644 --- a/lib/OpenLayers/Handler/Feature.js +++ b/lib/OpenLayers/Handler/Feature.js @@ -29,7 +29,8 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { 'mousemove': {'in': 'over', 'out': 'out'}, 'dblclick': {'in': 'dblclick', 'out': null}, 'mousedown': {'in': null, 'out': null}, - 'mouseup': {'in': null, 'out': null} + 'mouseup': {'in': null, 'out': null}, + 'touchstart': {'in': 'click', 'out': 'clickout'} }, /** @@ -117,6 +118,19 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { this.layer = layer; }, + /** + * Method: touchstart + * Handle touchmove events + * + * Parameters: + * evt - {Event} + * + * Returns: + * {Boolean} Let the event propagate. + */ + touchstart: function(evt) { + return this.mousedown(evt); + }, /** * Method: mousedown diff --git a/tests/Handler/Feature.html b/tests/Handler/Feature.html index db258db433..e1131362c9 100644 --- a/tests/Handler/Feature.html +++ b/tests/Handler/Feature.html @@ -53,7 +53,7 @@ } function test_events(t) { - t.plan(25); + t.plan(30); var map = new OpenLayers.Map('map'); var control = new OpenLayers.Control(); @@ -64,7 +64,7 @@ // list below events that should be handled (events) and those // that should not be handled (nonevents) by the handler - var events = ["mousedown", "mouseup", "mousemove", "click", "dblclick"]; + var events = ["mousedown", "mouseup", "mousemove", "click", "dblclick", "touchstart"]; var nonevents = ["mouseout", "resize", "focus", "blur"]; map.events.registerPriority = function(type, obj, func) { var output = func(); @@ -123,7 +123,7 @@ } function test_callbacks(t) { - t.plan(9); + t.plan(13); var map = new OpenLayers.Map('map', {controls: []}); var control = new OpenLayers.Control(); @@ -223,6 +223,36 @@ callbacks['dblclick'] = getCallback('dblclick', newFeature); evtPx.type = "dblclick"; map.events.triggerEvent('dblclick', evtPx); + + // test touchstart on a feature + // 'click' callback should be called + handler.feature = null; + lastFeature = null; + newFeature = new OpenLayers.Feature.Vector(); + newFeature.layer = layer; + callbacks['click'] = getCallback('click (touch)', newFeature); + callbacks['clickout'] = getCallback('clickout (touch)', lastFeature); + evtPx.type = "touchstart"; + map.events.triggerEvent('touchstart', evtPx); + + // test touchstart in new feature and out of last feature + // both 'click' and 'clickout' callbacks should be called + lastFeature = newFeature; + newFeature = new OpenLayers.Feature.Vector(); + newFeature.layer = layer; + callbacks['click'] = getCallback('click (touch)', newFeature); + callbacks['clickout'] = getCallback('clickout (touch)', lastFeature); + evtPx.type = "touchstart"; + map.events.triggerEvent('touchstart', evtPx); + + // test touchstart out of last feature + // only 'clickout' callback should be called + lastFeature = newFeature; + newFeature = null; + callbacks['click'] = getCallback('click (touch)', newFeature); + callbacks['clickout'] = getCallback('clickout (touch)', lastFeature); + evtPx.type = "touchstart"; + map.events.triggerEvent('touchstart', evtPx); } function test_deactivate(t) {