[GIS] How to have a popup anchored at the clicked position

openlayers-2wfs

I have a vector layer overlaid above a base layer. Basically I want to have a popup anchored at the clicked position when clicking anywhere on the vector geometries. So I have the code:

     var selectCtrl = new OpenLayers.Control.SelectFeature(activeLayer, {
            clickout: true, 
            onSelect: open_infowin, 
            onUnselect: close_infowin
        });

    function open_infowin(event) {

        var mousePos = this.events.getMousePosition(event);

        infowin = new OpenLayers.Popup.FramedCloud(
                     "popup",
                     map.getLonLatFromViewPortPx(mousePos),
                     new OpenLayers.Size(300,150),
                     "Updating<br/>information...",
                     null,
                     true,
                     null
                   );
        map.addPopup(infowin);
    }

But the OnSelect function passes an event object with no mouse position. If I register mouse events with the Map, no event will be fired when the mouse moves on the vector layer.

Any suggestion?

Best Answer

Maybe I'm not understanding the question, but does this example do what you want? Seems that the popup is anchored on the mouse position (unless the feature is near the edge of the map so the popup is shifted to fit on the map).

http://openlayers.org/dev/examples/getfeatureinfo-popup.html