Make sure the GoogleMap canvas element is already free

My question is pretty straight forward.

google.maps.event.addListenerOnce(map, 'idle', function() { // code }); 

This piece of code starts after the map is currently busy zooming or panning. Not when it is already idle.

Is there a way to check the status of the canvas in an if statement? So, when it is already idle, will you make // code without adding a listener?

+6
source share
1 answer

There is no documented property that signals the card's idle status, but you can implement it yourself.

Assuming you invoke this right after the card is initialized:

 google.maps.event.addListener (map, 'idle', function(){ this.lastBounds=this.getBounds(); }); 

Then you can check if the lastBounds property matches the current borders of the map:

 if (map.lastBounds==map.getBounds()){ //call function immediately }else{ //add listener } 
+4
source

All Articles