Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

javascript - Handle when drawing of polygons is complete in google maps api v3

It seems that drawing of polygons is asynchronous in google maps api v3. Try to click the "Load" button in this example:

http://jsfiddle.net/rmXXF/

the text "DONE" is written much sooner than the grid is drawn! It seems that drawing of rectangle grid is asynchronous. I want the text DONE displayed AFTER the grid is drawn! Is there some event handler for this?

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

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

Note that map 'idle' event doesn't work for this, because the map is not moving/zooming. You can try here: http://jsfiddle.net/92Hxj/

Maybe it has something to do not with google maps but with browser rendering? In any case, some event handler for this should be present.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

By triggering a small recentering of the map after drawing all the polygons this is added to the same internal google maps event queue as can be seen 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));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...