Hacker News new | ask | show | jobs
by jdmichal 3928 days ago
Option one: Use the built-in `idle` event on the top-level map object. This basically does all the debouncing for you, though I don't remember off the top of my head whether this event happens before or after the `tilesloaded` event. The distinction would only be important if you want to wait for the map to visually update before displaying the results.

Option two: I think for your use case just listening on the single `bounds_changed` event will do what you want. That should trigger for all types of map movement or zooming. For the callback, use a closure which clears and sets a timeout event with the desired debounce time; no need to overcomplicate it. Then it's just tuning the delay until it hits that sweet spot between firing too often and obvious visual delays.