我正在使用fluster 2来聚类标记,并发现fluster聚类方法过于激进。因此,即使我放大到城市级别,我仍然最终拥有比我真正想要的更多的集群。有没有人知道如何修改fluster .js,一旦你说缩放等级5,它就会显示所有标记?
这里有一些与fluster相关的代码太多,所以这个问题更适合已经使用fluster来满足其标记聚类需求的人。
谢谢,
答案 0 :(得分:0)
您可以在地图的缩放级别上创建一个侦听器,然后控制群集。这可能是你的代码看起来像什么的一个例子。我没有测试过代码,我从中获取代码的补充教程是here。
var fluster = new Fluster2(map);
// Set styles for the clustered icons
fluster.styles = {
0: {
image: "http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m1.png",
textColor: "#FFFFFF",
width: 53,
height: 52
},
10: {
image: "http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m2.png",
textColor: "#FFFFFF",
width: 56,
height: 55
},
15: {
image: "http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m3.png",
textColor: "#FFFFFF",
width: 66,
height: 65
}
};
// Initialize Fluster
// This will set event handlers on the map and calculate clusters the first time.
fluster.initialize();
// Event listener for switching to Street View/Road Map to show/hide the
// close button, respectively
google.maps.event.addListener(panorama,"visible_changed",toggleVisible);
// Add a listener to the zoom change event so we can change the grid size
// of the cluster script. Should be dynamic!
google.maps.event.addListener(map, "zoom_changed", function() {
var zoomLevel = map.getZoom();
switch(true){
case zoomLevel > 13:
fluster.gridSize = 0;
break;
case zoomLevel > 12:
fluster.gridSize = 10;
break;
case zoomLevel > 7:
fluster.gridSize = 20;
break;
case zoomLevel > 5:
fluster.gridSize = 40;
break;
default:
fluster.gridSize = 60;
break;
}
});
答案 1 :(得分:0)
好的答案Zied。
顺便说一句,如果您有多个具有相同位置的标记,即使gridSize为0,仍会发生聚类。 为了解决这个问题,将网格设置为-1
google.maps.event.addListener(map, "zoom_changed", function() {
var zoomLevel = map.getZoom();
switch(true){
case zoomLevel > 13:
fluster.gridSize = -1;
break;
case zoomLevel > 12:
fluster.gridSize = 10;
break;
case zoomLevel > 7:
fluster.gridSize = 20;
break;
case zoomLevel > 5:
fluster.gridSize = 40;
break;
default:
fluster.gridSize = 60;
break;
}
});