I've read many issues related to autozoom and the fact that it is showing at maximum level when there is only one marker, i.e. in location node block.

In gmap_marker.js (i.e. with no marker manager) when autozoom is enabled, it is setting the zoom level by calling to map.getBoundsZoomLevel() which is returning the zoom level at which the given rectangular region fits in the map view.
When there is only one marker to show, that rectangular region is only one point, so it is returning the maximum zoom level.

The GMap's configuration page says that, autozoom automatically zoom the map to fit all markers when markers are added, but I think that it should only zoom out the map to fit all markers when the zoom level selected with the corresponding macro (or default) is not enough to show all markers.

So, here is my fix for gmap_marker.js:

Before:

      obj.map.setCenter(obj.bounds.getCenter(),obj.map.getBoundsZoomLevel(obj.bounds));

After:

      // Zoom out to fit all markers, if needed
      if (obj.map.getBoundsZoomLevel(obj.bounds) < obj.map.getZoom()) {
        obj.map.setCenter(obj.bounds.getCenter(),obj.map.getBoundsZoomLevel(obj.bounds));
      }
      else {
        obj.map.setCenter(obj.bounds.getCenter());
      }

jpereza.

Comments

ultimike’s picture

Interesting point. I can see arguments for having the autozoom work either way...

Regardless, I tried your patch and it looks good to me (Firefox 2, OS X).

-mike

rbl’s picture

At last! Works for me! It was either not centering or showing everything at street level.

Thanks!
Ricardo

twooten’s picture

Sweeeeet! Works great jpereza, thanks a million.

bdragon’s picture

Version: 5.x-1.0-alpha1 » 5.x-1.x-dev
Status: Active » Fixed

Fixed this in a more flexible way in -dev by actually adding a setting.

http://drupal.org/cvs?commit=113786

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.