Ticket #3424 (new feature)

Opened 22 months ago

Differentiate between TouchEnd and Click in TouchNavigation Control

Reported by: breul Owned by: tschaub
Priority: trivial Milestone:
Component: Handler.Click Version: SVN
Keywords: event, tap, drag Cc:
State:

Description

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.

Attachments

click_handler_patch.txt Download (1.0 KB) - added by breul 22 months ago.

Change History

Changed 22 months ago by breul

Note: See TracTickets for help on using tickets.