[OpenLayers-Users] Popups that follow the mousepointer

Amos Hayes ahayes at gcrc.carleton.ca
Mon Nov 17 10:31:40 EST 2008


Hello Trond. I was having the same problem and tried to write around  
it by moving the popup corner a number of pixels horizontally and  
vertically to avoid covering the point. Unfortunately, my algorithm  
for guessing which quadrant the popup will appear in is flawed for  
points near the very center of the map. If you can fix it or find a  
better way (I have yet to feel capable enough to explore the  
OpenLayers popup code), I'd love to see it. :)

Here is what I came up with:

       var popup_lonlat =  
hoverFeature.geometry.getBounds().getCenterLonLat();
		if (popup_shift) {
			var shift_lon, shift_lat;
			var map_centre_lonlat = map.getCenter();
			if (popup_lonlat.lon >= map_centre_lonlat.lon) {
				shift_x = -5;
			} else {
				shift_x = 5;
			}
			if (popup_lonlat.lat >= map_centre_lonlat.lat) {
				shift_y = 5;
			} else {
				shift_y = -5;
			}
			var popup_pixel = map.getPixelFromLonLat(popup_lonlat);
			popup_pixel = popup_pixel.offset(new  
OpenLayers.Pixel(shift_x,shift_y));
			popup_lonlat = map.getLonLatFromPixel(popup_pixel);
		}
     	popup = new OpenLayers.Popup.AnchoredBubble("chicken",
                              popup_lonlat,
                              null,
                              feature_popup_html,
                              null, false, onPopupClose);

--
Amos Hayes
Geomatics and Cartographic Research Centre
Carleton University
ahayes at gcrc.carleton.ca
+1.613.520.2600x8179

On 17-Nov-08, at 10:16 AM, Trond Michelsen wrote:

> Hi.
>
> Is it possible to get a popup to float a couple of pixels above the
> mousepointer?
>
> I'm using SelectFeature with hover: true to open popups, and sometimes
> the popup will open where the pointer is, which will cause the popup
> to close. Once the popup is gone, it will reopen, since the pointer is
> still hovering over the feature.
>
> -- 
> Trond Michelsen
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list