You should check how the debounce function works. A good article by Taylor Keyes defines this as follows:
This function is designed to limit the number of function calls: scroll events, mouse events, and keystroke events - these are all great examples of events we might want to capture, but it can be quite complicated if we collect them every time they shoot
So, you define a function somewhere in your code:
function debounce(fn, time) { let timeout; return function() { const args = arguments; const functionCall = () => fn.apply(this, args); clearTimeout(timeout); timeout = setTimeout(functionCall, time); } }
Then you just use this function when adding a listener:
google.maps.event.addListener(myMap, 'bounds_changed', debounce(() => { }, 250));
250 ms seems to be a good frequency to use here.
Mau Muñoz Mar 22 '18 at 1:33 2018-03-22 01:33
source share