使用gmaps4rails更新群集图标的最佳方法是什么

时间:2012-08-07 20:05:58

标签: google-maps-api-3 gmaps4rails markerclusterer

我是gmaps4rails gem的忠实粉丝,它一直运作良好且非常灵活。

但是,我似乎无法轻松清除和更新Cluster标记,而且我在Stackoverflow上找不到使用此gem的类似解决方案。

在我的javascript中,我使用以下方法过滤掉可见标记。但是Gmaps.map.clearClusterer似乎没有响应click事件。我能够正确显示和隐藏标记,但无法清除群集标记,也无法使用新编号更新群集标记。我该怎么办?

  var VisibleMarker=function(){
    var filtered=_.filter(Gmaps.map.markers,function(marker){   
       return marker.building_type == SELECT;
     }); //end of _.filter
    return filtered
  }//end of VisibleMarker

  var applyFilters=function(){
    var VisibleArray=VisibleMarker()
    _.each(Gmaps.map.markers,function(marker){
         Gmaps.map.hideMarker(marker)
     })
        Gmaps.map.clearClusterer()
    _.each(VisibleArray,function(marker){
         Gmaps.map.showMarker(marker)
     }) 
        Gmaps.map.createClusterer(VisibleArray)

   };//end of applyFilters

更新:

如何正确调用MarkerClusterer类中的addMarkers()方法? http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/reference.html

我用过这一行:

  

Gmaps.map.addMarkers(VisibleArray)

但它改为调用此函数:

Gmaps4Rails.prototype.addMarkers = function(new_markers) {
this.markers = this.markers.concat(new_markers);
this.create_markers();
return this.adjustMapToBounds();
}; 

0 个答案:

没有答案