[OpenLayers-Users] Displaying attributes by onmouseover
Till Adams
adams at terrestris.de
Tue Feb 24 11:40:01 EST 2009
Kai,
for the rest... I'm sure you are on the right way, because you already
get the alert running by hovering the map.
Possibly you have to replace the "NABU.MAP" in my code with your "map"
or however you called your map-object. I just recognized, that I only
replaced it partwise so possibly you are filtered by the initial "if"... ;-)
Sorry for that.
What also is missing is the Css definition for "map-kurzinfo-popup"
Regards, Till
> Hi Till,
>
>
> thank you for the code :-)
> It`s quite helpful,although I didn`t get it to run as I want so far.
>
> The wfs is correctly visualized, I use that one:
> http://www.gastronomap.de/cgi-bin/mapserv?map=/home/promotion/behncke/gastronomap_wms/gastronomap_wfs.map&SERVICE=WFS&VERSION=1.0.0&Request=GetFeature&Typename=gastronomie_wfs
>
> If I do a mouseover at the different points of the wfs the following
>
> feature_info_hover(arguments[0], gastronomap_wfs) is called.
>
>
> I try:
>
> function feature_info_hover(feature, myWfsLayer)
> {
> alert (myWfsLayer.getFeatureById(feature.gid));
>
>
> ...and get always an alert with "null".
>
> (an "alert (feature);" gives an alert with [object Object], so I think the arguments[0]-parameter is transported correctly).
>
> Has anybody an idea why the gid of the feature doesn`t appear in the alert?
>
> Best regards, Kai
> -------- Original-Nachricht --------
>
>> Datum: Tue, 24 Feb 2009 15:20:45 +0100
>> Von: Till Adams <adams at terrestris.de>
>> An: Kai Behncke <Kai-Behncke at gmx.de>, users at openlayers.org
>> Betreff: Re: [OpenLayers-Users] Displaying attributes by onmouseover
>>
>
>
>> 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
>>
>
>
--
----------------------------------------------------------
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