Skip to content

Commit

Permalink
the zoom speed using the mouse wheel can be adjusted (#1289)
Browse files Browse the repository at this point in the history
* the zoom speed using the mouse wheel can be adjusted

* fixed formatting

Co-authored-by: Martin Böttcher <martin.boettcher@greenbytes.de>
  • Loading branch information
mboe and mboe authored Jun 28, 2022
1 parent 6bca06c commit bee620c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/flutter_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class MapOptions {
/// his mouse. This is supported on web and desktop, but might also work well
/// on Android. A [Listener] is used to capture the onPointerSignal events.
final bool enableScrollWheel;
final double scrollWheelVelocity;

final double? minZoom;
final double? maxZoom;
Expand Down Expand Up @@ -309,6 +310,7 @@ class MapOptions {
this.pinchMoveWinGestures =
MultiFingerGesture.pinchZoom | MultiFingerGesture.pinchMove,
this.enableScrollWheel = true,
this.scrollWheelVelocity = 0.005,
this.minZoom,
this.maxZoom,
this.interactiveFlags = InteractiveFlag.all,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/gestures/gestures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ abstract class MapGestureMixin extends State<FlutterMap>
// Calculate new zoom level
final minZoom = mapState.options.minZoom ?? 0.0;
final maxZoom = mapState.options.maxZoom ?? double.infinity;
final newZoom = (mapState.zoom + pointerSignal.scrollDelta.dy * -0.005)
final newZoom = (mapState.zoom -
pointerSignal.scrollDelta.dy *
mapState.options.scrollWheelVelocity)
.clamp(minZoom, maxZoom);
// Calculate offset of mouse cursor from viewport center
final List<dynamic> newCenterZoom = _getNewEventCenterZoomPosition(
Expand Down

0 comments on commit bee620c

Please sign in to comment.