1

I was reading this thread: Google Maps Api v3, custom Cluster icon

The thread, explain how we can change the icons of our makrerclusters but, is possible add as variable the quantity? I mean, if the group is of 2 markers display x image, if the group is of 6 markers display other image, etc.

Community
  • 1
  • 1
Benjamin RD
  • 11,516
  • 14
  • 87
  • 157

1 Answers1

1

The decision which icon to use will be made by the calculator-function of the MarkerClusterer.

You may use a custom calculator-function (may be added via the setCalculator-method.)

The default-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
  };
};

As you see, there will be passed 2 arguments:

  1. markers: the markers for the cluster
  2. numStyles: the number of styles available for the MarkerClusterer-instance(by default 5).

The calculator must return an object with the properties:

  • text(text to display, usually the number of markers in the cluster)
  • index(the index of the style that has to be applied)

So what you have to do is:

  1. setup your custom styles(icons)
  2. apply your custom calculator-function that returns the desired index
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201