Map idle event
See original GitHub issueI’m posting this partly for confirmation that I’ve done it right and partly in case anyone else may need it in future or even if it is something that could/should be added to leaflet.
I was having trouble with moveend
or dragend zoomend
calling the results function too soon which prevented the user from being able to do more than a single move (drag or zoom) at once (unless they were quick) before it would want to run the function so, taking inspiration from google maps, I’ve tried to replicate the idea of the idle
event. Rather than run the function directly on moveend
or dragend zoomend
it allows me to wait for user interaction to stop (500ms since last movement in this case) before running the function.
// declare timeout function name
var timeoutHandler;
...
// initialize map as normal
var map = L.map('map_canvas', {
...
});
// add event listener to map for movement
map.on('zoomend dragend', mapMoveHandler);
map.on('idle', mapIdleHandler);
...
function mapMoveHandler() {
// cancel any timeout currently running
window.clearTimeout(timeoutHandler);
// create new timeout to fire idle event after 500ms (or whatever you like)
timeoutHandler = window.setTimeout(function() {
map.fire('idle');
}, 500);
}
...
function mapIdleHandler() {
// run some function when map idle to get results or update markers or something
...
}
Issue Analytics
- State:
- Created 9 years ago
- Reactions:3
- Comments:41 (5 by maintainers)
Top Results From Across the Web
Events | Maps JavaScript API - Google Developers
Each Maps JavaScript API object exports a number of named events. Programs interested in certain events will register JavaScript event listeners for those ......
Read more >idle event on Google-maps with jQuery - Stack Overflow
For others having this issue: You can get the map object/variable like this: $('#map_canvas').gmap(); var map = $('#map_canvas').gmap('get', 'map');.
Read more >Add Idle Event Listener on Maps - techstrikers.com
In this example you will learn how to add Idle Event Listener to google map. This event fires when the map becomes idle...
Read more >Must wait for 'idle' event on map before calling ... - GitHub
I've this error code : "uncaught exception: Must wait for 'idle' event on map before calling markersNearAnyOtherMarker". I don't understand the ...
Read more >"idle" event fires too soon - Google Groups
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
with lodash.js, this is an exact replacement:
@GertS I found that for best results I had to cover all possible drag (and zoom in my case) listeners
dragstart drag dragend zoomstart zoomanim zoomend
for mymapMoveHandler
function.