Skip to content

Commit

Permalink
Trigger event on scroll wheel (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
a14n authored Mar 20, 2022
1 parent fb5a3e0 commit 17c1298
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/src/gestures/gestures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ abstract class MapGestureMixin extends State<FlutterMap>
: max(mapState.options.minZoom ?? 0, mapState.zoom + delta);
final newZoom = mapState.fitZoomToBounds(zoom);
// Move the map to the new zoom level
mapState.move(mapState.center, newZoom, source: MapEventSource.custom);
mapState.move(mapState.center, newZoom,
source: MapEventSource.scrollWheel);
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion lib/src/gestures/map_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ enum MapEventSource {
interactiveFlagsChanged,
fitBounds,
initialization,
custom
custom,
scrollWheel,
}

/// Base event class which is emitted by MapController instance, the event
Expand Down Expand Up @@ -183,6 +184,23 @@ class MapEventDoubleTapZoom extends MapEventWithMove {
);
}

/// Event which is fired when scroll wheel is used to zoom
class MapEventScrollWheelZoom extends MapEventWithMove {
MapEventScrollWheelZoom({
required LatLng targetCenter,
required double targetZoom,
required MapEventSource source,
required LatLng center,
required double zoom,
}) : super(
targetCenter: targetCenter,
targetZoom: targetZoom,
source: source,
center: center,
zoom: zoom,
);
}

/// Event which is fired when animation for double tap gesture is started
class MapEventDoubleTapZoomStart extends MapEvent {
MapEventDoubleTapZoomStart(
Expand Down
10 changes: 10 additions & 0 deletions lib/src/map/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ class MapState {
source: source,
),
);
} else if (source == MapEventSource.scrollWheel) {
emitMapEvent(
MapEventScrollWheelZoom(
center: _lastCenter!,
zoom: _zoom,
targetCenter: targetCenter,
targetZoom: targetZoom,
source: source,
),
);
} else if (source == MapEventSource.onDrag ||
source == MapEventSource.onMultiFinger) {
emitMapEvent(
Expand Down

0 comments on commit 17c1298

Please sign in to comment.