# OpenLayers.Event

Utility functions for event handling.

Summary

OpenLayers.Event | Utility functions for event handling.
Constants |
KEY_BACKSPACE | {int}
KEY_TAB | {int}
KEY_RETURN | {int}
KEY_ESC | {int}
KEY_LEFT | {int}
KEY_UP | {int}
KEY_RIGHT | {int}
KEY_DOWN | {int}
KEY_DELETE | {int}
OpenLayers.Events |
Constants |
BROWSER_EVENTS | {Array(String)} supported events
Properties |
fallThrough | {Boolean}
includeXY | {Boolean} Should the .xy property automatically be created for browser mouse events?
Constructor |
OpenLayers.Events | Construct an OpenLayers.Events object.
Functions |
destroy |
addEventType | Add a new event type to this events object.
on | Convenience method for registering listeners with a common scope.
register | Register an event on the events object.
registerPriority | Same as register() but adds the new listener to the front of the events queue instead of to the end.
un | Convenience method for unregistering listeners with a common scope.
unregister |
triggerEvent | Trigger a specified registered event.
clearMouseCache | Clear cached data about the mouse position.

### Constants

### KEY_BACKSPACE

{int}

### KEY_TAB

{int}

### KEY_RETURN

{int}

### KEY_ESC

{int}

### KEY_LEFT

{int}

### KEY_UP

{int}

### KEY_RIGHT

{int}

### KEY_DOWN

{int}

### KEY_DELETE

{int}

## OpenLayers.Events

Summary

Constants |
BROWSER_EVENTS | {Array(String)} supported events
Properties |
fallThrough | {Boolean}
includeXY | {Boolean} Should the .xy property automatically be created for browser mouse events?
Constructor |
OpenLayers.Events | Construct an OpenLayers.Events object.
Functions |
destroy |
addEventType | Add a new event type to this events object.
on | Convenience method for registering listeners with a common scope.
register | Register an event on the events object.
registerPriority | Same as register() but adds the new listener to the front of the events queue instead of to the end.
un | Convenience method for unregistering listeners with a common scope.
unregister |
triggerEvent | Trigger a specified registered event.
clearMouseCache | Clear cached data about the mouse position.

### Constants

### BROWSER_EVENTS

{Array(String)} supported events

### Properties

### fallThrough

{Boolean}

### includeXY

{Boolean} Should the .xy property automatically be created for browser mouse events? In general, this should be false. If it is true, then mouse events will automatically generate a ‘.xy’ property on the event object that is passed. (Prior to OpenLayers 2.7, this was true by default.) Otherwise, you can call the getMousePosition on the relevant events handler on the object available via the ‘evt.object’ property of the evt object. So, for most events, you can call: function named(evt) { this.xy = this.object.events.getMousePosition(evt) }

#### This option typically defaults to false for performance reasons

when creating an events object whose primary purpose is to manage relatively positioned mouse events within a div, it may make sense to set it to true.

This option is also used to control whether the events object caches offsets. If this is false, it will not: the reason for this is that it is only expected to be called many times if the includeXY property is set to true. If you set this to true, you are expected to clear the offset cache manually (using this.clearMouseCache()) if: the border of the element changes the location of the element in the page changes

### Constructor

### OpenLayers.Events

Construct an OpenLayers.Events object.

#### Parameters

object | {Object} The js object to which this Events object is being added
element | {DOMElement} A dom element to respond to browser events
eventTypes | {Array(String)} Array of custom application events
fallThrough | {Boolean} Allow events to fall through after these have been handled?
options | {Object} Options for the events object.

### Functions

### destroy

> destroy: function ()

### addEventType

> addEventType: function( | eventName | )

Add a new event type to this events object. If the event type has already been added, do nothing.

#### Parameters

eventName | {String}

### on

> on: function( | object | )

Convenience method for registering listeners with a common scope. Internally, this method calls register as shown in the examples below.

#### Example use

>     // register a single listener for the "loadstart" event
>     events.on({"loadstart": loadStartListener});

>     // this is equivalent to the following
>     events.register("loadstart", undefined, loadStartListener);

>     // register multiple listeners to be called with the same `this` object
>     events.on({
>         "loadstart": loadStartListener,
>         "loadend": loadEndListener,
>         scope: object
>     });

>     // this is equivalent to the following
>     events.register("loadstart", object, loadStartListener);
>     events.register("loadend", object, loadEndListener);

#### Parameters

object | {Object}

### register

> register: function ( | type,
> | obj,
> | func | )

Register an event on the events object.

When the event is triggered, the ‘func’ function will be called, in the context of ‘obj’. Imagine we were to register an event, specifying an OpenLayers.Bounds Object as ‘obj’. When the event is triggered, the context in the callback function will be our Bounds object. This means that within our callback function, we can access the properties and methods of the Bounds object through the “this” variable. So our callback could execute something like:

>     leftStr = "Left: " + this.left;

or

>     centerStr = "Center: " + this.getCenterLonLat();

#### Parameters

type | {String} Name of the event to register
obj | {Object} The object to bind the context to for the callback#. If no object is specified, default is the Events’s ‘object’ property.
func | {Function} The callback function. If no callback is specified, this function does nothing.

### registerPriority

> registerPriority: function ( | type,
> | obj,
> | func | )

Same as register() but adds the new listener to the front of the events queue instead of to the end.

TODO: get rid of this in 3.0 | Decide whether listeners should be called in the order they were registered or in reverse order.

#### Parameters

type | {String} Name of the event to register
obj | {Object} The object to bind the context to for the callback#. If no object is specified, default is the Events’s ‘object’ property.
func | {Function} The callback function. If no callback is specified, this function does nothing.

### un

> un: function( | object | )

Convenience method for unregistering listeners with a common scope. Internally, this method calls unregister as shown in the examples below.

#### Example use

>     // unregister a single listener for the "loadstart" event
>     events.un({"loadstart": loadStartListener});

>     // this is equivalent to the following
>     events.unregister("loadstart", undefined, loadStartListener);

>     // unregister multiple listeners with the same `this` object
>     events.un({
>         "loadstart": loadStartListener,
>         "loadend": loadEndListener,
>         scope: object
>     });

>     // this is equivalent to the following
>     events.unregister("loadstart", object, loadStartListener);
>     events.unregister("loadend", object, loadEndListener);

### unregister

> unregister: function ( | type,
> | obj,
> | func | )

#### Parameters

type | {String}
obj | {Object} If none specified, defaults to this.object
func | {Function}

### triggerEvent

> triggerEvent: function ( | type,
> | evt | )

Trigger a specified registered event.

#### Parameters

type | {String}
evt | {Event}

#### Returns

{Boolean} The last listener return. If a listener returns false, the chain of listeners will stop getting called.

### clearMouseCache

> clearMouseCache: function()

Clear cached data about the mouse position. This should be called any time the element that events are registered on changes position within the page.

> destroy: function ()

> addEventType: function( | eventName | )

Add a new event type to this events object.

> on: function( | object | )

Convenience method for registering listeners with a common scope.

> register: function ( | type,
> | obj,
> | func | )

Register an event on the events object.

> registerPriority: function ( | type,
> | obj,
> | func | )

Same as register() but adds the new listener to the front of the events queue instead of to the end.

> un: function( | object | )

Convenience method for unregistering listeners with a common scope.

> unregister: function ( | type,
> | obj,
> | func | )

> triggerEvent: function ( | type,
> | evt | )

Trigger a specified registered event.

> clearMouseCache: function()

Clear cached data about the mouse position.
Close