标记完成加载后是不是有回调?
Posted
技术标签:
【中文标题】标记完成加载后是不是有回调?【英文标题】:Is there a callback for markers when they finished to load?标记完成加载后是否有回调? 【发布时间】:2019-12-18 19:22:09 【问题描述】:我在任何地方都找不到,无论是在文档中,当标记完成加载到地图上时的回调。
【问题讨论】:
MarkerClustererPlus 公开了一个clusteringend
事件。
@MrUpsidown 我没有使用加号,我发布的技巧也适用于单个标记/圆圈和集群
我只是建议这个库,因为它公开了您正在使用的事件没有... 其他功能应该是一样的。
我很欣赏否决票,可能解释为什么会有很大帮助。只是为了澄清,我提出这个问题是为了提供我自己的答案。根据我的要求,没有其他方法,除非您知道并提供答案。
【参考方案1】:
我在文档上找不到任何其他方式或关于如何解决“当所有标记都加载到谷歌地图中时的回调或事件”的答案,所以我想分享我使用的这个技巧:
创建加载器
设置你想要的缩放,gmap 会认为你移动了它
var map = new google.maps.Map(document.getElementById('map'),
center: lat: 40.600486, lng: 9.261252,
zoomControl: true,
zoom: 8,
...draw your pins and then set them normally in the map
markerClusterer = new MarkerClusterer(map, markers, mcOptions);
...now fake a zoom
google.maps.event.addListenerOnce(map,
'zoom_changed',
function(event)
console.log("All your markers are loaded");
// remove the loader
);
map.setZoom(8);
【讨论】:
以上是关于标记完成加载后是不是有回调?的主要内容,如果未能解决你的问题,请参考以下文章
HTML5 new Image() 图像需要加载后才能drawImage? 怎样保证多个Image对象都加载完成?