google-mapsgoogle-maps-api-3infobubble

pixeloffset not working in google map


I have created a customized google map, with a marker and customized info window. want the info window below the marker instead of top. I achieved this by positioning lattitude and longitude of info window. But I came across pixeloffset attribute in google api, but its not working. I used

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);

Solution

  • InfoBubble is not a implementation of a google.maps.InfoWindow , there is no property pixelOffset for a InfoBubble.

    But it only takes some minor changes in infobubble.js to apply this feature.

    Open infobubble.js(uncompiled version) and find this code(inside the 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);
    

    apply these changes:

      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;