Вот более полное решение:
в .html добавить:
<div id="map-canvas-hidden" style="display:none"></div>
<div id="map-canvas-shown" style="width:500px; height:500px"></div>
в .js добавить:
MarkerClusterer.prototype.remove = function() { };
var HIDDEN_MAP = new google.maps.Map(document.getElementById("map-canvas-hidden"), {});
var gmap = new google.maps.Map(document.getElementById("map-canvas-shown"), {});
чтобы показать кластеры:
cluster.setMap(gmap);
cluster.resetViewport();
cluster.redraw();
чтобы скрыть кластеры:
cluster.setMap(HIDDEN_MAP);
cluster.resetViewport();
cluster.redraw();
наконец, мне понадобились следующие патчи для markerclusterer.js:
--- markerclusterer.js.orig 2013-12-06 18:02:32.887516000 +0100
+++ markerclusterer.js 2013-12-06 18:03:25.487516924 +0100
@@ -620,6 +620,7 @@
*/
MarkerClusterer.prototype.getExtendedBounds = function(bounds) {
var projection = this.getProjection();
+ if (!projection) return null;
// Turn the bounds into latlng.
var tr = new google.maps.LatLng(bounds.getNorthEast().lat(),
@@ -657,7 +658,7 @@
* @private
*/
MarkerClusterer.prototype.isMarkerInBounds_ = function(marker, bounds) {
- return bounds.contains(marker.getPosition());
+ return bounds ? bounds.contains(marker.getPosition()) : false;
};
надеюсь, это поможет