Maps API for JavaScript Developer's Guide

H.mapevents.MapEvents

Class Summary

Extends: H.util.Disposable

MapEvents enables the events functionality on the map and on map objects. The class makes it possible to listen to events on map objects such as markers, polylines, polygons, circles and on the map object itself. Events are triggered by user interaction, for example clicking or tapping on the map. Please check the Events Summary section for the list of events fired by this class and by the map objects.

[ For full details, see the Class Details ]

Method Summary

Table 1. Methods
Methods

dispose ()

This method destroys the MapEvents instance by removing all handlers from the map object. After calling this method, mapEvents and map objects do not trigger any events. This object is disposed of automatically when the corresponding map object is disposed of.

getAttachedMap () : {H.Map}

This method retrieves the map object to which events are attached.

Events Summary

Table 2. Events
Events

pointerdown : {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) has reached the map surface. It is equivalent to platform-specific events mousedown, touchstart, pointerdown.

pointerup : {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) has left the map surface. It is equivalent to platform-specific events mouseup, touchend, pointerup.

pointermove : {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) has been moved across the screen (and the map). It is equivalent to platform-specific events mousemove, touchmove, pointermove.

pointerenter : {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) has entered the object area. It is equivalent to platform-specific events mouseenter, touchenter, pointerenter. Note: this event is not propagated to the mapEvents object if triggered by a map object (for example marker).

pointerleave : {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) has left the target object area. It is equivalent to platform-specific events mouseleave, touchleave, pointerleave. Note: this event is not propagated to the mapEvents object if triggered by a map object (for example marker).

pointercancel : {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) event has been cancelled by the browser. It is equivalent to platform-specific events touchcancel, pointercancel.

dragstart : {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) started dragging the target. This event is only fired if the target object has draggable property set to true.

drag : {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) is dragging the target. This event is only fired if the target object has draggable property set to true.

dragend : {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) stopped dragging the target. This event is only fired if the target object has draggable property set to true.

tap : {H.mapevents.Event}

This event type signifies that the pointer (touch, pen, mouse) has touched the map (or object) surface for a moment.

dbltap : {H.mapevents.Event}

This event type signifies that the pointer (touch, pen) has touched the map (or object) surface twice in a row for a moment.

longpress : {H.mapevents.Event}

This event is dispatched on the pointer target after pointerdown has occurred and no pointerup was triggered and pointer stayed in place for a longer time.

contextmenu : {H.mapevents.ContextMenuEvent}

This event is dispatched on a target after a right click on the desktop or a longpress on a touch device, but no other pointers were pressed.

contextmenuclose : {H.mapevents.Event}

This event is dispatched after a "contextmenu" event, if there was any user interaction within the map viewport ("mousedown", "touchstart", "pointerdown" or "wheel").

Class Description

MapEvents enables the events functionality on the map and on map objects. The class makes it possible to listen to events on map objects such as markers, polylines, polygons, circles and on the map object itself. Events are triggered by user interaction, for example clicking or tapping on the map. Please check the Events Summary section for the list of events fired by this class and by the map objects.

Example

// prerequisites: mapInstance and marker is initialized
mapInstance.addObject(marker);
var mapevts = new H.mapevents.MapEvents(mapInstance);
// add listener to map
mapInstance.addEventListener('pointermove', function(e) {...});
// add listener to the marker
marker.addEventListener('pointerenter', function(e) {...});
marker.addEventListener('pointerleave', function(e) {...});

Constructor Details

H.mapevents.MapEvents(map)

Parameters:
 
map:
{H.Map}
 
An object representing the map used for firing events

Method Details

dispose ()

This method destroys the MapEvents instance by removing all handlers from the map object. After calling this method, mapEvents and map objects do not trigger any events. This object is disposed of automatically when the corresponding map object is disposed of.

getAttachedMap () : {H.Map}

This method retrieves the map object to which events are attached.

Returns:
 
{H.Map}

Event Details

pointerdown: {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) has reached the map surface. It is equivalent to platform-specific events mousedown, touchstart, pointerdown.

pointerup: {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) has left the map surface. It is equivalent to platform-specific events mouseup, touchend, pointerup.

pointermove: {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) has been moved across the screen (and the map). It is equivalent to platform-specific events mousemove, touchmove, pointermove.

pointerenter: {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) has entered the object area. It is equivalent to platform-specific events mouseenter, touchenter, pointerenter. Note: this event is not propagated to the mapEvents object if triggered by a map object (for example marker).

pointerleave: {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) has left the target object area. It is equivalent to platform-specific events mouseleave, touchleave, pointerleave. Note: this event is not propagated to the mapEvents object if triggered by a map object (for example marker).

pointercancel: {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) event has been cancelled by the browser. It is equivalent to platform-specific events touchcancel, pointercancel.

dragstart: {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) started dragging the target. This event is only fired if the target object has draggable property set to true.

drag: {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) is dragging the target. This event is only fired if the target object has draggable property set to true.

dragend: {H.mapevents.Event}

This event type signifies that the pointer (mouse, pen, touch) stopped dragging the target. This event is only fired if the target object has draggable property set to true.

tap: {H.mapevents.Event}

This event type signifies that the pointer (touch, pen, mouse) has touched the map (or object) surface for a moment.

dbltap: {H.mapevents.Event}

This event type signifies that the pointer (touch, pen) has touched the map (or object) surface twice in a row for a moment.

longpress: {H.mapevents.Event}

This event is dispatched on the pointer target after pointerdown has occurred and no pointerup was triggered and pointer stayed in place for a longer time.

contextmenu: {H.mapevents.ContextMenuEvent}

This event is dispatched on a target after a right click on the desktop or a longpress on a touch device, but no other pointers were pressed.

contextmenuclose: {H.mapevents.Event}

This event is dispatched after a "contextmenu" event, if there was any user interaction within the map viewport ("mousedown", "touchstart", "pointerdown" or "wheel").

The context menu UI component should stop propagation of the aforementioned events to prevent firing of "contextmenuclose" while the user interacts with the context menu.