[OpenLayers-Trac] [OpenLayers] #3424: Differentiate between
TouchEnd and Click in TouchNavigation Control
OpenLayers
trac-20090302 at openlayers.org
Thu Jul 21 06:32:34 EDT 2011
#3424: Differentiate between TouchEnd and Click in TouchNavigation Control
------------------------------+---------------------------------------------
Reporter: breul | Owner: tschaub
Type: feature | Status: new
Priority: trivial | Milestone:
Component: Handler.Click | Version: SVN
Keywords: event, tap, drag | State:
------------------------------+---------------------------------------------
We have been trying to process click events directly in the
TouchNavigation control by passing a function to the click handler in the
TouchNavigation control through the clickHandlerOptions paramter:
{{{
new OpenLayers.Control.TouchNavigation({
dragPanOptions: {
enableKinetic: true
},
pinchZoom: new
OpenLayers.Control.PinchZoom({autoActivate: true}),
clickHandlerOptions: {
handleSingle: function(ev){
//single click code goes here
}
}
})
}}}
The problem we faced was that the handleSingle function is called both on
single tap events and after drag events, as touchend calls handleSingle in
the handler.
We can thus not differentiate between click/tap events and longer drag
events.
We fixed this for our project by keeping track of a timestamp set by the
touchstart event. In touchend that timestamp is evaluated and both the
timestamp as well as the duration of the touch event from touchstart to
touchend is passed on in the event object for convenience. We can then
evaluate this in our hanleSingle function to make sure we are dealing with
a short tap and not a drag. The attached file contains the changes we are
using.
This is of course a quick and dirty fix. Possibly there is already a
better approach to solve this problem in place.
--
Ticket URL: <http://trac.openlayers.org/ticket/3424>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer
More information about the Trac
mailing list