2

I'm trying to add the features I get from a WFS query using the WFS protocol. But something doesn't work.

I have looked at other posts with people having similar problems, but their solution doesn't fit with my problem.

I have tried:

var gmlReader = new OpenLayers.Format.GML({ extractAttributes: true });
var features = gmlReader.read(evtResponse.responseText);
markerVectorLayer.addFeatures([features])

But then I receive a error:

TypeError: a is undefined

...b.push(d)}return b},parseFeature:function(a){for(var b="MultiPolygon Polygon Mul...

OpenLayers.2.13.1.js (line 380)`

When I use console.log to check the features it looks like a perfect FeatureCollection object.

If I loop the response and create polygons from the coordinate points it works, but the performance isn't functional.

What am I doing wrong?

1

Since gmlReader.read(); returns an array, you should try this :

markerVectorLayer.addFeatures(features);

  • Thanks for the reply. Sadly that doesnt do any difference. The same error is returned – Mike001 Jun 11 '14 at 10:29
1

Here is an working example where I get the WFS features and add them to my vector layer:

OpenLayers.Request.GET({
        url: 'http://demo.opengeo.org/geoserver/wfs',
        params: {
            service: 'WFS',
            version: '1.0.0',
            request: 'GetFeature',
            typeName: 'ne_10m_populated_places',
            featureNS: "http://openstreemap.org",
            bbox: '137.9109375,-54.98359375,155.4890625,-28.61640625'
            // using bbox for the request because the layer has a huge amount of features
        },
        //proxy: "/cgi-bin/proxy.cgi?url=",
        success: function (response) {
            var gmlReader = new OpenLayers.Format.GML({
                extractAttributes: true
            });
            var features = gmlReader.read(response.responseText);
            layer.addFeatures(features);

        }
    });

see http://jsfiddle.net/expedio/6115L481/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.