onMoveStart onMoveEnd implementation
Hello again, There are two map event leaflet js on the map - onMoveStart and onMoveEnd. Because i'm using big DB - about two dozen M markers i use them in them web client to get an initial bounds and zoom before drag and at the end to call backend and get lists with the markers that have to stay, be removed from the memory or add to the new screen. Is there a chance to have these events "from the box" with callback at the map that of course to be corresponded with the mapcontroller for zoom and move or should be better to implement workaround monkey job wrap with gesturedetector using onDrag events?
have some relation to https://github.com/apptreesoftware/flutter_map/issues/138 but move and zoom are required too.
+1, I'd like to see this feature
I need something like that too. I want to fetch some data from the server according to the map position every time the map stop moving.
I know the issue has been open for a while, yet I allow myself to post my onMoveEnd workaround here, hoping to save time for the ones having a similar problem in the future :)
So in my case I'm using Timer to detect when the position hasn't changed for a while.
First, I create a variable to store my Timer:
Timer _mapMovementTimer;
Then, within the onPositionChanged callback:
onPositionChanged: (MapPosition position, bool hasGesture, bool fromUser) {
if(_mapMovementTimer != null)
_mapMovementTimer.cancel();
_mapMovementTimer = Timer(Duration(milliseconds: 750), () {
// Here, the map didn't moved for 750ms
BlocProvider.of<PointsBloc>(context).requestPointsInZone(position.bounds);
});
},
The counter is canceled and restarted each time the user pan or zoom the map. If onPositionChanged callback is not called for 750ms (if the map didn't moved), then I request my points in the given zone. You can change the Duration of the Timer to have a quicker/slower reaction.
+1
Just stumbled upon this and it's exactly what I need.
Any chance a onPositionChangeStopped callback could be added in the next public release?
I did not understand exactly what John has suggested, but maybe you guys can help: https://github.com/johnpryan/flutter_map/issues/252#issuecomment-493557510
I know the issue has been open for a while, yet I allow myself to post my onMoveEnd workaround here, hoping to save time for the ones having a similar problem in the future :)
So in my case I'm using Timer to detect when the position hasn't changed for a while.
First, I create a variable to store my Timer:
Timer _mapMovementTimer;Then, within the onPositionChanged callback:
onPositionChanged: (MapPosition position, bool hasGesture, bool fromUser) { if(_mapMovementTimer != null) _mapMovementTimer.cancel(); _mapMovementTimer = Timer(Duration(milliseconds: 750), () { // Here, the map didn't moved for 750ms BlocProvider.of<PointsBloc>(context).requestPointsInZone(position.bounds); }); },The counter is canceled and restarted each time the user pan or zoom the map. If onPositionChanged callback is not called for 750ms (if the map didn't moved), then I request my points in the given zone. You can change the Duration of the Timer to have a quicker/slower reaction.
The problem with this solution comes when you want to center the map again and the user is still touching the screen but not moving the map.
I ended up using the following workaround, maybe it works for you as well:
var mapPointers = 0;
var mapPosition;
var mapWidget = Listener(
onPointerDown: (details) {
if (mapPointers == 0) // onMoveStart
mapPointers++;
},
onPointerUp: (details) {
mapPointers--;
if (mapPointers == 0) // onMoveEnd
},
behavior: HitTestBehavior.deferToChild,
child: FlutterMap(
options: new MapOptions(
onPositionChanged: (position, gesture) {
mapPosition = position;
}
)
)
);
Check out: #719
There are a lot of issues which ask for
onMoveStart/onMoveEnd callbacks, just listen tomapEventStreamand filter these events (MapEventMoveStart/MapEventMoveEnd), however take care becauseMap may use fling animationif the velocity is high enough so the final location will be different fromMapEventMoveEnd's targetLocation, so there are two options:
- disable fling animation
- filter
MapEventFlingEndandMapEventFlingNotStarted