Handle when polygon drawing is completed in google maps api v3

It seems that drawing polygons is asynchronous in google maps api v3 . Try clicking the download button in this example:

http://jsfiddle.net/rmXXF/

the text "DONE" is written much earlier than the grid is drawn! It seems that drawing a rectangular grid is asynchronous. I want DONE text to be displayed AFTER meshing! Is there any event handler for this?

The important part of the code is in the action() function:

 polygons = draw_all_squares(map); // draw grid here document.getElementById('status').innerHTML = 'DONE'; // displayed 2 seconds // before the grid! 

Note that the map idle event does not work for this, because the map does not move / scale. You can try here: http://jsfiddle.net/92Hxj/

Maybe he has something to do not with Google maps, but with a browser? In any case, some event handler must be present for this.

+7
source share
2 answers

By starting a small re-placement of the map after drawing all the polygons, this is added to the same internal google maps event queue, as shown in this example: http://jsfiddle.net/rmXXF/40/

 google.maps.event.addListener(map, 'idle', function() { document.getElementById('status').innerHTML = 'DONE'; }); 

and

 my_map.setCenter(new google.maps.LatLng(my_map.getCenter().lat(), my_map.getCenter().lng() + .000000001)); 
+8
source

You must use the overlay and listen to the drawing manager's "rectanglecomplete" event. I can make an example after lunch.

David is right. I read the documentation incorrectly. Apologize. He must receive a reward.

+3
source

All Articles