OpenLayers.Handler.Click

A handler for mouse clicks.  The intention of this handler is to give controls more flexibility with handling clicks.  Browsers trigger click events twice for a double-click.  In addition, the mousedown, mousemove, mouseup sequence fires a click event.  With this handler, controls can decide whether to ignore clicks associated with a double click.  By setting a pixelTolerance, controls can also ignore clicks that include a drag.  Create a new instance with the OpenLayers.Handler.Click constructor.

Inherits from

Summary
OpenLayers.Handler.ClickA handler for mouse clicks.
Properties
delay{Number} Number of milliseconds between clicks before the event is considered a double-click.
single{Boolean} Handle single clicks.
double{Boolean} Handle double-clicks.
pixelTolerance{Number} Maximum number of pixels between mouseup and mousedown for an event to be considered a click.
dblclickTolerance{Number} Maximum distance in pixels between clicks for a sequence of events to be considered a double click.
stopSingle{Boolean} Stop other listeners from being notified of clicks.
stopDouble{Boolean} Stop other listeners from being notified of double-clicks.
timerId{Number} The id of the timeout waiting to clear the delayedCall.
touch{Boolean} When a touchstart event is fired, touch will be true and all mouse related listeners will do nothing.
down{Object} Object that store relevant information about the last mousedown or touchstart.
last{Object} Object that store relevant information about the last mousemove or touchmove.
first{Object} When waiting for double clicks, this object will store information about the first click in a two click sequence.
rightclickTimerId{Number} The id of the right mouse timeout waiting to clear the <delayedEvent>.
Constructor
OpenLayers.Handler.ClickCreate a new click handler.
Functions
touchstartHandle touchstart.
touchmoveStore position of last move, because touchend event can have an empty “touches” property.
touchendCorrectly set event xy property, and add lastTouches to have touches property from last touchstart or touchmove
unregisterMouseListenersIn a touch environment, we don’t want to handle mouse events.
mousedownHandle mousedown.
mouseupHandle mouseup.
rightclickHandle rightclick.
delayedRightCallSets rightclickTimerId to null.
clickHandle click events from the browser.
dblclickHandle dblclick.
handleDoubleHandle double-click sequence.
handleSingleHandle single click sequence.
queuePotentialClickThis method is separated out largely to make testing easier (so we don’t have to override window.setTimeout)
passesToleranceDetermine whether the event is within the optional pixel tolerance.
getTouchDistance{Boolean} The pixel displacement between two touches.
passesDblclickToleranceDetermine whether the event is within the optional double-cick pixel tolerance.
clearTimerClear the timer and set timerId to null.
delayedCallSets timerId to null.
getEventInfoThis method allows us to store event information without storing the actual event.
deactivateDeactivate the handler.

Properties

delay

{Number} Number of milliseconds between clicks before the event is considered a double-click.

single

{Boolean} Handle single clicks.  Default is true.  If false, clicks will not be reported.  If true, single-clicks will be reported.

double

{Boolean} Handle double-clicks.  Default is false.

pixelTolerance

{Number} Maximum number of pixels between mouseup and mousedown for an event to be considered a click.  Default is 0.  If set to an integer value, clicks with a drag greater than the value will be ignored.  This property can only be set when the handler is constructed.

dblclickTolerance

{Number} Maximum distance in pixels between clicks for a sequence of events to be considered a double click.  Default is 13.  If the distance between two clicks is greater than this value, a double- click will not be fired.

stopSingle

{Boolean} Stop other listeners from being notified of clicks.  Default is false.  If true, any listeners registered before this one for click or rightclick events will not be notified.

stopDouble

{Boolean} Stop other listeners from being notified of double-clicks.  Default is false.  If true, any click listeners registered before this one will not be notified of any double-click events.

The one caveat with stopDouble is that given a map with two click handlers, one with stopDouble true and the other with stopSingle true, the stopSingle handler should be activated last to get uniform cross-browser performance.  Since IE triggers one click with a dblclick and FF triggers two, if a stopSingle handler is activated first, all it gets in IE is a single click when the second handler stops propagation on the dblclick.

timerId

{Number} The id of the timeout waiting to clear the delayedCall.

touch

{Boolean} When a touchstart event is fired, touch will be true and all mouse related listeners will do nothing.

down

{Object} Object that store relevant information about the last mousedown or touchstart.  Its ‘xy’ OpenLayers.Pixel property gives the average location of the mouse/touch event.  Its ‘touches’ property records clientX/clientY of each touches.

last

{Object} Object that store relevant information about the last mousemove or touchmove.  Its ‘xy’ OpenLayers.Pixel property gives the average location of the mouse/touch event.  Its ‘touches’ property records clientX/clientY of each touches.

first

{Object} When waiting for double clicks, this object will store information about the first click in a two click sequence.

rightclickTimerId

{Number} The id of the right mouse timeout waiting to clear the <delayedEvent>.

Constructor

OpenLayers.Handler.Click

Create a new click handler.

Parameters

control{OpenLayers.Control} The control that is making use of this handler.  If a handler is being used without a control, the handler’s setMap method must be overridden to deal properly with the map.
callbacks{Object} An object with keys corresponding to callbacks that will be called by the handler.  The callbacks should expect to recieve a single argument, the click event.  Callbacks for ‘click’ and ‘dblclick’ are supported.
options{Object} Optional object whose properties will be set on the handler.

Functions

touchstart

touchstart: function(evt)

Handle touchstart.

Returns

{Boolean} Continue propagating this event.

touchmove

touchmove: function(evt)

Store position of last move, because touchend event can have an empty “touches” property.

Returns

{Boolean} Continue propagating this event.

touchend

touchend: function(evt)

Correctly set event xy property, and add lastTouches to have touches property from last touchstart or touchmove

Returns

{Boolean} Continue propagating this event.

unregisterMouseListeners

unregisterMouseListeners: function()

In a touch environment, we don’t want to handle mouse events.

mousedown

mousedown: function(evt)

Handle mousedown.

Returns

{Boolean} Continue propagating this event.

mouseup

mouseup: function (evt)

Handle mouseup.  Installed to support collection of right mouse events.

Returns

{Boolean} Continue propagating this event.

rightclick

rightclick: function(evt)

Handle rightclick.  For a dblrightclick, we get two clicks so we need to always register for dblrightclick to properly handle single clicks.

Returns

{Boolean} Continue propagating this event.

delayedRightCall

delayedRightCall: function(evt)

Sets rightclickTimerId to null.  And optionally triggers the rightclick callback if evt is set.

click

click: function(evt)

Handle click events from the browser.  This is registered as a listener for click events and should not be called from other events in this handler.

Returns

{Boolean} Continue propagating this event.

dblclick

dblclick: function(evt)

Handle dblclick.  For a dblclick, we get two clicks in some browsers (FF) and one in others (IE).  So we need to always register for dblclick to properly handle single clicks.  This method is registered as a listener for the dblclick browser event.  It should not be called by other methods in this handler.

Returns

{Boolean} Continue propagating this event.

handleDouble

handleDouble: function(evt)

Handle double-click sequence.

handleSingle

handleSingle: function(evt)

Handle single click sequence.

queuePotentialClick

queuePotentialClick: function(evt)

This method is separated out largely to make testing easier (so we don’t have to override window.setTimeout)

passesTolerance

passesTolerance: function(evt)

Determine whether the event is within the optional pixel tolerance.  Note that the pixel tolerance check only works if mousedown events get to the listeners registered here.  If they are stopped by other elements, the pixelTolerance will have no effect here (this method will always return true).

Returns

{Boolean} The click is within the pixel tolerance (if specified).

getTouchDistance

getTouchDistance: function(from,
to)

Returns

{Boolean} The pixel displacement between two touches.

passesDblclickTolerance

passesDblclickTolerance: function(evt)

Determine whether the event is within the optional double-cick pixel tolerance.

Returns

{Boolean} The click is within the double-click pixel tolerance.

clearTimer

clearTimer: function()

Clear the timer and set timerId to null.

delayedCall

delayedCall: function(evt)

Sets timerId to null.  And optionally triggers the click callback if evt is set.

getEventInfo

getEventInfo: function(evt)

This method allows us to store event information without storing the actual event.  In touch devices (at least), the same event is modified between touchstart, touchmove, and touchend.

Returns

{Object} An object with event related info.

deactivate

deactivate: function()

Deactivate the handler.

Returns

{Boolean} The handler was successfully deactivated.

delayedCall: function(evt)
Sets timerId to null.
touchstart: function(evt)
Handle touchstart.
touchmove: function(evt)
Store position of last move, because touchend event can have an empty “touches” property.
touchend: function(evt)
Correctly set event xy property, and add lastTouches to have touches property from last touchstart or touchmove
unregisterMouseListeners: function()
In a touch environment, we don’t want to handle mouse events.
mousedown: function(evt)
Handle mousedown.
mouseup: function (evt)
Handle mouseup.
rightclick: function(evt)
Handle rightclick.
delayedRightCall: function(evt)
Sets rightclickTimerId to null.
{Number} The id of the right mouse timeout waiting to clear the delayedEvent.
click: function(evt)
Handle click events from the browser.
dblclick: function(evt)
Handle dblclick.
handleDouble: function(evt)
Handle double-click sequence.
handleSingle: function(evt)
Handle single click sequence.
queuePotentialClick: function(evt)
This method is separated out largely to make testing easier (so we don’t have to override window.setTimeout)
passesTolerance: function(evt)
Determine whether the event is within the optional pixel tolerance.
getTouchDistance: function(from,
to)
{Boolean} The pixel displacement between two touches.
passesDblclickTolerance: function(evt)
Determine whether the event is within the optional double-cick pixel tolerance.
clearTimer: function()
Clear the timer and set timerId to null.
{Number} The id of the timeout waiting to clear the delayedCall.
getEventInfo: function(evt)
This method allows us to store event information without storing the actual event.
deactivate: function()
Deactivate the handler.
{Number} Maximum number of pixels between mouseup and mousedown for an event to be considered a click.
Create a new click handler.
Base class to construct a higher-level handler for event sequences.
Controls affect the display or behavior of the map.
Close