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

onMoveStart onMoveEnd implementation #148

Closed
yostrokon opened this issue Oct 26, 2018 · 8 comments · Fixed by #719
Closed

onMoveStart onMoveEnd implementation #148

yostrokon opened this issue Oct 26, 2018 · 8 comments · Fixed by #719
Labels
feature This issue requests a new feature

Comments

@yostrokon
Copy link

yostrokon commented Oct 26, 2018

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.

@vinicentus
Copy link
Contributor

+1, I'd like to see this feature

@johnpryan johnpryan added the feature This issue requests a new feature label Nov 19, 2018
@GENL
Copy link

GENL commented Feb 9, 2019

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.

@SebastienAwali
Copy link

SebastienAwali commented Jul 1, 2019

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.

@dimitristaufer
Copy link

+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?

@aytunch
Copy link
Contributor

aytunch commented Oct 25, 2019

I did not understand exactly what John has suggested, but maybe you guys can help:
#252 (comment)

@nicowernli
Copy link

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.

@bashennekam
Copy link

bashennekam commented Apr 29, 2020

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;
      }
    )            
  )
);

@maRci002
Copy link
Contributor

maRci002 commented Aug 6, 2020

Check out: #719

There are a lot of issues which ask for onMoveStart / onMoveEnd callbacks, just listen to mapEventStream and filter these events (MapEventMoveStart / MapEventMoveEnd), however take care because Map may use fling animation if the velocity is high enough so the final location will be different from MapEventMoveEnd's targetLocation, so there are two options:

  • disable fling animation
  • filter MapEventFlingEnd and MapEventFlingNotStarted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue requests a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants