react-map-gl icon indicating copy to clipboard operation
react-map-gl copied to clipboard

is there a 'moveend' event handler like in Mapboxgl?

Open ZhenanH opened this issue 9 years ago • 10 comments

the current mapboxgl instance seems only register 'move' event.

ZhenanH avatar Feb 08 '17 16:02 ZhenanH

moveend behave the same as move, which is not correct

ZhenanH avatar Feb 08 '17 16:02 ZhenanH

Any solution to monitoring when the map is being dragged? Setting onLoad on InteractiveMap to register the event listeners move and moveend causes them to be fired at the same time so moveend is not useful to know when someone stopped dragging.

const onLoad = event => {
  event.target.on('move', () => console.log('moving'));
  event.target.on('moveend', () => console.log('stop'));
}

bstaats avatar Oct 31 '17 17:10 bstaats

Based on mapbox examples https://www.mapbox.com/mapbox-gl-js/example/filter-features-within-map-view/ moveend is working fine. Is there workaround yet?

ilionic avatar Nov 14 '18 11:11 ilionic

4.0.0's onViewportChange callback is invoked with a second argument including the following flags:

  • inTransition
  • isDragging
  • isPanning
  • isRotating
  • isZooming

Pessimistress avatar Nov 14 '18 19:11 Pessimistress

Thanks, it's solving the issue partially. I'd prefer to have explicit moveend / dragend indicating user interaction. ( usecase - fitBounds VS user interaction - both triggering onViewportChange but need different logic for every case ) At the moment partially solved it with custom rxjs debouncing.

ilionic avatar Nov 15 '18 05:11 ilionic

@ilionic would you kindly share your solution of that rxjs debouncing?

I like to make a final call the API once I know at least there is a 1sec silence.

layik avatar Dec 13 '18 12:12 layik

@layik using redux, just dispatching action (i.e. UPDATE_VIEWPORT) from React component with mapbox instance ( _updateViewport) with redux-observable epics and rxjs6 it looks something like:

export const updateViewportEpic = (action$: Observable<Action>) =>
  action$.pipe(
    ofType('UPDATE_VIEWPORT'),
    debounceTime(400),
    switchMap(({ payload }) => {
      // your logic here
      // ...

ilionic avatar Dec 13 '18 18:12 ilionic

This problem is still there. moveend behaves as move

saadsaifse avatar Apr 17 '20 10:04 saadsaifse

The moveend behavior can be simulated by listening to onInteractionStateChange.

Pessimistress avatar Apr 19 '20 02:04 Pessimistress

@Pessimistress that indeed did the job. Can confirm that this worked

onInteractionStateChange={(s) => {
  if (
    s.isDragging ||
    s.inTransition ||
    s.isRotating ||
    s.isZooming ||
    s.isHovering ||
    s.isPanning
  )
    return;
 // Perform your operation. In my case I update the URL.
  updateURL(state.viewport as ViewportProps);
}}

saadsaifse avatar Apr 20 '20 08:04 saadsaifse