Permalink
Browse files

Fixed positioning bug

  • Loading branch information...
1 parent e801f73 commit 24793eeb38ad21a6b39e4602e9f87a1f21c8c5b8 @christianhellsten committed Oct 29, 2009
Showing with 29 additions and 3 deletions.
  1. +8 −2 README.textile
  2. +21 −1 jquery.google-maps.tooltip.js
View
@@ -12,6 +12,9 @@ h3. HTML
<script src="/javascripts/jquery.google-maps.tooltip.js" type="text/javascript"></script>
<script src="/javascripts/jquery-1.3.2.min.js" type="text/javascript"></script>
+ <!-- The map -->
+ <div id="map"></div>
+
<!-- The tooltip -->
<div style="display:none; position: absolute;" id="map-tooltip"></div>
</code>
@@ -21,6 +24,9 @@ h3. JavaScript
<pre>
<code>
+ // The Google map
+ var map = new google.maps.Map(document.getElementById("map"), options);
+
// Called right before tooltip is displayed
var before_show = function(marker, tooltip) {
// Set tooltip contents to the marker's title
@@ -35,9 +41,9 @@ h3. JavaScript
};
// Attach tooltip to the DIV element
- var tooltip = new MapTooltip($('#map-tooltip'), before_show, before_hide);
+ var tooltip = new MapTooltip(map, $('#map-tooltip'), before_show, before_hide);
- // Add a marker to tooltip, see http://code.google.com/intl/sv-SE/apis/maps/documentation/v3/reference.html#Marker
+ // Attach tooltip to marker, see http://code.google.com/intl/sv-SE/apis/maps/documentation/v3/reference.html#Marker
tooltip.addMarker(marker); //
</code>
</pre>
@@ -1,13 +1,15 @@
//
//
//
-function MapTooltip(tip, onBeforeShow, onBeforeHide) {
+function MapTooltip(map, tip, onBeforeShow, onBeforeHide) {
// Don't forget the tip
var $tooltip = tip;
// One timer
var timer = 0;
// Don't loose our scope
var self = this;
+ // xy position
+ var overlay = get_overlay(map);
if(!$tooltip.hasClass('tooltip-enabled')) {
// Mouse enter
@@ -23,6 +25,24 @@ function MapTooltip(tip, onBeforeShow, onBeforeHide) {
$tooltip.addClass('tooltip-enabled');
}
+ //
+ // We need this overlay for getting the markers position
+ //
+ function get_overlay(map) {
+ function ProjectionHelperOverlay(map) {
+ this.set_map(map);
+ }
+
+ ProjectionHelperOverlay.prototype = new google.maps.OverlayView();
+ ProjectionHelperOverlay.prototype.draw = function () {
+ if (!this.ready) {
+ this.ready = true;
+ google.maps.event.trigger(this, 'ready');
+ }
+ };
+ return new ProjectionHelperOverlay(map);
+ }
+
function startTimer(callback, time) {
stopTimer();
timer = setTimeout(callback, time);

0 comments on commit 24793ee

Please sign in to comment.