Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off clustering with Google Maps API

Tags:

google-maps

I am creating clusters on the map like this:

markerCluster = new MarkerClusterer(map, markers, mcOptions);

Without 'refreshing' the map markers, is it possible to temporarily turn off clustering and then turn it back on again?

like image 886
gp. Avatar asked Oct 26 '11 20:10

gp.


People also ask

How do I remove a marker cluster from Google Maps?

Removing all markers You can then clear all the markers using clearMarkers something like this: markerClusterer. clearMarkers(); markers = [];

What is clustering in Google Maps?

The number on a cluster indicates how many markers it contains. Notice that as you zoom into any of the cluster locations, the number on the cluster decreases, and you begin to see the individual markers on the map. Zooming out of the map consolidates the markers into clusters again.

How do I disable Google Maps API?

Disable an APIGo to the API Console. From the projects list, select a project or create a new one. If the API Manager page isn't already open, open the console left side menu and select API Manager. Next to the API you want to disable, click Disable.

Can you customize Google Maps API?

Easily create your styleThe new Google Maps APIs Styling Wizard helps you to create a map style in a few clicks. Use one of our pre-built styles or create your own style from scratch.


2 Answers

You can try to set maxZoom and gridSize to something minimal.

markerClusterer.setMaxZoom(1);
markerClusterer.setGridSize(1);
markerClusterer.redraw();

Before doing that you may just save previous values (getMaxZoom() and getGridSize()). Relying on reference there are nothing like enableClustering().

like image 156
dmitry Avatar answered Sep 30 '22 21:09

dmitry


This repaint() method worked for me:

    var markerCluster2 = new MarkerClusterer(map, markers, mcOptions);

$('#turnoff_clustering').click(function(){
                markerCluster2.setMaxZoom(1);
                markerCluster2.repaint();
});
like image 22
Эрих Гайлис Avatar answered Sep 30 '22 22:09

Эрих Гайлис