Skip to content

Instantly share code, notes, and snippets.

@pierrevalade
Created October 18, 2011 18:26
Show Gist options
  • Save pierrevalade/1296233 to your computer and use it in GitHub Desktop.
Save pierrevalade/1296233 to your computer and use it in GitHub Desktop.
scale = Math.pow(2, this.map.getZoom());
nw = new google.maps.LatLng(this.map.getBounds().getNorthEast().lat(), this.map.getBounds().getSouthWest().lng());
worldCoordinateNW = this.map.getProjection().fromLatLngToPoint(nw);
worldCoordinate = this.map.getProjection().fromLatLngToPoint(venueMarker.getPosition());
pixelOffset = new google.maps.Point(Math.floor((worldCoordinate.x - worldCoordinateNW.x) * scale), Math.floor((worldCoordinate.y - worldCoordinateNW.y) * scale));
tooltipDiv = $('#explore-tooltip');
tooltip = {
width: tooltipDiv.width(),
height: tooltipDiv.height()
};
console.log("tooltipWidth: " + tooltip.width);
console.log("tooltipHeight: " + tooltip.height);
mapDiv = $('#google-map');
map = {
width: mapDiv.width(),
height: mapDiv.height()
};
console.log("map:");
console.log(map);
venue = {
x: pixelOffset.x,
y: pixelOffset.y
};
console.log("venue");
console.log(venue);
mapCenter = {
x: map.width / 2,
y: map.height / 2
};
console.log("mapCenter:");
console.log(mapCenter);
if (venue.x < mapCenter.x) {
tooltipDiv.css('left', venue.x + 30 + 350);
tooltipDiv.css('right', '');
} else {
tooltipDiv.css('right', (map.width - venue.x) + 30);
tooltipDiv.css('left', '');
}
if (venue.y < mapCenter.y) {
tooltipDiv.css('top', venue.y + 76 - 45);
tooltipDiv.css('bottom', '');
if ((venue.y + tooltip.height) > map.height) {
tooltipDiv.css('top', 20 + 76);
}
} else {
tooltipDiv.css('bottom', map.height - venue.y);
tooltipDiv.css('top', '');
if ((venue.y - tooltip.height) < 0) {
tooltipDiv.css('bottom', 20);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment