Google 地图 API 3 加载图标
有没有办法在地图加载标记时显示加载图标?我正在使用 google 地图 API 3 和 javascript,但找不到太多关于此的信息。
Is there a way to have a loading icon while the map is loading markers? I am using google maps API 3 with javascript and cant find much information on this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 API 文档,此事件现在称为“status_changed”:https://developers。 google.com/maps/documentation/javascript/reference#KmlLayer
它可以像这样使用:
This event is now called "status_changed" per the API docs: https://developers.google.com/maps/documentation/javascript/reference#KmlLayer
It can be used like this:
如果您使用 KmlLayer 对象加载标记,则可以将侦听器附加到事件
metadata_changed
,该事件在 KmlLayer 加载所有信息后触发。因此,您可以在初始化地图后立即显示自定义加载图标,然后使用
new google.maps.KmlLayer(...)
调用标记。在metadata_changed
的侦听器中,您可以删除自定义加载图标,或隐藏它以使其不显示。因此,当 KmlLayer 完成加载时,它将运行代码以删除加载图标。您可以通过以下方式附加侦听器:
If you're loading markers using a KmlLayer object, then you can attach a listener to the event
metadata_changed
which gets fired after the KmlLayer has loaded all the information.So you can have your custom loading icon display as soon as you initialize your map, then make the call for the markers using
new google.maps.KmlLayer(...)
. In the listener formetadata_changed
you can remove the custom loading icon, or hide it from displaying. So when the KmlLayer finishes loading, then it'll run the code to remove your loading icon.You can attach listeners by going:
您还可以使用加载 div“隐藏”地图画布并在初始化后显示它。
另一件需要注意的事情是,当地图在 init 中隐藏时,它可能会表现得很奇怪,可以通过“调整”地图大小来修复:
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/251f20b769d116ea/ba3ca54f5e1352a2
You could also "hide" the map canvas with a loading div and show it after initialization.
Another thing to be aware of is when the map is hidden on init, it may behave strangely that can be fixed by "resizing" the map:
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/251f20b769d116ea/ba3ca54f5e1352a2