在google maps api v3中完成多边形绘图时的处理 [英] Handle when drawing of polygons is complete in google maps api v3

查看:141
本文介绍了在google maps api v3中完成多边形绘图时的处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎在 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/

文本DONE的写入时间早于绘制网格!看起来矩形网格的绘制是异步的。 我想要在绘制网格后显示文本DONE!是否有一些事件处理程序?

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?

代码的重要部分在于功能 action()

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! 

请注意,地图空闲事件不适用于此,因为地图不移动/缩放。您可以在这里尝试:
http://jsfiddle.net/92Hxj/

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.

推荐答案

在绘制所有多边形被添加到同一内部的Google Maps事件队列中,可以在此示例中看到: http://jsfiddle.net/rmXXF/40 /

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';
});

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

这篇关于在google maps api v3中完成多边形绘图时的处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆