-
Hi, I wonder is exist in flutter_map package v. 0.13.1 some zoom change event listener? I try change line width size according to zoom size. How can I handle this? |
Beta Was this translation helpful? Give feedback.
Answered by
vnmiso
Sep 5, 2023
Replies: 1 comment
-
You can listen to map events and try to determine whether a zoom occurred there, until this functionality is implemened. class MyMap extends StatelessWidget {
// To be able to access the current zoom level at all times. Not strictly
// needed, you can omit this.
final _mapController = MapController();
@override
Widget build(BuildContext context) {
return FlutterMap(
options: MapOptions(onMapEvent: _handleMapEvent),
mapController: _mapController,
);
}
void _handleMapEvent(MapEvent event) {
double? oldZoom;
double? newZoom;
// event.targetZoom should be the same as _mapController.zoom
if (event is MapEventWithMove) {
oldZoom = event.zoom;
newZoom = event.targetZoom;
} else if (event is MapEventDoubleTapZoom) {
oldZoom = event.zoom;
newZoom = event.targetZoom;
}
// There is a case that I was not able to handle: you can zoom by double
// tapping and then dragging, but no events seem to be generated, so this
// code doesn't detect that.
// Other checks you might consider instead of the ones above:
// event.source == MapEventSource.scrollWheel
// event.source == MapEventSource.doubleTapZoomAnimationController
// Check whether a zoom event occurred and whether you want to handle it.
if (oldZoom != null && newZoom != null && oldZoom != newZoom) {
// ...
}
}
}
You can also attach the map event handler to a |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JaffaKetchup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can listen to map events and try to determine whether a zoom occurred there, until this functionality is implemened.
For example: