简体   繁体   English

MarkerClusterer缩放问题

[英]MarkerClusterer zooming issue

I'm using the latest version of MarkerClusterer with Google Maps API v3 and I think I've found a bug! 我正在使用最新版本的MarkerClusterer和Google Maps API v3,我想我发现了一个错误!

My google map minZoom is set to 1. Zooming from level 1 down to any level and back up to 1 is just fine. 我的谷歌地图minZoom设置为1.从1级缩小到任何级别,然后回到1就可以了。 The bug is seen when I try to zoom out from level 1 to level 0. 当我尝试从1级缩小到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. 当我单击从第1级缩小到第0级时,gMap UI不允许按预期进行缩放,但是我的所有markerClusters都会消失,当我向下缩放到第2级并返回到第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). 我已经在Google Maps API v3的Google网页上发布了这个帖子,但到目前为止还没有回复(截至今天已过了一周)。

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 这是Maps-API中的一个错误,而不是markerClusterer中的错误,但你可以在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) 当你(尝试)将缩放设置为0时,我不确定你点击的位置(当我使用变焦控制时,我的问题不会发生),但是当我使用map.setZoom(0)设置缩放时会发生这种情况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). 问题:API报告缩放为0,但这是不正确的,因为缩放将设置为1(minZoom)。

Fix: 固定:
Replace this part of marcerclusterer.js: 替换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();
    }
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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