Search code examples
cesiumjs

How to get the last wheel event in Cesium?


I have a problem with wheel event. I want to fetch some data after scroll wheel, but when I do as below:

var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);

handler.setInputAction(function (e) {
    fetchData(e);
}, Cesium.ScreenSpaceEventType.WHEEL);

The result is that the fetchData function will be invoked several times. I want it just call one time after the last wheel event triggered, rather than send useless request in the wheeling process.

Any ideas?

Thanks.


Solution

  • How would you know when the "wheeling process" is finished? The native JS events come in realtime when the wheel is moving, and typically the wheel is used for scrolling or zooming with every notch on the wheel. What data are you trying to fetch based on wheel motions?

    Cesium's Camera class also has a moveEnd event that indicates when the camera has settled down into a new location. If you're trying to fetch new data as the result of a completed camera motion, this may be a better event to subscribe to.