简体   繁体   English

Google Maps API 3加载图标

[英]Google Maps API 3 loading icon

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. 我正在将google maps API 3与javascript结合使用,无法找到更多有关此的信息。

This event is now called "status_changed" per the API docs: https://developers.google.com/maps/documentation/javascript/reference#KmlLayer 根据API文档,此事件现在称为“ status_changed”: https : //developers.google.com/maps/documentation/javascript/reference#KmlLayer

It can be used like this: 可以这样使用:

google.maps.event.addListener(kmlLayer, 'status_changed', function () {
    if (kmlLayer.getStatus() == google.maps.KmlLayerStatus.OK) {
        // Success
    }
    else {
        // Failure
    }
});

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. 如果您正在使用KmlLayer对象加载标记,则可以将侦听器附加到事件metadata_changed ,该事件在KmlLayer加载所有信息后触发。

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(...) . 因此,您可以在初始化地图后立即显示自定义加载图标,然后使用new google.maps.KmlLayer(...)调用标记。 In the listener for metadata_changed you can remove the custom loading icon, or hide it from displaying. metadata_changed的侦听器中,您可以删除自定义加载图标,也可以使其不显示。 So when the KmlLayer finishes loading, then it'll run the code to remove your loading icon. 因此,当KmlLayer完成加载后,它将运行代码以删除您的加载图标。

You can attach listeners by going: 您可以通过以下方式附加侦听器:

google.maps.event.addListener(kmlLayerObject, 'metadata_changed', function () {
    ...
}

You could also "hide" the map canvas with a loading div and show it after initialization. 您也可以使用加载div“隐藏”地图画布,并在初始化后显示它。

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: 要注意的另一件事是,当地图在init上隐藏时,它的行为可能很奇怪,可以通过“调整”地图的大小来解决:

http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/251f20b769d116ea/ba3ca54f5e1352a2 http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/251f20b769d116ea/ba3ca54f5e1352a2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM