2011-01-26 36 views

回答

2

由于缺乏任何其他的答案,我做了自己MarkerClusterer的延伸,我敢肯定,它可以被改写为更好的标准,但是这是我能想出:

MarkerClusterer.prototype.AddCluster = function(clat, clng, csize) 
{ 
    var clusterlocation = new google.maps.LatLng(clat, clng) 
    var CI = new ClusterIcon(new Cluster(this), this.getStyles, this.getGridSize()); 
    var index = 0; 
    var dv = csize; 
    while (dv !== 0) { 
    dv = parseInt(dv/10, 10); 
    index++; 
    } 
    var style = this.styles_[index-1]; 
    CI.setCenter(clusterlocation); 
    $.extend(CI, {sums_ : {text : csize, index: index}, url_ : style['url'], width_ : style['width'], height_ : style['height']}); 
    CI.setMap(this.map_); 
    CI.show(); 
    CI.triggerClusterClick = function() 
    {this.map_.setCenter(clusterlocation); 
    this.map_.setZoom(this.map_.getZoom()+1); } 
} 
0

如果我得到这个权利,你可以使用zoom_changed() event of google map object和即当map.getZoom()==16maxNumberOfFetchedPlaces发送您的JSON请求参数,以便您的服务器能够返回results.Since的数量有限markerClusterer初始化就像
var markerClusterer = new MarkerClusterer(map, fetchedPlacesArray);你将没有问题。

干杯

+0

是啊,这有MarkerClusterer手动处理我的标记的功能,但如果我在我的分贝10.000标志,这是waaaaaay到costy到通过网络发送的数据,更不用说已经MarkerClusterer使所有的计算,所以我想知道如何添加一个ClusterMarker,以便我(服务器端)可以进行一些计算,并通过线路发送没有markerdetails的集群标记,指示存在ie。该群集中有1532个标记。顺便说一句。 bounds_changed比zoom_changed更好,因为它在移动地图时获得。 – Jakob 2011-01-27 11:42:58

1

我改编了@ Jakob的Google Maps API V3代码。 希望能帮助别人。

 
MarkerClusterer.prototype.A 

    ddCluster = function(clat, clng, csize) 
    { 
     this.setZoomOnClick(false); 
     if (typeof this.aAddClusterIcons == "undefined"){ 
      this.aAddClusterIcons = []; 
     } 

     this.activeMap_ = this.getMap(); 
     var clusterlocation = new google.maps.LatLng(clat, clng) 
     var CI = new ClusterIcon(new Cluster(this), this.getStyles, this.getGridSize()); 
     var index = 0; 
     var dv = csize; 
     while (dv !== 0) { 
      dv = parseInt(dv/10, 10); 
      index++; 
     } 
     var style = this.styles_[index-1]; 
     $.extend(CI, {sums_ : {text : csize, index: index}, url_ : style['url'], width_ : style['width'], height_ : style['height'], anchorIcon_: [clat, clng]}); 
     CI.setCenter(clusterlocation); 
     CI.setMap(this.activeMap_); 
     CI.show(); 

     this.aAddClusterIcons.push(CI); 
    } 
    MarkerClusterer.prototype.RemoveClusters = function(clat, clng, csize) 
    { 
     if (typeof this.aAddClusterIcons == "undefined"){ 
      this.aAddClusterIcons = []; 
     } 

     $.each(this.aAddClusterIcons, function(iIndex, oObj){ 
      oObj.onRemove(); 
     }); 
     this.aAddClusterIcons = []; 
    } 

相关问题