Skip to content

Commit

Permalink
BUGFIX: Adjust zoom handling for cluster marker
Browse files Browse the repository at this point in the history
Always zoom in when you click the cluster marker. If zoomOnClick is enabled and the map aspect ration
is special the zoom in does not work.

See issue googlemaps#437 for more information.
  • Loading branch information
markusguenther authored Jun 15, 2018
1 parent 141697f commit 76fee84
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions markerclustererplus/src/markerclusterer.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ ClusterIcon.prototype.onAdd = function () {
if (!cDraggingMapByCluster) {
var theBounds;
var mz;
var currentZoom;
var mc = cClusterIcon.cluster_.getMarkerClusterer();
/**
* This event is fired when a cluster marker is clicked.
Expand All @@ -161,20 +162,23 @@ ClusterIcon.prototype.onAdd = function () {

// The default click handler follows. Disable it by setting
// the zoomOnClick property to false.
// CORE-PATCH begin by Markus Günther
// For more details look at the github issue https://github.com/googlemaps/v3-utility-library/issues/437
if (mc.getZoomOnClick()) {
// Zoom into the cluster.
mz = mc.getMaxZoom();
currentZoom = mc.getMap().getZoom();
theBounds = cClusterIcon.cluster_.getBounds();

mc.getMap().fitBounds(theBounds);
// There is a fix for Issue 170 here:
setTimeout(function () {
var newZoom = (mz !== null && (currentZoom > mz) ? mz : currentZoom) + 1;
mc.getMap().fitBounds(theBounds);
// Don't zoom beyond the max zoom level
if (mz !== null && (mc.getMap().getZoom() > mz)) {
mc.getMap().setZoom(mz + 1);
}
mc.getMap().setZoom(newZoom);
}, 100);
}
// CORE-PATCH end by Markus Günther

// Prevent event propagation to the map:
e.cancelBubble = true;
Expand Down

1 comment on commit 76fee84

@garylittleRLP
Copy link

@garylittleRLP garylittleRLP commented on 76fee84 Jun 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the fitBounds call in line 177 doing anything now? What if fitBounds would normally cause the map to zoom in by two levels? It wouldn't work because the setZoom call in line 178 just increases the zoom level by 1. Perhaps after the fitBounds you should set newZoom to the max of newZoom and the current zoom.

Please sign in to comment.