隐藏 Google Maps v3 地图,在需要时显示 [英] Keep a Google Maps v3 Map hidden, show when needed

查看:15
本文介绍了隐藏 Google Maps v3 地图,在需要时显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从一开始就阻止显示 Google Maps (JS, v3) 地图?我正在做一些预处理,并想显示我的加载"微调器,直到一切顺利(更雄辩地放置,隐藏地图 - 例如容器 div - 直到所有预处理完成——此时,显示地图).

连接地图的 idle 事件并没有多大帮助,因为在此事件发生时地图已经显示了.

我知道容器 div 在加载后被 GMaps 设置为内联样式,我的第一个想法是清除 style 属性(同时监听 idle 事件),但看看是否有一种方法可以创建地图并且在所有预处理完成之前不显示它.

也许通过使用 new google.maps.Map 构造函数的参数,或 MapOption ?

对此有什么想法吗?

先谢谢你!

解决方案

另外记得拨打:

google.maps.event.trigger(map, 'resize');

如果您更改了

的大小.display:none

没有大小.

Is there a way of preventing a Google Maps (JS, v3) map being displayed from the get-go? I'm doing some pre-processing and would like to show my 'Loading' spinner until everything is good to go (more eloquently put, hide the map -- e.g. the container div – until all pre-processing is complete – at which point, show the map).

Hooking up the map's idle event doesn't help that much, since the map is already displayed when this event hits.

I know that the container div gets inline-styled by GMaps after loading, my first idea was to clear out the style attribute (whilst listening to the idle event), but it would be interesting to see if there is a way of creating the map and not displaying it until all pre-processing is done.

Maybe by using an argument to the new google.maps.Map constructor, or a MapOption ?

Any thoughts on this?

Thank you in advance!

解决方案

Also remember to call:

google.maps.event.trigger(map, 'resize');

if you have changed the size of the <div>. A display:none <div> has no size.

这篇关于隐藏 Google Maps v3 地图,在需要时显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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