Flutter_map: mapGestureInteractionStarted mapGestureInteractionStopped callback

Created on 23 Mar 2019  路  3Comments  路  Source: fleaflet/flutter_map

Is there a way to get callbacks for mapGestureInteractionStarted and mapGestureInteractionStopped? onPositionChanged should give results in between these two callbacks. I am doing some heavy work after the mapPosition changes. But currently the only way to understand this is by too many small updates. This slows things a lot. I would like to know when the user takes his/her hands on/off the map ie stop pan/zoom and do the heavy work only after this. I am mainly working on clustering.

Optionally, is there another way to accomplish this by using debouncing? When the first onPositionChanged happens, mapGestureInteractionStarted state can be set, and after a certain time passes without any more onPositionChanged, mapGestureInteractionStopped state can be set. Is this good practice? This would also cover the cases when the user is still continuing to touch the map but does not move/zoom it. Like a pause gesture.

enhancement

Most helpful comment

Currently I'm using a throttling method to workaround the mapGestureInteractionStarted and mapGestureInteractionStopped.

Timer _timer;
bool _gestureStart = true;
void _restartTimer() {
  _gestureStart = false;
  _timer?.cancel();
  _timer = Timer(Duration(milliseconds: 100), () {
    _gestureStart = true;
    // mapGestureInteractionStopped callback here
  });
}

And on your FlutterMap onPositionChanged

onPositionChanged: (_) {
  if (_gestureStart) {
    // mapGestureInteractionStart callback here
  }
  _restartTimer(); 
}

All 3 comments

Currently I'm using a throttling method to workaround the mapGestureInteractionStarted and mapGestureInteractionStopped.

Timer _timer;
bool _gestureStart = true;
void _restartTimer() {
  _gestureStart = false;
  _timer?.cancel();
  _timer = Timer(Duration(milliseconds: 100), () {
    _gestureStart = true;
    // mapGestureInteractionStopped callback here
  });
}

And on your FlutterMap onPositionChanged

onPositionChanged: (_) {
  if (_gestureStart) {
    // mapGestureInteractionStart callback here
  }
  _restartTimer(); 
}

FlutterMapState uses the MapGestureMixin class that could emit events through MapState (in addition to calling move())

@johnpryan can you show a small snippet of code(could be pseudo) how we would access those events from our view controllers?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JonasVautherin picture JonasVautherin  路  4Comments

palicka picture palicka  路  4Comments

jasonleung101 picture jasonleung101  路  3Comments

garrrettt picture garrrettt  路  4Comments

EdHubbell picture EdHubbell  路  4Comments