Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

modifying MarkerClusterer icons for top score, rather than marker count

I'm looking for some advice on where to start with this:

I currently have "vanilla" MarkerClusterer up and running in a dev environment (aprox 3000 markers).

Each marker has a score associated with it, and i want to change it so that the cluster markers represent the top score of the markers they contain (rather than representing just the number of markers).

Where should i go, and how would i go about making this change happen?

Thanks!

like image 986
user1051849 Avatar asked Oct 08 '12 13:10

user1051849


1 Answers

use the setCalculator() method to define how you want the calculation to be done. Here's the code that uses the original function. Tweak it to do the calculation the way you want it. The calculator function is called once per cluster, so the result is the text you want in the cluster and the index of the style it should have.

your_clusterer.setCalculator(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
  };
});
like image 128
Mark Avatar answered Nov 15 '22 06:11

Mark