javascript - Updating markerclusters - Stack Overflow

I have a google map set up with markers supplied via a JSON feed. Since there are a large number of mar

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.

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.

Share Improve this question asked May 17, 2011 at 14:42 Donny HammellDonny Hammell 1052 silver badges8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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.

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744095296a4557832.html

相关推荐

  • javascript - Updating markerclusters - Stack Overflow

    I have a google map set up with markers supplied via a JSON feed. Since there are a large number of mar

    9天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信