# OpenLayers.Handler

Base class to construct a higher-level handler for event sequences. All handlers have activate and deactivate methods. In addition, they have methods named like browser events. When a handler is activated, any additional methods named like a browser event is registered as a listener for the corresponding event. When a handler is deactivated, those same methods are unregistered as event listeners.

Handlers also typically have a callbacks object with keys named like the abstracted events or event sequences that they are in charge of handling. The controls that wrap handlers define the methods that correspond to these abstract events - so instead of listening for individual browser events, they only listen for the abstract events defined by the handler.

Handlers are created by controls, which ultimately have the responsibility of making changes to the the state of the application. Handlers themselves may make temporary changes, but in general are expected to return the application in the same state that they found it.

Summary

OpenLayers.Handler | Base class to construct a higher-level handler for event sequences.
Properties |
id | {String}
control | {OpenLayers.Control}.
map | {OpenLayers.Map}
keyMask | {Integer} Use bitwise operators and one or more of the OpenLayers.Handler constants to construct a keyMask.
active | {Boolean}
evt | {Event} This property references the last event handled by the handler.
Constructor |
OpenLayers.Handler | Construct a handler.
Functions |
setMap |
checkModifiers | Check the keyMask on the handler.
activate | Turn on the handler.
deactivate | Turn off the handler.
callback | Trigger the control’s named callback with the given arguments
register | register an event on the map
unregister | unregister an event from the map
setEvent | With each registered browser event, the handler sets its own evt property.
destroy | Deconstruct the handler.
Constants |
OpenLayers.Handler.MOD_NONE | If set as the keyMask, checkModifiers returns false if any key is down.
OpenLayers.Handler.MOD_SHIFT | If set as the keyMask, checkModifiers returns false if Shift is down.
OpenLayers.Handler.MOD_CTRL | If set as the keyMask, checkModifiers returns false if Ctrl is down.
OpenLayers.Handler.MOD_ALT | If set as the keyMask, checkModifiers returns false if Alt is down.

### Properties

### id

{String}

### control

{OpenLayers.Control}. The control that initialized this handler. The control is assumed to have a valid map property - that map is used in the handler’s own setMap method.

### map

{OpenLayers.Map}

### keyMask

{Integer} Use bitwise operators and one or more of the OpenLayers.Handler constants to construct a keyMask. The keyMask is used by checkModifiers. If the keyMask matches the combination of keys down on an event, checkModifiers returns true.

#### Example

>     // handler only responds if the Shift key is down
>     handler.keyMask = OpenLayers.Handler.MOD_SHIFT;

>     // handler only responds if Ctrl-Shift is down
>     handler.keyMask = OpenLayers.Handler.MOD_SHIFT |
>                       OpenLayers.Handler.MOD_CTRL;

### active

{Boolean}

### evt

{Event} This property references the last event handled by the handler. Note that this property is not part of the stable API. Use of the evt property should be restricted to controls in the library or other applications that are willing to update with changes to the OpenLayers code.

### Constructor

### OpenLayers.Handler

Construct a handler.

#### Parameters

control | {OpenLayers.Control} The control that initialized this handler. The control is assumed to have a valid map property; that map is used in the handler’s own setMap method. If a map property is present in the options argument it will be used instead.
callbacks | {Object} An object whose properties correspond to abstracted events or sequences of browser events. The values for these properties are functions defined by the control that get called by the handler.
options | {Object} An optional object whose properties will be set on the handler.

### Functions

### setMap

> setMap: function ( | map | )

### checkModifiers

> checkModifiers: function ( | evt | )

Check the keyMask on the handler. If no keyMask is set, this always returns true. If a keyMask is set and it matches the combination of keys down on an event, this returns true.

#### Returns

{Boolean} The keyMask matches the keys down on an event.

### activate

> activate: function()

Turn on the handler. Returns false if the handler was already active.

#### Returns

{Boolean} The handler was activated.

### deactivate

> deactivate: function()

Turn off the handler. Returns false if the handler was already inactive.

#### Returns

{Boolean} The handler was deactivated.

### callback

> callback: function ( | name,
> | args | )

Trigger the control’s named callback with the given arguments

#### Parameters

name | {String} The key for the callback that is one of the properties of the handler’s callbacks object.
args | {Array(*)} An array of arguments (any type) with which to call the callback (defined by the control).

### register

> register: function ( | name,
> | method | )

register an event on the map

### unregister

> unregister: function ( | name,
> | method | )

unregister an event from the map

### setEvent

> setEvent: function( | evt | )

With each registered browser event, the handler sets its own evt property. This property can be accessed by controls if needed to get more information about the event that the handler is processing.

This allows modifier keys on the event to be checked (alt, shift, and ctrl cannot be checked with the keyboard handler). For a control to determine which modifier keys are associated with the event that a handler is currently processing, it should access (code)handler.evt.altKey || handler.evt.shiftKey || handler.evt.ctrlKey(end).

#### Parameters

evt | {Event} The browser event.

### destroy

> destroy: function ()

Deconstruct the handler.

### Constants

### OpenLayers.Handler.MOD_NONE

If set as the keyMask, checkModifiers returns false if any key is down.

### OpenLayers.Handler.MOD_SHIFT

If set as the keyMask, checkModifiers returns false if Shift is down.

### OpenLayers.Handler.MOD_CTRL

If set as the keyMask, checkModifiers returns false if Ctrl is down.

### OpenLayers.Handler.MOD_ALT

If set as the keyMask, checkModifiers returns false if Alt is down.

Controls affect the display or behavior of the map.
Instances of OpenLayers.Map are interactive maps embedded in a web page.

> setMap: function ( | map | )

> checkModifiers: function ( | evt | )

Check the keyMask on the handler.

> activate: function()

Turn on the handler.

> deactivate: function()

Turn off the handler.

> callback: function ( | name,
> | args | )

Trigger the control’s named callback with the given arguments

> register: function ( | name,
> | method | )

register an event on the map

> unregister: function ( | name,
> | method | )

unregister an event from the map

> setEvent: function( | evt | )

With each registered browser event, the handler sets its own evt property.

> destroy: function ()

Deconstruct the handler.
{Integer} Use bitwise operators and one or more of the OpenLayers.Handler constants to construct a keyMask.
Close