Maps API v3 clustering at different zoom levels

2019-02-24 01:35发布

问题:

I am working on a map project where I need clustering. I implemented a store locator and used MarkerClusterer which works fine. Now I have another requirement from the customer and I wonder which solution I should use to achieve these goals:

  • Zoom level 0: Cluster markers within 1500km distance to each other
  • Zoom level 1: Cluster within 1000km
  • Zoom level 2: Cluster within 750km
  • Zoom level 3: Cluster within 400km
  • Zoom level 4 and above: no clustering

I was thinking I should be using MarkerManager and MarkerClusterer together, but I am not sure about that. Any help to get me on the right path?

Thanks in advance!

回答1:

You can only use MarkerClusterer, but you have to modify some options.

To prevent the clusterer acts after level 4, you have to use maxZoom property. It defines the max level where the clusterer can cluster marker, so in your case, you have to fix it at 4.

Then, to change the size of the grid depending the zoom level, use gridSize property. You can find a definition of all option fields on the doc.

So, your MarkerClusterer instanciation will look like something like this :

var mcOptions = {gridSize: /*Your value*/, maxZoom: 4};
var markerCluster = new MarkerClusterer(map, /*your array of markers*/ mcOptions);