[OpenLayers-Users] Showing OpenLayers.Popup when marker is hovered
Daniel Werner
DanWeEtz at web.de
Sat Oct 8 19:19:21 EDT 2011
Hi,
I want to create a hover popup effect for map markers. Right now popups
are displayed when klicking on a marker, now I want to show them when
the mouse is over the marker and it should vanish when mouse goes down
from the marker. If the marker is klicked, the popup should stay and get
the close icon.
First, OpenLayers.Popup.addCloseBox() creates the close box in the
wrong place, can't figure out why since this is the case even if I call
it like this:
var popup = new OpenLayers.Feature( markerLayer, this.lonlat
).createPopup( false );
popup.addCloseBox( function(){ this.feature.destroy(); } );
This seems odd since createPopup() would be called from createPopup(
true ) in the end and there it works fine. A way to register a custom
callback for the close event would help too, but there is no function
for that only one parameter in the popup constructor (which I can't set
when using OpenLayers.Feature) and it can be set with addCloseBox() but
since the bug above I can't use it either.
Now the main problem:
The hover effect works fine when the popup appears in the left or right
bottom corner. If its on the top it won't work fine because the popup
will be on top of the marker and my 'mouseout' event is triggered too
early, namely when the popup appears on top of the marker and the mouse
is on top of it, now JS will trigger the 'mouseout' for the marker event
though, visually, the mouse is still on top of the marker.
Now all that wouldn't be much of a problem if the popups dom would be a
descendant of the marker. But it is not, it's totally independent. So I
tried to add a 'mousemove' event to the popup and do some pixel
calculation to check whether the mouse is still visually on top of the
marker. This works except that the popup starts a few pixels above the
marker, so if the mouse leaves at the bottom, it doesn't work perfectly.
Is there any better solution for this? Is ist posible to make the popups
dom the markers descendant somehow??
Thanks for any help
Daniel
More information about the Users
mailing list