Hacker News new | ask | show | jobs
by jdmichal 3930 days ago
> We took a conscious decision disabling the scrolling wheel as zoom in/out because otherwise it would have triggered too many "refine searches".

Tip: Any operation that's reliant on mouse events should be throttled or debounced -- they are just too noisy. For mapping, I have done debounces as long as two seconds without the delay being obvious. I suspect due to the style of user interaction in combination with the loading animations from the map itself.

1 comments

really appreciated - it's somewhat debounced already, but it seems to be not quite right... I'd be curious to hear about how you went about debouncing (what time delays on which specific actions, zoom, moving the map)
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.