2013-09-22 105 views
-1

我创建了一个定制的谷歌地图,带有标记和自定义信息窗口。 想要标记下面的信息窗口而不是顶部。 我通过定位信息窗口的经度和纬度来实现这一点。 但我在google api中遇到了pixeloffset属性,但它不起作用。 我用pixeloffset不能在谷歌地图工作

var infoBubble = new InfoBubble({ 
map: map, 
content: '<div>Some label</div>', 
position: new google.maps.LatLng(26.890076,75.755000), 
shadowStyle: 1, 
padding: 0, 
backgroundColor: 'rgb(57,57,57)', 
borderRadius: 4, 
arrowSize: 0, 
borderWidth: 1, 
borderColor: '#2c2c2c', 
disableAutoPan: true, 
hideCloseButton: true, 
pixelOffset: new google.maps.Size(-100,0) 
}); 
infoBubble2.open(map,marker); 
+0

你是什么意思是 “不工作” ? – geocodezip

回答

5

InfoBubble不是google.maps.InfoWindow的实现,有一个InfoBubble没有财产pixelOffset

但是它只需要对infobubble.js进行一些小修改就可以应用此功能。

打开infobubble.js(未编译的版本),找到这个代码(抽奖功能内):

// Adjust for the height of the info bubble 
    var top = pos.y - (height + arrowSize); 

    if (anchorHeight) { 
    // If there is an anchor then include the height 
    top -= anchorHeight; 
    } 

    var left = pos.x - (width * arrowPosition); 

应用这些更改:

 
    if(!this.pixelOffset 
     || !this.pixelOffset.constructor 
     || this.pixelOffset.constructor !== google.maps.Size){ 
    this.pixelOffset = new google.maps.Size(0,0); 
    } 
    // Adjust for the height of the info bubble 
    var top = pos.y - (height + arrowSize) + this.pixelOffset.height; 

    if (anchorHeight) { 
    // If there is an anchor then include the height 
    top -= anchorHeight; 
    } 

    var left = pos.x - (width * arrowPosition) + this.pixelOffset.width; 

+0

太棒了!谢谢。 – Kabkee