【问题标题】:MarkerClusterer zooming issueMarkerClusterer 缩放问题
【发布时间】:2013-02-12 11:24:27
【问题描述】:

我正在使用最新版本的 MarkerClusterer 和 Google Maps API v3,我想我发现了一个错误!

我的谷歌地图 minZoom 设置为 1。从级别 1 缩放到任何级别并返回到 1 都很好。当我尝试从级别 1 缩小到级别 0 时会看到该错误。

当我单击以从 1 级缩小到 0 级时,gMap UI 不允许按预期进行缩放,但我的所有 markerCluster 都消失了,当我向下缩放到 2 级并返回时它们会重新出现到 1 级。

我已在 Google Maps API v3 的 Google 群组页面上发布了此内容,但到目前为止没有任何回复(截至今天已超过一周)。

非常感谢任何帮助!

【问题讨论】:

标签: javascript google-maps google-maps-api-3 google-maps-markers markerclusterer


【解决方案1】:

这更像是 Maps-API 中的错误,而不是 markerClusterer 中的错误,但您可以在 markerClusterer.js 中修复它

当您(尝试)将缩放设置为 0 时,我不确定您点击的位置(当我使用缩放控件时不会出现这个问题),但是当我使用设置缩放时会发生这种情况map.setZoom(0)

问题:API 报告缩放为 0,但这是不正确的,因为缩放将设置为 1(minZoom)。

修复:
替换这部分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();
    }
  });

...这样:

  // 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();
    }
  });

【讨论】:

  • 嗨,Molle 博士,您的解决方案有效!但是由于markerClusterer 中的一些其他错误,我不得不升级到markerclustererPlus。我正在使用 v2.0.9 link 并且那里存在相同的错误。我试图将您的解决方案纳入markerclustererPlus,但没有成功。你能看看这个,让我知道如何修复这里的错误吗? (line 723)
  • 我指的是谷歌地图 v3.5,刚刚更新,它解决了 markerClustererPlus 的问题!感谢您的帮助:)
猜你喜欢
  • 2011-08-08
  • 2011-09-01
  • 2017-02-08
  • 1970-01-01
  • 2019-05-24
  • 1970-01-01
  • 2018-06-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多