pixeloffset在谷歌地图中不起作用

Tri*_*hul -1 google-maps google-maps-api-3 infobubble

我创建了一个自定义的谷歌地图,带有标记和自定义信息窗口.想要标记下面的信息窗口而不是顶部.我通过定位信息窗口的纬度和经度来实现这一点.但是我在google api中遇到了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);
Run Code Online (Sandbox Code Playgroud)

Dr.*_*lle 5

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

但是,只需要对infobubble.js进行一些小的更改即可应用此功能.

打开infobubble.js(未编译版本)并找到此代码(在draw-function中):

  // 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);
Run Code Online (Sandbox Code Playgroud)

应用这些更改:

  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;