Skip to main content

Events

MapWeave lets you respond to various events fired by the map, which can be triggered either by user interaction or by items changing on the map. Use the on() function to attach an event handler to an event. To detach it, use the off() function.

When an event fires, any attached event handlers are passed a single object containing all the details of the event.

If present, calling the preventDefault() function in the event handler will prevent the event's default action.

ChangeReason

ChangeReason

"auto" | "user"

The reason the event was fired:

  • 'auto' - The event was triggered by internal MapWeave state.
  • 'user' - The event was triggered by user action.

ClickEvent

An object to describe the event fired when the user clicks or taps on the map.

Properties

id

string

The id of the targeted item, or null for the background map.

The targeted item, or null for the background map.

layer

Layer<any, any>

The layer of the targeted item, or null for the background map.

position

The geographic position and height above sea level of the event, or null if not a valid position on the map.

x

number

The distance from the left of the canvas to the pointer position in pixels.

y

number

The distance from the top of the canvas to the pointer position in pixels.


DragEndEvent

An object to describe the event fired when the drag is finished and pointer is released, or when the drag is canceled.

Properties

id

string

The id of the targeted item, or null for the background map.

The targeted item, or null for the background map.

layer

Layer<any, any>

The layer of the targeted item, or null for the background map.

position

The geographic position and height above sea level of the event, or null if not a valid position on the map.

x

number

The distance from the left of the canvas to the pointer position in pixels.

y

number

The distance from the top of the canvas to the pointer position in pixels.


DragMoveEvent

An object to describe the event fired continuously as the cursor moves during a drag.

Properties

entityId

string

When dragging a tracker node, the associated entity id of this trajectory tracker. Otherwise null.

id

string

The id of the targeted item, or null for the background map.

The targeted item, or null for the background map.

layer

Layer<any, any>

The layer of the targeted item, or null for the background map.

position

The geographic position and height above sea level of the event, or null if not a valid position on the map.

time

Date

When dragging a tracker node, the time corresponding to the node's position along the trajectory. Otherwise null.

x

number

The distance from the left of the canvas to the pointer position in pixels.

y

number

The distance from the top of the canvas to the pointer position in pixels.


DragStartEvent

An object to describe the event fired when a drag is started. Default action: Creates a dragger.

Properties

defaultPrevented

boolean

readonly

If the default action was prevented.

id

string

The id of the targeted item, or null for the background map.

The targeted item, or null for the background map.

layer

Layer<any, any>

The layer of the targeted item, or null for the background map.

position

The geographic position and height above sea level of the event, or null if not a valid position on the map.

x

number

The distance from the left of the canvas to the pointer position in pixels.

y

number

The distance from the top of the canvas to the pointer position in pixels.

Methods

preventDefault()

Can be called to prevent the default action of the event.

Returns
void

HoverEvent

An object to describe the event fired when the user hovers over the map.

Properties

id

string

The id of the targeted item, or null for the background map.

The targeted item, or null for the background map.

layer

Layer<any, any>

The layer of the targeted item, or null for the background map.

position

The geographic position and height above sea level of the event, or null if not a valid position on the map.

x

number

The distance from the left of the canvas to the pointer position in pixels.

y

number

The distance from the top of the canvas to the pointer position in pixels.


MapWeaveEventMap

Shows the events available in MapWeave and the object returned to an event handler for that event.

Properties

click

(event) => any

Fires when the user clicks or taps on the map.

Parameters

An object describing the click.

Returns
any

drag-end

(event) => any

Fires when the drag is finished and pointer is released, or when the drag is canceled.

Parameters

An object describing the drag end.

Returns
any

drag-move

(event) => any

Fires continuously as the cursor moves during a drag.

Parameters

An object describing the drag movement.

Returns
any

drag-start

(event) => any

Fires when a drag is started. Default action: Creates a dragger.

Parameters

An object describing the drag.

Returns
any

hover

(event) => any

Fires when the user hovers over the map.

Parameters

An object describing the hover.

Returns
any

load

() => any

Fires when the initial loading completes in MapWeave.

Returns
any

view-change

(event) => any

Fires continuously when the MapWeave view changes, e.g. during zooming or panning.

Parameters

An object describing the view change.

Returns
any

ViewChangeEvent

An object to describe the event fired when the map view changes.

Properties

The new view state after the change.

The reason the view changed.