how to detect dragging?

283 views
Skip to first unread message

M. Dietrich

unread,
Jul 15, 2015, 6:59:18 PM7/15/15
to mapsfo...@googlegroups.com
i tried MapViewPosition.addObserver and FrameBufferModel.addObserver to detect if the user is dragging the map. but if program itself sets the map center these methods fire as well. how can i simply detect if the program moved the map or is the user moved it?

Emux

unread,
Jul 16, 2015, 2:44:34 AM7/16/15
to mapsfo...@googlegroups.com
That's platform (Android / Java) relevant.

The map position observer is about changes in location / zoom, as they're propagated from all sources.

For gesture listening, in Android you could play with touch gesture detector in map view.

--
Emux
Cruiser - Atlas

Andy Greaves

unread,
Jul 16, 2015, 5:20:01 AM7/16/15
to mapsfo...@googlegroups.com
I recently implemented this using a Gesture Detector. Note in my implementation I only needed to know when the user lifts their finger following a drag gesture. 


Extend SimpleOnDrawGestureListener and override the onScroll method:

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
scrolling = true;
return super.onScroll(e1, e2, distanceX, distanceY);

}

In the onTouch method of the MapView see if the scroll variable is true when the event s MotionEvent.ACTION_UP is called. If it is then the user has touched the map, moved their finger and released the map. If you want to be notified during the drag operation implement a callback in the onScroll method. 


this.mapView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}

if (event.getAction() == MotionEvent.ACTION_UP) {
if (gestureLis.scrolling) {
gestureLis.scrolling = false;

}
}
return false;
}
});




Andy

Emux

unread,
Jul 16, 2015, 5:26:34 AM7/16/15
to mapsfo...@googlegroups.com
You could even use the provided mapView.setGestureDetector method for that.

Reply all
Reply to author
Forward
0 new messages