Skip to content

Commit 6d25519

Browse files
feat: add MapOptions.onPointerMove callback (#2137)
Co-authored-by: Luka S <[email protected]>
1 parent 9e6b1e3 commit 6d25519

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/src/gestures/map_interactive_viewer.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>
420420
}
421421

422422
void _onPointerMove(PointerMoveEvent event) {
423+
if (_options.onPointerMove != null) {
424+
final latLng = _camera.offsetToCrs(event.localPosition);
425+
_options.onPointerMove!(event, latLng);
426+
}
423427
if (!_ckrTriggered.value) return;
424428

425429
final baseSetNorth =

lib/src/map/options/options.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ typedef PointerHoverCallback = void Function(
4040
LatLng point,
4141
);
4242

43+
/// Callback to notify when the map registers a pointer move event.
44+
typedef PointerMoveCallback = void Function(
45+
PointerMoveEvent event,
46+
LatLng point,
47+
);
48+
4349
/// Callback that gets called when the viewport of the map changes.
4450
///
4551
/// {@macro map_position.has_gesture}
@@ -109,6 +115,16 @@ class MapOptions {
109115
/// down (e.g. mouse pointers, but not most touch pointers)
110116
final PointerHoverCallback? onPointerHover;
111117

118+
/// Called when a pointer is down and moves.
119+
///
120+
/// If used while dragging the map, this may emit the same point as by
121+
/// [onPositionChanged], but might not due to map pixel snapping or a slight
122+
/// delay, or any other disconnect between the pointer and map camera.
123+
///
124+
/// Prefer using [onPositionChanged], unless this is specifically required,
125+
/// such as obtaining the pointer position while the map camera is 'locked'.
126+
final PointerMoveCallback? onPointerMove;
127+
112128
/// This callback fires when the [MapCamera] data has changed. This gets
113129
/// called if the zoom level, or map center changes.
114130
final PositionCallback? onPositionChanged;
@@ -158,6 +174,7 @@ class MapOptions {
158174
this.onPointerUp,
159175
this.onPointerCancel,
160176
this.onPointerHover,
177+
this.onPointerMove,
161178
this.onPositionChanged,
162179
this.onMapEvent,
163180
this.onMapReady,

0 commit comments

Comments
 (0)