更新标记簇
我设置了一个 google 地图,其中包含通过 JSON feed 提供的标记。由于涉及大量标记(超过 600 个),我使用了 markclusterer v3 来加快速度。一切工作正常,直到我尝试更改通过选项按钮显示的标记。我将此功能分配给单选按钮:
function activities(markerarray,mapused,actType) {
for(i in markerarray) {
if(markerarray[i].activity[actType] == null) {
markerarray[i].setMap(null);
}
else {
markerarray[i].setMap(mapused);
}
}
return markerarray;
}
这将阻止标记在地图上显示,并且适用于实际的谷歌标记。但是我似乎无法找到如何更新页面加载时创建的集群。
I have a google map set up with markers supplied via a JSON feed. Since there are a large number of markers involved (over 600) I have used markerclusterer v3 to speed things up. Everything is working fine until I try to change the markers displayed via option buttons. I have this function assigned to radio buttons :
function activities(markerarray,mapused,actType) {
for(i in markerarray) {
if(markerarray[i].activity[actType] == null) {
markerarray[i].setMap(null);
}
else {
markerarray[i].setMap(mapused);
}
}
return markerarray;
}
This will stop the markers from displaying on the map and works fine for the actual google markers. However I don't seem to be able to find how to update the cluster which was created when the page loaded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了更新集群,您应该首先调用
resetViewport();
方法将其隐藏,而不是使用redraw();
方法重新计算集群。在标记上使用 setMap(null) 函数不会将其从标记集群中取消注册,要取消注册,您可以使用
removeMarkers(marker, opt_nodraw)
或removeMarkers(markers, opt_nodraw)
功能。根据我的经验,这些都是昂贵的操作。将 opt_nodraw 函数设置为 true 将强制不重绘,从而提高性能。您可以先删除一堆标记,将
opt_nodraw
设置为true
,然后resetViewport();
redraw();
稍后手动。In order to update a cluster you should first call
resetViewport();
method to hide it than useredraw();
method to recalculate clusters.Using a setMap(null) function on a marker won't unregister it from a markerClusterer, to unregister you can use
removeMarkers(marker, opt_nodraw)
orremoveMarkers(markers, opt_nodraw)
functions. From my experience these are expensive operations. Settingopt_nodraw
function totrue
will force no redraw which will improve performace.You can first delete a bunch of markers with
opt_nodraw
set totrue
and thanresetViewport();
redraw();
later manually.我遇到了同样的问题,从我可以看出正在阅读源代码......你不能。
我将后台中的所有项目缓存为单独的标记,在需要时过滤它们
this.markers 是我的标记缓存, this.markerCluster 是我的markerCluster 对象 - 两者都是全局的。
您无法直接编辑群集,但可以使用 addMarker/removeMarker 添加和删除标记到markerCluster 对象,这反过来会将它们从群集中删除并重新绘制。
I had the same problem and from what I could tell be reading the source code... you cant.
I cache all the items in the background as individual markers, filter them when required
this.markers is my cache of markers and this.markerCluster is my markerCluster object - both are global.
You cant directly edit a cluster but you can add and remove markers to to the markerCluster object using addMarker/removeMarker which in turn will remove them from a cluster and redraw it.