javascript - The Hidden markers show in cluster icon in google map api v3 - Stack Overflow

I used google map api in my project with cluster (MarkerClusterer)var markers=[];for(var i=0;i<1000

I used google map api in my project with cluster (MarkerClusterer)

var markers=[];
for(var i=0;i<1000;i++)
{ //create marker
    markers.push(marker):
}
 markerclusterer = new MarkerClusterer(map, markers);
// then .. in another part .. i do .
for(var j=0;j<200;j++)
{
markers[j].setVisible(false);
}
markerclusterer.draw();

the problem ::

its hide the 200 markers but in cluster icon its still ..

i mean .. ( if i calculate the numbers shown in cluster icon =1000) . but actually 800 markes is visible and 200 are hidden.)

how to make the cluster icon =800 only. ..thnx

I used google map api in my project with cluster (MarkerClusterer)

var markers=[];
for(var i=0;i<1000;i++)
{ //create marker
    markers.push(marker):
}
 markerclusterer = new MarkerClusterer(map, markers);
// then .. in another part .. i do .
for(var j=0;j<200;j++)
{
markers[j].setVisible(false);
}
markerclusterer.draw();

the problem ::

its hide the 200 markers but in cluster icon its still ..

i mean .. ( if i calculate the numbers shown in cluster icon =1000) . but actually 800 markes is visible and 200 are hidden.)

how to make the cluster icon =800 only. ..thnx

Share asked Nov 9, 2012 at 20:50 IbrahimAsadIbrahimAsad 5161 gold badge5 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

when you finished your loop, add .repaint() method, so it will update counters. But the main thing is that you need to add/remove these shown/hidden markers from the markerclusterer object automatically on hide/show marker

var markers=[], markerclusterer;

markerclusterer = new MarkerClusterer(map, []);

for(var i=0;i<1000;i++)
{ 
    //create marker
    markerclusterer.addMarker(marker, true);

    google.maps.event.addListener(marker, 'visible_changed', function(){
        if ( marker.getVisible() ) {
            markerclusterer.addMarker(marker, true);
        } else {
            markerclusterer.removeMarker(marker, true);
        }                   
    });
}
// then .. in another part .. i do .
for(var j=0;j<200;j++)
{
    markers[j].setVisible(false);
}
markerclusterer.repaint();

Hope that will help somebody.

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信