如何更改 google 地图的 maker 集群默认值?

How to change the default value of maker cluster for google maps?

我在一个项目中工作,在该项目中我将 MarkerClustererPlus 用于 Google Maps V3。我已经阅读了文档,但我无法在任何地方找到如何更改标记集群显示的默认值(集群中的引脚数)。我想用该集群的引脚中包含的一些值的总和来更改该值。这可以实现吗?

您必须设置自定义计算器函数。

在此函数中遍历所有标记,对您想要的内容求和并计算样式的索引。

示例(将在群集图标中显示名为 prop 的标记-属性 的总和:

markerCluster.setCalculator(function(markers, numStyles) {
  var val=0,//this will be the text you see in the cluster-icon
      index=0,
      dv;

  for(var m=0;m<markers.length;++m){
    //add the value of the markers prop-property to val
    val+=Number(markers[m].prop);
  }
  dv = val;
  while (dv !== 0) {
    dv = parseInt(dv / 10, 10);
    index++;
  }

  index = Math.min(index, numStyles);
  return {
    text: val,
    index: index
  };
}
);