2013-07-19 78 views
0

我正在制作一个包含群集的地图,我想在其下显示群集列表。获取markerclusterer群集

为了获得簇,我试图从对象中检索它们。但是,如我所料不工作:

// Initialize clusterer 
    markerCluster = new MarkerClusterer(map, markers, clusterOptions); 

    // this logs an empty array 
    var clusters = markerCluster.clusters_; 
    console.log(clusters); 

    // This logs array of clusters 
    setTimeout(function(){ 
     var clusters = markerCluster.clusters_; 
     console.log(clusters); 
    }, 500) 

所以我试图找出是否有一个onload事件或回调函数..

+0

[Marker Clusterer Plus not working]的可能重复(http://stackoverflow.com/questions/17672295/marker-clusterer-plus-not-working) – geocodezip

回答

1

这取决于你所使用的集聚库,但基本上,MarkerClusterer类是OverlayView的扩展。

一旦实际添加了OverlayView,就会完成群集(OverlayView.onAdd方法)。

您得到的第一个日志为空,表示覆盖图尚未添加。据我所知,没有添加叠加的事件。

最好的解决方案是扩展MarkerCluster类,重载onAdd方法,发送一个事件,然后在相应的侦听器中添加标记。