2011-05-13 169 views
5

我试图在'clusterclick'事件中向infoCluster添加一个infoBubble,但是infoBubble.Open方法要求绑定一个'marker'参数。问题是markerCluster不是google.maps.Point,因此不可能将infoBubble绑定到它。google maps api v3 + infoBubble in markerClusterer

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

有没有人有同样的问题?有没有修改原始infoBubble代码的解决方案?

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

回答

6

解决问题1: 标记参数是可选的,如果我根本不会分配给它,问题就解决了。

用途:

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

不:

infoBubble.open(map, marker); 

问题2:但是现在infoBubble出现在市场上,有没有动起来的方式?

解决问题2

我修改了InfoBubble源代码包含一个offsetParameter然后在绘制函数中添加像素:

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

万一有人有同样的问题

1

将此添加到第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); 
+0

将其更改为top + =和left + =更有意义。 [-10,-10]会向左移动。 [10,10]会向右移动。否则,很好的解决方案 – 2017-09-25 18:28:13