Events
Every map module has one events object for both what users do on its features and what happens to the module itself. Map style changes and raw MapLibre events have their own hooks.
| You want to react to | Use | Guide |
|---|---|---|
| A click, right click, hover or long hover on a place, route, traffic incident or your own data | module.events.on('click', …) |
User interaction events |
| A click or hover on the rest of the map | BaseMapModule events |
Handling events on the rest of the map |
| Selecting or highlighting a feature from your own UI | setEventState, getEventStates |
Event states |
| A module's configuration changing, to keep your UI in sync | module.events.on('config-change', …) |
Module lifecycle events |
New data drawn by a module's show |
module.events.on('shown-features', …) |
Module lifecycle events |
| A map style switch, to keep your own layers or a dark-mode class | map.addStyleChangeHandler(…) |
Listening to style changes |
Map lifecycle such as load, moveend or zoom |
map.mapLibreMap.on(…) |
MapLibre Map events |
For anything a module draws, prefer the module's events over a raw MapLibre listener: only the top-most feature receives the event, the cursor has one state, and handlers get your original typed data. About MapLibre explains when the raw listener is the right tool.