[GIS] How to center a popup window exactly where I’ve clicked

openlayers-2

I have a question on how I can change this code

selectedFeature = feature;
popup = new OpenLayers.Popup.FramedCloud("chicken", 
  feature.geometry.getBounds().getCenterLonLat(),
  null,
  div,
  null, null, onPopupClose);
feature.popup = popup;

to make the center point of popup window exactly where I've clicked, instead of on the center of object bounds as it is now ?

Best Answer

I have a not tested proposition :

1 - From that example you will be able to get coordinates from click -see also that example.

2 - You will, then be able to convert coordinates to pixel, with that function.

3 - Finally, you move the popup with popup.moveTo(new OpenLayers.Pixel(xxx));.

You probably have to calculate it before, regarding popup width and height. With the help of jQuery it can even be dynamic.