【问题标题】:google maps api v3 + infoBubble in markerClusterer谷歌地图 api v3 + markClusterer 中的 infoBubble
【发布时间】:2011-08-25 05:17:45
【问题描述】:

我试图在“clusterclick”事件中向 markerCluster 添加一个 infoBubble,但 infoBubble.Open 方法要求绑定一个“marker”参数。问题是 markerCluster 不是 google.maps.Point 所以不可能将 infoBubble 绑定到它。

我将 markerCluster 的位置分配给 infoBubble,但 infoBubble 在新位置重绘,将标记从其位置移开。

有人遇到过同样的问题吗?有没有不修改原有infoBubble代码的解决方案?

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/

【问题讨论】:

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


    【解决方案1】:

    解决问题一: 标记参数是可选的 如果我只是从不分配它,问题就解决了。

    用途:

    infoBubble.setPossition(latLng);
    infoBubble.open(map);
    

    不是:

    infoBubble.open(map, marker);
    

    问题 2:但是现在市场上出现了 infoBubble,有没有办法让它向上移动??

    解决问题2

    我修改了 InfoBubble sourceCode 以包含一个 offsetParameter,然后在绘图函数中添加像素:

    InfoBubble.prototype.PIXEL_OFFSET = 0
    ...
    var top = pos.y - (height + arrowSize); if (anchorHeight) { top -= anchorHeight; } top -= this.PIXEL_OFFSET
    

    以防万一有人遇到同样的问题

    【讨论】:

      【解决方案2】:

      将此添加到第 93 行(在其他选项字段下方)

      if (options['pixelOffset'] == undefined) {
          options['pixelOffset'] = this.PIXEL_OFFSET_;
      }
      

      在第 182 行附近,添加这个

      InfoBubble.prototype.PIXEL_OFFSET_ = [0.0];
      

      在第 908 行附近,添加以下内容:

      top -= this.get('pixelOffset')[1];  // Add offset Y.
      left -= this.get('pixelOffset')[0]; // Add offset X.
      

      上面的行应该放在上面:

      this.bubble_.style['top'] = this.px(top);
      this.bubble_.style['left'] = this.px(left);
      

      现在你正在构建你可以做的选择

      var popupWindowOptions = {
          backgroundColor: '#2B2B2B',
          arrowStyle: 0,
          pixelOffset: [0,16]
       };
      
       this.popupWindow = new InfoBubble(popupWindowOptions);
      

      【讨论】:

      • 将其更改为顶部 += 和左侧 += 在这里更有意义。 [-10,-10] 会向左移动。 [10,10] 将向右移动。否则,很好的解决方案。
      猜你喜欢
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      • 1970-01-01
      • 2012-08-03
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多