简体   繁体   中英

MarkerClusterer zooming issue

I'm using the latest version of MarkerClusterer with Google Maps API v3 and I think I've found a bug!

My google map minZoom is set to 1. Zooming from level 1 down to any level and back up to 1 is just fine. The bug is seen when I try to zoom out from level 1 to level 0.

When I click to zoom out from level 1 to level 0, the gMap UI doesn't allow the zoom, as intended, but all my markerClusters disappear, they re-appear when I go down to zoom level 2 and come back to level 1.

I've posted this on the Google Group page for Google Maps API v3, but no response so far (been over a week as of today).

Any help is much appreciated!

It's more a bug in the Maps-API than a bug in markerClusterer, but you can fix it in markerClusterer.js

I'm not sure where you click on when you(try to) set the zoom to 0(the issue for me doesn't occur when I use the zoom-control), but it happens when I set the zoom using map.setZoom(0)

The issue: the API reports a zoom of 0, but this is incorrect, because the zoom will be set to 1(the minZoom).

Fix:
Replace this part of marcerclusterer.js:

// Add the map event listeners
  var that = this;
  google.maps.event.addListener(this.map_, 'zoom_changed', function() {
    var zoom = that.map_.getZoom();

    if (that.prevZoom_ != zoom) {
      that.prevZoom_ = zoom;
      that.resetViewport();
    }
  });

...with that:

  // Add the map event listeners
  var that = this;
  google.maps.event.addListener(this.map_, 'zoom_changed', function() {
    var zoom = that.map_.getZoom(),
        minZoom=that.map_.minZoom||0,
        maxZoom=Math.min(that.map_.maxZoom||100,
                         that.map_.mapTypes[that.map_.getMapTypeId()].maxZoom);
        zoom=Math.min(Math.max(zoom,minZoom),maxZoom);

    if (that.prevZoom_ != zoom) {
      that.prevZoom_ = zoom;
      that.resetViewport();
    }
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM