我试图改变谷歌地图API标记集群的级别大小。默认情况下,标记小尺寸(蓝色图标/m1):2-9标记,中等大小(黄色图标/m2):10-100标记,大级别(红色图标/m3)大小: 101-250标记。(如果我错了,请纠正我)。
我希望更改级别大小小于默认值的值。我找到了另一条主题相同的帖子,但我仍然没有明白。
这是Google标记集群图标,我的意思是:
PS:我没有提到如何改变集群图标,我的意思是如何改变大小的值。例:我怎样才能改变标记的级别大小,这样它就会被聚成蓝色(m1)、黄色(m2)和红色(M3)?正如我前面提到的默认大小,对于m1,它包含2-9标记,我可以将大小值更改为2-5标记吗?
发布于 2017-06-04 19:30:02
您需要创建一个自定义Calculator
函数。从来源 (在Google文档中引用的版本中,确保使用您所使用的版本的文档进行验证,这是您没有提供的)。默认的calculator
函数:
/**
* The function for calculating the cluster icon image.
*
* @param {Array.<google.maps.Marker>} markers The markers in the clusterer.
* @param {number} numStyles The number of styles available.
* @return {Object} A object properties: 'text' (string) and 'index' (number).
* @private
*/
MarkerClusterer.prototype.calculator_ = function(markers, numStyles) {
var index = 0;
var count = markers.length;
var dv = count;
while (dv !== 0) {
dv = parseInt(dv / 10, 10);
index++;
}
index = Math.min(index, numStyles);
return {
text: count,
index: index
};
};
设置它的函数(它描述它的返回值,索引是图标数组中的索引,文本是要显示在集群上的文本):
/**
* Set the calculator function.
*
* @param {function(Array, number)} calculator The function to set as the
* calculator. The function should return a object properties:
* 'text' (string) and 'index' (number).
*
*/
MarkerClusterer.prototype.setCalculator = function(calculator) {
this.calculator_ = calculator;
};
https://stackoverflow.com/questions/44351686
复制相似问题