React-map-gl: Listening to the 'idle' event

Created on 14 Jun 2019  路  4Comments  路  Source: visgl/react-map-gl

We've come across situations where want to perform some application logic once the map is done doing its thing.

We've tried using onInteractionStateChange and creating a shouldUpdateApp variable which checks if every interactionState properties are false.

<ReactMapGl
  ...
  onInteractionStateChange={(interactionState) => {
    const shouldUpateApp = Object.keys(interactionState).every((key) => !interactionState(key))
    if (shouldUpdateApp) {
      updateApp()
    }
  }}
/>

This works great except for _onWheel. Because _onWheel is considered an one-off event, our updateApp() gets called on each instance of wheel. This isn't ideal as we only care about the app being updated once we are idle.

Mapbox supports the 'idle' event.

It would be great if we could support the 'idle' event by passing in an onIdle prop similar to onLoad and onError.

enhancement

Most helpful comment

idle refers to both a change in the interaction state (managed by react-map-gl) and data loading/rendering (managed by mapbox-gl). I'm open to supporting it in the long term but it will be more complicated to implement and test.

All 4 comments

We can probably add a debounce to resetting isZooming on wheel events. That should solve your issue?

Debouncing would solve my issue!
However, that fix seems less appropriate than handling the behavior through the 'idle' event.
Is there a particular reason we want to avoid supporting the 'idle' event?

idle refers to both a change in the interaction state (managed by react-map-gl) and data loading/rendering (managed by mapbox-gl). I'm open to supporting it in the long term but it will be more complicated to implement and test.

The debounced state is published (4.1.8 and 5.0.4).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sicksid picture sicksid  路  3Comments

yangshun picture yangshun  路  4Comments

SethHamilton picture SethHamilton  路  3Comments

porteron picture porteron  路  5Comments

jenyeeiam picture jenyeeiam  路  4Comments