Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to parse WFS reponse using OpenLayers.Format.GML parser. However, an exception thrown in my try-catch block is TypeError: a is undefined. Any pointers as to what I may be doing wrong will be appreciated.

protocol = new OpenLayers.Protocol.WFS({
    version: "1.1.0",
    url: WFS_HOST,
    featureType: "pl",
    featureNS: "ws",
    srsName: "EPSG:900913"
});

wfsLayer = new OpenLayers.Layer.Vector("PE Vector", {
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: protocol
});

var _Callback = function(resp) {
    console.log(resp);
    console.log(resp.error);

    try {
        var gmlParser = new OpenLayers.Format.GML();
        gmlParser.extractAttributes = true;
        var features = gmlParser.read(resp.responseText);

        if(features){
            for(var i = 0; i < features.length; i++) {
                var feature = features[i];
                                    // More operations
            }
        }
    } catch(e) {
        alert("Error: " + e);
    }
};

response = protocol.read({
    maxFeatures: 100,
    callback: _Callback
});

My environment: GeoServer 2.1.3, OpenLayers 2.11, PostGIS 1.5.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I got it working by updating the _Callback variable to:

var _Callback = function(resp) {
    console.log(resp);
    console.log(resp.error);

    try {
        var gmlParser = new OpenLayers.Format.GML.v3();
        gmlParser.extractAttributes = true;
        var features = gmlParser.read(resp.priv.responseXML);

        if(features){
            for(var i = 0; i < features.length; i++) {
                var feature = features[i];
                // TODO: More operations
            }
        }
    } catch(e) {
        alert("Error: " + e);
    }
};
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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