Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trigger event on scroll wheel #1182

Merged
merged 1 commit into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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