Skip to content
James Rae edited this page Jan 19, 2016 · 6 revisions

Objects in the ESRI Javascript API use Dojo on events to indicate when important things happen. As we do not want the Dojo library to be exposed outside of geoApi, we provide a mechanism for a user to register event handlers that will get triggered when the Dojo events happen.

Event handlers are assigned to a handler definition object (examples below) and passed into the geoApi to be registered against the Dojo events. All handlers are optional. Some event arguments are modified from the original dojo event arguments to either abstract specific API implementations or to make code more readable.

TODO link to function that perform the handler registration (events.wrapEvents).

Exposed Events

If more events are required, contact your friendly developer.

Map

click

Native click event. The same event argument will be passed to the handler function.

Occurs when the user clicks the mouse on the map. Clicking a feature on a feature layer will not trigger the map click event.

extentChange

Native extent-change event. The same event argument will be passed to the handler function.

Occurs when the map extent changes.

panStart

Native pan-start event. The same event argument will be passed to the handler function.

Occurs when the map pan begins.

panEnd

Native pan-end event. The same event argument will be passed to the handler function.

Occurs when the map pan ends.

updateStart

Native update-start event. Has no event argument

Occurs when the map begins to update its data.

updateEnd

Native update-end event. The same event argument will be passed to the handler function.

Occurs when the map finishes updating its data.

zoomStart

Native zoom-start event. The same event argument will be passed to the handler function.

Occurs when the map zoom begins.

zoomEnd

Native zoom-end event. The same event argument will be passed to the handler function.

Occurs when the map zoom ends.

Layer

click

Native click event. The same event argument will be passed to the handler function.

Occurs when the user clicks the mouse on a feature of a feature layer. This event will not trigger on other layer types (a map click event will happen).

error

Native error event. Property layer will be added to the event argument pointing to the layer that errored.

Occurs when an error happens during layer processes.

load

Native load event. The same event argument will be passed to the handler function.

Occurs when an error happens during layer processes.

mouseOut

Native mouse-out event. The same event argument will be passed to the handler function.

Occurs when the the mouse leaves a feature of a feature layer. This event will not trigger on other layer types.

mouseOver

Native mouse-over event. The same event argument will be passed to the handler function.

Occurs when the the mouse goes onto a feature of a feature layer. This event will not trigger on other layer types.

updateEnd

Native update-end event. Property layer will be added to the event argument pointing to the layer that finished updating.

Occurs when a layer finishes updating its data.

updateStart

Native update-start event. Property layer will be added to the event argument pointing to the layer that started updating.

Occurs when a layer starts updating its data.

Examples

Sample Event Handler Object Structure

The <fn> placeholders denote where a caller would assign the custom handler functions to be called when the native dojo events occur. All handlers are optional.

{
    map: {
		click: <fn>,
		extentChange: <fn>,
		panEnd: <fn>,
		panStart: <fn>,
		updateEnd: <fn>,
		updateStart: <fn>,
		zoomEnd: <fn>,
		zoomStart: <fn>
	}, 
	layer: {
		click: <fn>,
		error: <fn>,
		load: <fn>,
		mouseOut: <fn>,
		mouseOver: <fn>,
		updateEnd: <fn>,
		updateStart: <fn>
	}
}

Usage Example

//log the map point that was clicked
function mapClickHandler(evt) {
    console.log('Map clicked at screen co-ords');
    console.log(evt.screenPoint.x.toString() + ', ' + evt.screenPoint.y.toString());	
}

//make object that defines handler to trigger on the on the map.click event
let eventHandlers = {
    map: {
		click: mapClickHandler
	}
};

//make the geoApi register our handlers for the map
geoApi.events.wrapEvents(myMap, eventHandlers.map);