简体   繁体   English

Google Maps API标记群集器更改级别大小

[英]Google Maps API Marker Clusterer Change Level Size

I'm trying to change level size of Google Maps API Marker Clusterer. 我正在尝试更改Google Maps API Marker Clusterer的级别大小。 For default, the marker small size (blue icon/m1): 2-9 markers, medium level size (yellow icon/m2): 10-100 markers, big level (red icon/m3) size: 101-250 markers. 默认情况下,小标记(蓝色图标/ m1):2-9个标记,中等大小(黄色图标/ m2):10-100个标记,大标记(红色图标/ m3)大小:101-250个标记。 (correct Me if I wrong). (如果我错了,请纠正我)。

I want to change the value of level size smaller than default. 我想将级别大小的值更改为小于默认值。 I have found another thread with same topic but I still didn't get clearly point. 我发现了另一个主题相同的话题,但我仍然不清楚。

This is the Google Maps API Marker Cluster icon I meant: 这是我的Google Maps API标记群集图标:

Google Maps API Marker Clusterer Icon Google Maps API标记群集器图标

PS: I didn't mention about how to change clusterer icon, I meant how to change value of size. PS:我没有提到如何更改群集器图标,而是要更改大小值。 Ex: How I can change the level size of marker so it will be clustered to blue (m1), yellow (m2), and red(m3)? 例如:如何更改标记的级别大小,以便将其聚类为蓝色(m1),黄色(m2)和红色(m3)? The default size like I mentioned before, for m1 it's contain of 2-9 markers, can I change the size value to 2-5 markers only? 像我之前提到的那样,默认大小为m1,其中包含2-9个标记,我可以将大小值更改为仅2-5个标记吗?

You need to create a custom Calculator function. 您需要创建一个自定义Calculator功能。 From the source (of the version referenced in Google's documentation, be sure to verify with the documentation of the version you are using, which you didn't provide). 来源 (Google文档中引用的版本,请确保与您使用的版本的文档进行核实,而您未提供)。 The default calculator function: 默认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
  };
};

The function to set it (which describes its return value, the index is the index into the array of icons, the text is the text to display on the cluster): 设置它的函数(描述其返回值,索引是图标数组的索引,文本是要在群集上显示的文本):

/**
 * 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;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM