React
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. To attach an event handler to an event, add the event handler prop in the MapWeave tag.
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"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.
An object to describe the event fired when the user clicks or taps on the map.
stringThe id of the targeted item, or null for the background map.
The targeted item, or null for the background map.
Layer<any, any, any>The layer of the targeted item, or null for the background map.
The geographic position and height above sea level of the event, or null if not a valid position on the map.
numberThe distance from the left of the canvas to the pointer position in pixels.
numberThe distance from the top of the canvas to the pointer position in pixels.
An object to describe the event fired when the drag is finished and pointer is released, or when the drag is canceled.
stringThe id of the targeted item, or null for the background map.
The targeted item, or null for the background map.
Layer<any, any, any>The layer of the targeted item, or null for the background map.
The geographic position and height above sea level of the event, or null if not a valid position on the map.
numberThe distance from the left of the canvas to the pointer position in pixels.
numberThe distance from the top of the canvas to the pointer position in pixels.
An object to describe the event fired continuously as the cursor moves during a drag.
stringWhen dragging a tracker node, the associated entity id of this trajectory tracker. Otherwise null.
stringThe id of the targeted item, or null for the background map.
The targeted item, or null for the background map.
Layer<any, any, any>The layer of the targeted item, or null for the background map.
The geographic position and height above sea level of the event, or null if not a valid position on the map.
DateWhen dragging a tracker node, the time corresponding to the node's position along the trajectory. Otherwise null.
numberThe distance from the left of the canvas to the pointer position in pixels.
numberThe distance from the top of the canvas to the pointer position in pixels.
An object to describe the event fired when a drag is started. Default action: Creates a dragger.
If the default action was prevented.
stringThe id of the targeted item, or null for the background map.
The targeted item, or null for the background map.
Layer<any, any, any>The layer of the targeted item, or null for the background map.
The geographic position and height above sea level of the event, or null if not a valid position on the map.
numberThe distance from the left of the canvas to the pointer position in pixels.
numberThe distance from the top of the canvas to the pointer position in pixels.
Can be called to prevent the default action of the event.
Returns void
An object to describe the event fired when the user hovers over the map.
stringThe id of the targeted item, or null for the background map.
The targeted item, or null for the background map.
Layer<any, any, any>The layer of the targeted item, or null for the background map.
The geographic position and height above sea level of the event, or null if not a valid position on the map.
numberThe distance from the left of the canvas to the pointer position in pixels.
numberThe distance from the top of the canvas to the pointer position in pixels.
An object to describe the event fired when the map view changes.
The new view state after the change.
The reason the view changed.