更新标记簇

发布于 2024-11-07 23:18:55 字数 488 浏览 0 评论 0原文

我设置了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风追烟花雨 2024-11-14 23:18:55

为了更新集群,您应该首先调用 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 use redraw(); 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) or removeMarkers(markers, opt_nodraw) functions. From my experience these are expensive operations. Setting opt_nodraw function to true will force no redraw which will improve performace.

You can first delete a bunch of markers with opt_nodraw set to true and than resetViewport(); redraw(); later manually.

奈何桥上唱咆哮 2024-11-14 23:18:55

我遇到了同样的问题,从我可以看出正在阅读源代码......你不能。

我将后台中的所有项目缓存为单独的标记,在需要时过滤它们

    displayItems: function(infilter){
        this.markerCluster.clearMarkers();
        var matches = infilter.matches(this.markers);
        this.markerCluster.addMarkers(matches);

    }

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

    displayItems: function(infilter){
        this.markerCluster.clearMarkers();
        var matches = infilter.matches(this.markers);
        this.markerCluster.addMarkers(matches);

    }

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文