[GIS] Add features to vector layer from WFS query

geoserveropenlayers-2wfs

I am trying to add the resulting WFS features (xml format) to my selected items vector layer but can't get it to work.

I am querying my WFS layer with the following:

    showFeatureLink.on('click', function() {
        OpenLayers.Request.GET({
            url: 'http://1.2.3.4:8080/geoserver/wfs',
            params: {
                service: 'WFS',
                version: '1.1.0',
                request: 'GetFeature',
                typeName: 'Mylines:WebLayer1'
            },
            proxy: "../gis/geoserver.seam?url=",
            success: function(request) {
                var features = new OpenLayers.Format.WFS().read(response.responseText);
                selected_items.addFeatures(features);
                map.zoomToExtent(selected_items.getDataExtent());
            },
    });

The XML returned contains all the relevant information so there's no problem there.

<wfs:FeatureCollection numberOfFeatures="1000"...... />

I seem to be falling at the last hurdle, I've googled for some time but can't get to the bottom of it, your help would be appreciated!

Thanks

Best Answer

So I got to the bottom of it thanks to this post Sending xml post request to geoserver

The answer is to use a GML object and convert this to a list of features using the following code in the success block:

success: function(response) {
    var gmlReader = new OpenLayers.Format.GML({ extractAttributes: true });
    var features = gmlReader.read(response.responseText);
    selected_items.addFeatures(features);
    map.zoomToExtent(selected_items.getDataExtent());
}

Thanks for looking...

Related Question