getInfowindowOffset = function (map, marker) {
var center = this.getPixelFromLatLng(map.getCenter()),
point = this.getPixelFromLatLng(marker.getPosition()),
quadrant = "",
offset;
quadrant += (point.y > center.y) ? "b" : "t";
quadrant += (point.x < center.x) ? "l" : "r";
if (quadrant == "tr") {
offset = new google.maps.Size(-160, 250);
} else if (quadrant === "tl") {
offset = new google.maps.Size(160, 260);
} else if (quadrant === "br") {
offset = new google.maps.Size(-140, -30);
} else if (quadrant === "bl") {
offset = new google.maps.Size(160, 30);
}
return offset;
};
getPixelFromLatLng = function (latLng) {
var projection = this.map.getProjection();
var point = projection.fromLatLngToPoint(latLng);
return point;
};
ourOverlay:null, createOverlay:function(){ this.ourOverlay = new google.maps.OverlayView(); this.ourOverlay.draw = function() {}; this.ourOverlay.setMap(this.map); },
getInfowindowOffset: function (map, marker) { // Settings var iwWidth = 240; // InfoWindow width var iwHeight = 190; // InfoWindow Height var xOffset = 0; var yOffset = 0; // Our point of interest var location = this.ourOverlay.getProjection().fromLatLngToContainerPixel(marker.getPosition()); // Get Edges of map in pixels: Sout West corner and North East corner var swp = this.ourOverlay.getProjection().fromLatLngToContainerPixel(map.getBounds().getSouthWest()); var nep = this.ourOverlay.getProjection().fromLatLngToContainerPixel(map.getBounds().getNorthEast()); // Horizontal Adjustment if(location.x<iwWidth/2){ xOffset= iwWidth/2-location.x; }else if(location.x>nep.x-iwWidth/2){ xOffset = (nep.x-iwWidth/2)-location.x ; } // Vertical Adjustment if(location.y<iwHeight){ yOffset = location.y + iwHeight-(location.y-nep.y); } // Return it return new google.maps.Size(xOffset, yOffset); },