I'm trying to get features from WFS service, this service using stored queries. I've managed to retrieve data both with axios and XMLHttpRequest. But the problem in the reading features and showing them on my layer.

My sample code:

let vector; 

let xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
    var format = new GML3();
    var xmlDoc = xmlhttp.responseXML;
    vector = new Vector({
        source: new VectorSource({
            format: format

    for (var i = 1; i < xmlDoc.children[0].children.length; i++) {

        console.log('xmlDoc.children[0].children[i] >>> ', xmlDoc.children[0].children[i]);
        let features = format.readFeatures(xmlDoc.children[0].children[i]);

        console.log('features >>> ', features);
        // features.getGeometry().transform('EPSG:4326', 'EPSG:3857');

    // map.getView().fit(vector.getSource().getExtent(), map.getSize())


// trigger the GET request

So when i run this code, console tells that "Uncaught TypeError: feature.getId is not a function". I'm using OpenLayers 4. Could anyone explain what happening ? As i understood there is a class Feature , which has set and get id's methods. Moreover is it possible to convert my GML response into the geoJson , maybe it will be easier to work with ?

  • To answer your second question, your WFS may offer GeoJSON as an output format, so possibly no reason to do a conversion. – nmtoken May 17 '18 at 12:40
  • What WFS version are you using and what version GML is returned? Is it simple feature WFS? – nmtoken May 17 '18 at 12:42
  • No, it supports only <ows:Operation name="GetFeature"> <ows:DCP> <ows:Parameter name="outputFormat"> <ows:AllowedValues> <ows:Value>text/xml; subtype=gml/3.2</ows:Value> <ows:Value>text/xml; version=3.2</ows:Value> <ows:Value>application/gml+xml; subtype=gml/3.2</ows:Value> <ows:Value>application/gml+xml; version=3.2</ows:Value> </ows:AllowedValues> </ows:Parameter> </ows:Operation> – Vlad.d May 17 '18 at 12:44
  • WFS version = 2.0.0 because <ows:Parameter name="version"> <ows:AllowedValues> <ows:Value>2.0.0</ows:Value> </ows:AllowedValues> </ows:Parameter – Vlad.d May 17 '18 at 12:47
  • I dont know how to identify simple or not simple WFS , i really dont know what to do with this responses, i tried a lot of ways , and cant figure out how to use it, or transform it into JSON – Vlad.d May 17 '18 at 12:51

Your Answer

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

Browse other questions tagged or ask your own question.