The standard KVO events beforepropertychange and change are available, as well as one event for each of the observable properties: change:layergroup, change:size, change:target, and change:view. Review the section on KVO in Chapter 2, Key Concepts in OpenLayers if you don't remember how these events work.
In addition to the KVO related events, however, there are quite a few new events that can be triggered from a map object. As with any other event, you can register for these events using the on() and once() methods discussed earlier. We'll group these events into browser events, map events, and render events.
The Browser events are all events that are provided in response to the user interacting with the map's HTML element. The available events are:
click: This event is fired once for every discrete click on the map. If the user double-clicks on the map, this event will be fired twice. If you want to distinguish between a click and a double-click, use the singleclick event instead.dblclick: This event is fired if the user double-clicks the map.pointerdrag: This event is fired when the user moves the mouse while holding down one of the mouse buttons.pointermove: This event is fired when the user moves the mouse.singleclick: This event is fired when the user single-clicks on the map. There is a short 250 ms delay after the click event before this event is triggered to ensure that the user is not double-clicking the map.Listeners attached to the Browser events will receive an object of the ol.MapBrowserEvent type that contains the following properties:
type – This is a string, MapBrowserEvent.map: The ol.Map is a reference to the map object on which the event happened.browserEvent: The DOMEvent is a standard browser event that was originally issued by the browser. This will contain information about the event (its position and what the user did—move, click, and so on) that you'd be usually looking for.frameState: This is an object representing the current frame state of the map.There are two events that are triggered when the map state changes.
Listeners attached to the map events will receive an object of the ol.MapEvent type, which contains the following properties:
There are two events that are triggered when the map is being rendered. These can be used to programmatically alter the appearance of the rendered map image in interesting ways:
precompose: This event is triggered when the map is rendered, just before all the layers will be drawn into the rendering context.postrender: This event is triggered when the map has completed rendering all the layers into the current rendering context. This is a very interesting event as it provides an opportunity to modify the canvas (for Canvas and WebGL renderers) after the map has been rendered. We'll explore this in Chapter 6, Styling Vector Layers when we discuss vector styling.Listeners attached to the render events will receive an object of the ol.render.Event type that contains the following properties:
type: This is a MapEvent stringtarget: The ol.Map is a reference to the map object on which the event happenedvectorContext: This is a rendering API capable of drawing to the contextframeState: This is an object representing the current frame state of the mapcontext: This is the 2D context associated with the canvas (if applicable)glContext: This is a WebGL rendering context (if applicable)