Map Events

When certain actions are performed on the map, a corressponding event is triggered. You can then create listeners to peform specified actions on a layer or do something in your application.

Creating an Event Listener

You can set up a new event listener by calling the register function of the map's events property. There are three main parameters, the first is a string specifying the event type to listen for, the second is the object to bind the context to for the callback function, and the third is the callback function that will be triggered when the event is detected. There is also a fourth optional boolean parameter that if true will place the event at the front of the events queue instead of the end.

var listener = function(event){
    console.log("map mouse over");                  
};
myMap.events.register("mouseover", this, listener);
                

Map Event Types

Supported Events
Event Description
preaddlayer Triggered before a layer has been added. The event object will include a layer property that references the layer to be added. When a listener returns "false" the adding will be aborted.
addlayer Triggered after a layer has been added. The event object will include a layer property that references the added layer.
preremovelayer Triggered before a layer has been removed. The event object will include a layer property that references the layer to be removed. When a listener returns "false" the removal will be aborted.
removelayer Triggered after a layer has been removed. The event object will include a layer property that references the removed layer.
changelayer Triggered after a layer name change, order change, opacity change, params change, visibility change (due to resolution thresholds) or attribution change (due to extent change). Listeners will receive an event object with layer and property properties. The layer property will be a reference to the changed layer. The property property will be a key to the changed property (name, order, opacity, params, visibility or attribution).
movestart Triggered after the start of a drag, pan, or zoom.
move Triggered after each drag, pan, or zoom.
moveend Triggered after a drag, pan, or zoom completes.
zoomend Triggered after a zoom completes.
mouseover Triggered after mouseover the map.
mouseout Triggered after mouseout the map.
mousemove Triggered after mousemove the map.
changebaselayer Triggered after the base layer changes.

Mouse Over Map to Zoom Out