[OpenLayers-Users] Displaying attributes by onmouseover

Till Adams adams at terrestris.de
Tue Feb 24 09:20:45 EST 2009


Kai Behncke schrieb:
> Dear Openlayers-Users,
>
>
> I use an application with a couple of point objects (500) visualized by a wms in the map.
>
> I´m looking for a function that pops up a small window (for example with the name of an object) if I do a mouseover at an object in the map.
> I think for this using a second layer ("invisible" wfs) could be best practise (or which other possibilities shall be usable)??
>
> As far as I can see a script like that does not exist in the examples (if I haven`t overseen it.....).
> I would like to try to write one and supply it.
> What is the way if I want to supply a script like that to the examples?
>
> Best regards, Kai Behncke
>   
Kai,


we use WFS and the select feature from OL::

**
 * -------------------------------------------------------------------
 * feature_info_hover
 * function to hover a feature open a new pop up window and destroy
 * it after 3000 milliseconds (variable at end of function)
 *
 * @feature
 * -------------------------------------------------------------------
 */
function feature_info_hover(feature, myWfsLayer)
{
    if (this.popup && NABU.MAP && NABU.MAP.popups && 
NABU.MAP.popups.length > 0)
    {
        window.clearTimeout(this.autodestroy);
        this.popup.destroy();
        this.popup = null;
    }
    var myFeature = myWfsLayer.getFeatureById(feature.id);
   
    if (myFeature)
    {
   
        var window_position = new 
OpenLayers.LonLat(myFeature.geometry.x, myFeature.geometry.y);
        this.popup = new OpenLayers.Popup("ol-info-popup", 
window_position, null, '<div class="map-kurzinfo-popup"><span>' + 
myFeature.data.name + '</span><br><span onclick="javascript:OpenInfo(\'' 
+ myFeature.data.gid + '\',\'' + myWfsLayer.typename + '\')" 
style="cursor:pointer;">weitere Informationen</span></div>', false);
        this.popup.autoSize = true;
        map.addPopup(this.popup, true);
        this.autodestroy = window.setTimeout(function()
        {
            if (map && map.popups && map.popups.length > 0)
            {
                var len = map.popups.length;
                for (var i = 0; i < len; i++)
                {
                    if (map.popups[i] && map.popups[i].destroy)
                    {
                        map.popups[i].destroy();
                    }
                }
            }
        }, 3000);
    }
}

See that we refer manually to "myFeature.data.gid", 
"myFeature.data.name" and "myFeature.data.typename" which is not really 
them ost elegant way...

Then initiate it through that code in the ol init function:


    hover.parken = new OpenLayers.Control.SelectFeature(tbl_p_parken, {
        callbacks: {
            'over': function()
            {
                feature_info_hover(arguments[0], tbl_p_parken);
            }
        }
    });
    map.addControl(hover.parken);
    hover.parken.activate();


Where "tbl_p_parken" is our WFS defined in the layer section of the ol 
init function. This only works for one layer as the select feature of OL 
in the moment only handles one layer, this is to be changed on the next 
OL versions.

Regards, Till


----------------------------------------------------------
terrestris GmbH & Co. KG
Irmintrudisstrasse 17
53111 Bonn
Germany

Till Adams
Geschäftsführung

Tel: +49 (0)228 / 962 899-52
Fax: +49 (0)228 / 962 899-57
adams at terrestris.de http://www.terrestris.de
Amtsgericht Bonn, HRA 6835
---------------------------------------------------------

Komplementärin:

terrestris Verwaltungs GmbH

vertreten durch:
Hinrich Paulsen, Till Adams




More information about the Users mailing list