手工绘制markerclusterer集群的地图V3
问题描述:
嘿,我使用谷歌地图的流行markerclusterer插件,可以在http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js手工绘制markerclusterer集群的地图V3
找到我想知道我可以使用哪些功能,手动添加clustermarker,因为我希望当我缩小很多时,在通过电线发送大量JSON之前,将标记集群在服务器端。
调用什么函数来添加聚类标记?
任何帮助深表感谢
答
由于缺乏任何其他的答案,我做了自己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); }
}
答
如果我得到这个权利,你可以使用zoom_changed() event of google map object和即当map.getZoom()==16
与maxNumberOfFetchedPlaces发送您的JSON请求参数,以便您的服务器能够返回results.Since的数量有限markerClusterer初始化就像var markerClusterer = new MarkerClusterer(map, fetchedPlacesArray);
你将没有问题。
干杯
答
我改编了@ 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 = []; }
是啊,这有MarkerClusterer手动处理我的标记的功能,但如果我在我的分贝10.000标志,这是waaaaaay到costy到通过网络发送的数据,更不用说已经MarkerClusterer使所有的计算,所以我想知道如何添加一个ClusterMarker,以便我(服务器端)可以进行一些计算,并通过线路发送没有markerdetails的集群标记,指示存在ie。该群集中有1532个标记。顺便说一句。 bounds_changed比zoom_changed更好,因为它在移动地图时获得。 – Jakob 2011-01-27 11:42:58