Map Events
The event system is the used if you want to listen to any user interactions or state changes on the map.
Basic Usage
To listen to map events, implement a callback function for the onEvent
parameter.
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Events')),
body: MapLibreMap(
options: MapOptions(center: Position(9.17, 47.68)),
onEvent: _onEvent,
),
);
}
void _onEvent(event) {
print(event.runtimeType);
// check for the event type
if (event is MapEventClicked) {
print('The map has been clicked at ${event.point.lng}, ${event.point.lat}');
}
// or use a switch statement to listen to all the events you are interested in
switch (event) {
case MapEventMapCreated():
print('map created');
case MapEventStyleLoaded():
print('style loaded');
default:
// ignore all other events
}
}
Available Events
Flutter | Web | Android | iOS | Windows | MacOS | Linux |
---|---|---|---|---|---|---|
MapEventMapCreated | ||||||
MapEventStyleLoaded | load | (OnDidFinishLoadingStyleListener) | ||||
MapEventClicked | click | OnMapClickListener | ||||
MapEventDoubleClicked | dblclick | |||||
MapEventSecondaryClicked | contextmenu | |||||
MapEventLongClicked | OnMapLongClickListener | |||||
MapEventIdle | idle | OnDidBecomeIdleListener | ||||
mousedown | ||||||
MapEventStartMoveCamera | OnCameraMoveStartedListener | |||||
MapEventMoveCamera | move | OnCameraMoveListener | ||||
MapEventCameraIdle | moveend | OnCameraMoveCanceledListener |