[OpenLayers-Users] WFS Layers, Markers, Popups

Arnd Wippermann arnd.wippermann at web.de
Tue Oct 28 13:25:59 EDT 2008


Try this, to get all attributes for the feature:
 
function onFeatureSelect(feature) {             
    var Msg="";
    for(var key in feature.attributes)
        Msg += key + ":" + feature.attributes[key] + "\r\n";
    alert(Msg);
}
 
but perhaps you mean city_name instead of citiy_name.
 
Arnd Wippermann


  _____  

Von: indika85 at gmail.com [mailto:indika85 at gmail.com] 
Gesendet: Dienstag, 28. Oktober 2008 11:47
An: Eric Lemoine
Cc: Arnd Wippermann; users at openlayers.org
Betreff: Re: [OpenLayers-Users] WFS Layers, Markers, Popups


Thanks for the info. Got the featureselected event working.

I am having the issue of obtaining attributes of a feature.

This is how my code look like.

 wfs_cities = new OpenLayers.Layer.WFS( "WFS Cities",
                        "http://localhost:8080/geoserver/wfs",
                        {typename: "topp:cities",
                        extractAttributes : true
                    },
                        {styleMap: new OpenLayers.StyleMap({
                                  "default": cities_symbolizer//,
                                  //"select" : cities_symbolizer_select
                 })}
          );

 var selectControl = new OpenLayers.Control.SelectFeature(
                            wfs_cities,
                            {onSelect : onFeatureSelect});
               
            function onFeatureSelect(feature) {             
                alert(feature.attribute.citiy_name);
        }  
        
            map.addControl(selectControl);
            selectControl.activate();

The alert above does not show any output.
By following this method is it necessary to do the following also to extract
attribute information using GetFeature ?

 wfs_cities.events.register('featureselected', map, function (e) {
                document.getElementById('nodelist').innerHTML = "Loading";
                var url =  wfs_cities.getFullRequestString(
                    {
                        //SERVICE : 'WFS',
                        REQUEST: "GetFeature",
                        EXCEPTIONS: "application/vnd.ogc.se_xml",
                        //BBOX: map.getExtent().toBBOX(),
                        //X: e.xy.x,
                        //Y: e.xy.y,
                        INFO_FORMAT: 'text/html',
                        //QUERY_LAYERS: map.layers[2].params.LAYERS,
                        PROPERTYNAME: 'the_geom',
                        FEATURE_COUNT: 50
                        //FILTER: '<wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc" service="WFS" version="1.1.0"
xmlns:gml="http://www.opengis.net/gml"><gml:featureMember><ogc:Filter><ogc:C
ontains><ogc:PropertyName>the_geom</ogc:PropertyName><gml:Point><gml:coordin
ates>'+lonlatxy+'</gml:coordinates></gml:Point></ogc:Contains></ogc:Filter><
/gml:featureMember></wfs:FeatureCollection>',
                        //WIDTH: map.size.w,
                        //HEIGHT: map.size.h
                    },
                    "http://localhost:8080/geoserver/wfs"
                );

Thanks in advance



2008/10/28 Eric Lemoine <eric.c2c at gmail.com>


As Arnd said you should use vectors styled with externalgraphic and
the select feature control to be able to select your markers and
display a popup on feature selection. To be notified on feature
selection register a listener on the layer's featureselected event.
featureselected listeners receive an object with a feature property
referencing the selected feature. This is shown in the example Arnd
pointed you to. Eric

2008/10/28, Indika Tantrigoda <indika85 at gmail.com>:

> Thanks for the reply.
>
> It seems that when I click within the marker, I get different lon, lat
> values.
>
> Is it necessary to bind the markers to something ?
>
> Also with the extractAttributes:true, how can I access the attributes of
the
> feature ?
>
> Regards,
> Indika
>
> 2008/10/27 Arnd Wippermann <arnd.wippermann at web.de>
>
>>  you can use a select control for the wfs layer.
>>
>> http://openlayers.org/dev/examples/select-feature-openpopup.html
>>
>> If you have load the wfs layer with extractAttributes: true, then your
wfs
>> data are saved in the attributes of the features.
>>
>> Arnd Wippermann
>>
>>  ------------------------------
>> *Von:* users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
>> *Im Auftrag von *Indika Tantrigoda
>> *Gesendet:* Montag, 27. Oktober 2008 16:17
>> *An:* OpenLayers users mailing list
>> *Betreff:* [OpenLayers-Users] WFS Layers, Markers, Popups
>>
>> Hi,
>> I have a wfs layer that displays points on my map, using markers.
>> I would like to have a popup that displays data regarding the point which
>> would get activated for a click event.
>>
>> I tried the following but, it seems to return all the data regarding the
>> wfs layer, not the single point, irrespective of
>> where I click on the map.
>>
>>  wfs_cities.events.register('click', map, function (e) {
>>                 document.getElementById('nodelist').innerHTML =
>> "Loading...
>> please wait...";
>>                 var url =  map.layers[2].getFullRequestString(
>>                     {
>>                         REQUEST: "GetFeature",
>>                         EXCEPTIONS: "application/vnd.ogc.se_xml",
>>                         BBOX: map.getExtent().toBBOX(),
>>                         X: e.xy.x,
>>                         Y: e.xy.y,
>>                         INFO_FORMAT: 'text/html',
>>                         QUERY_LAYERS: map.layers[2].params.LAYERS,
>>                         FEATURE_COUNT: 50,
>>                         WIDTH: map.size.w,
>>                         HEIGHT: map.size.h
>>                     },
>>                     "http://localhost:8080/geoserver/wfs"
>>                 );
>>
>> Any ideas how I can get around this ?
>>
>> Thanks in advance.
>>
>> Regards,
>> Indika
>>
>



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081028/2cf0cd55/attachment.html


More information about the Users mailing list