Re: Find pixel coordinates of marker on mouseover (V2)
I've ended up with the code below for the code that pops up the tool
tip.
http://www.econym.demon.co.uk/googlemaps2/examples/tooltips.htm
Switching to G_ANCHOR_BOTTOM_LEFT instead of G_ANCHOR_TOP_LEFT means
that we're positioning the bottom left corner of the tooltip object,
which in turn means that we don't have to allow for the height of the
tooltip itself when trying to position it sensibly.
It also happens to simplify the code, because we can use getSouthWest()
directly instead of assembling a NorthWest point from the two halves of
getNorthEast() and getSouthWest().
I've chosen to place the bottom left corner of the tooltip at the top
right corner of the box that contains the icon. This is achieved by
subtracting out the iconAnchor (which gives us the top left corner) then
adding iconSize.width. That should be reasonably sensible for most
icons. An alternative strategy would be to add an icon.tooltipAnchor
property to the GIcon()s.
The code still goes wrong when zoomed right out. That's because we
really need to know the unnormalized location of
map.getBounds().getSouthWest(), but there doesn't currently appear to be
any way to obtain that information (as mentioned on a few other threads
recently, map.getBounds() is normalized).
GEvent.addListener(marker,"mouseover", function() {
tip.innerHTML = '<b>'+this.tooltip+'</b>';
var point=map.getCurrentMapType().getProjection().fromLa
tLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
var offset=map.getCurrentMapType().getProjection().fromL
atLngToPixel(this.point,map.getZoom());
var anchor=marker.icon.iconAnchor;
var width=marker.icon.iconSize.width;
var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new
GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y
+anchor.y));
pos.apply(document.getElementById("div_marker_tooltip"))
;
tip.style.visibility="visible";
});
--
The Blackpool Community Church Google Map API Version 2 Tutorial
http://www.econym.demon.co.uk/googlemaps2/
0 Comments:
Yorum Gönder
<< Home