1
votes

I am trying to display a geometry trough a WFS in OpenLayer 4. The problem is that using the following snippet of code.. The request is succesfull, I can see the XML (wfs gml) data in the response (using firebug) but the polygons are not visible. It seems that the readFeatures method cannot parse the XML (gml) file. Is there any way of specifying the xml (gml) element in the readFeatures method in order to read the geometry?

...
...
    var vectorSource = new ol.source.Vector({
        format: new ol.format.WFS({
          featureNS: 'http://www.opengis.net/wfs/2.0',
          featureType: 'Test'
        }),
        loader: function(extent, resolution, projection) {
          var url = 'http://localhost/deegree-webservices-3.3.20/services/test_WFS?'+
            'service=WFS&request=GetFeature&'+
            'version=2.0.0&typeNames=aaa:Testg&count=30&'+
            'srsname=EPSG:3857';
          $.ajax({
            url: url
          })
          .done(function(response) {
            vectorSource.addFeatures((new ol.format.WFS()).readFeatures(response));
          });
        },
        projection: 'EPSG:3857'
      });
...
...
Are you sure that you are using the correct format in the ajax callback? You have defined a format on the source class, but in the callback you are not using that source and instead creating a new one.spottexj
That is like a static method in Java. Is just to access to the "readFeatures" method. I don't think the problem is there because with another "standard" GML the map is working. I think that the problem is my WFS is composed of coplex nested elements before the gml:Polygon emelemntsuser9370976
My apologies, seems I did not read the question correctly. If you're using a custom GML format the standard ol formats will not work. Could you post an example of what your data looks like?spottexj
can you add a snippet of the GML you get back?Ian Turton