0

I allow the user to draw features, and on drawend I need to make a request to my WFS service to return features.

I can get the WFS to return data based on the extent using:

let vectorSource = new VectorSource({
                format: new GeoJSON(),
                url: function(extent) {
                    return 'https://example/wfs' +
                        '?key=key' +
                        '&SERVICE=WFS' +
                        '&REQUEST=GetFeature' +
                        '&TYPENAMES=data_point' +
                        '&SRSNAME=urn:ogc:def:crs:EPSG::27700' +
                        '&BBOX=' + extent.join(',') + ',urn:ogc:def:crs:EPSG::27700';

                },
                strategy: bboxStrategy
            });

However I cannot get these features to display despite injecting this source into the layer, and the layer onto the map.

I can get all features to display using something along the lines of:

        fetch('example/wfs?key=key', {
        method: 'POST',
        body: new XMLSerializer().serializeToString(featureRequest)
    }).then(function(response) {
        return response.text();
    }).then(function(gml) {
        console.log(gml);
        let features = new GML().readFeatures(gml);
        vectorSource.addFeatures(features);
        map.getView().fit(vectorSource.getExtent());
    });

However I cannot for the life of me work out how to restrict the data requested in this request to a bounding box of say four coordinates.

Potentially this could be a limitless pointed geometry that will act as a cookie cutter for data displayed.

My searches have yielded no results.

Phish
  • 774
  • 3
  • 11
  • 27
  • In your first snippet using `format: new GeoJSON()` will need `&outputFormat=application/json` in the url (and a server which supports it). Otherwise `format: new WFS()` should suffice if both the view and data are EPSG:27700 – Mike Jul 13 '19 at 16:13
  • @Mike thank you for getting back to me, and on a a Saturday no less. I actually wrote this up here incorrectly as my WFS serves me GML. I will try the WFS and see what happens. Thank you. – Phish Jul 13 '19 at 19:15
  • @Mike so going with the former snippet, I have changed and attempted to set the format as GML and WFS and although it throws no errors, and looking at the request, these are sending back correctly formed GML within my extent (to be changed to coords for a bbox), the data is not displayed on the layer! – Phish Jul 13 '19 at 19:20
  • @Mike I suppose my issue is, with the first code snippet I can get the right data back from the server but it does not get displayed on my map, the second displays the data but I cannot work out how to only request data from within a bounding box. – Phish Jul 13 '19 at 19:35

1 Answers1

0

You seem to be very close in both cases.

In the top snippet you could log any features and their geometry to confirm whether any are being loaded, and if so why they don't appear where expected (e.g. geometry coordinates are lon/lat values when view is EPSG:27700)

setTimeout(function(){
  console.log(vectorSource.getFeatures());
  vectorSource.getFeatures().forEach(function(feature){console.log(feature.getGeometry());});
}, 10000);

In the second snippet if everything else is working I presume you will need to add the bbox array to the featureRequest object used in the serializeToString call, or change the way you pass the data.

Here is a similar WFS example where you can use view source. It works equally well with WFS or GML as the format. When the view is the same projection as the data http://mikenunn.16mb.com/demo/wfs-italy-4326.html using a url function is sufficient. But unlike formats such as GeoJSON OpenLayers doesn't automatically reproject features to view projection for GML or WFS. With a different projection http://mikenunn.16mb.com/demo/wfs-italy-3857.html a loader function is needed to reproject the feature geometry, otherwise Italian provinces end up in the Atlantic within few meters of [0,0].

Mike
  • 16,042
  • 2
  • 14
  • 30
  • Thank you, I think the former snipped is my way to go. The second snippet became a problem when understanding how to use the filter options. The problem still persists with the first, although in my network tab I am definitely getting the correct gml returned it is definitely not being applied to the layer! Running the get features at any stage of my application returns an empty array. – Phish Jul 15 '19 at 11:08
  • is there a possibility you may be able to test displaying lineStrings with OL5? We have now extensively tested this and we cannot for the life of us display LineStrings on a vector layer using the first method and are leaning towards an OL bug. – Phish Jul 17 '19 at 07:31
  • To confirm, features are being added to the layer but only points and poly's are displayed. – Phish Jul 17 '19 at 07:32
  • If you log the loaded geometry do you see any LineStrings? It may be your GML isn't Simple Features compliant http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/1.0.0/gmlsf.xsd (e.g. LineString is defined as array of gml:pos instead of a single gml:posList) or there may be a styling issue. LineStrings will not display unless the style includes a stroke. – Mike Jul 17 '19 at 15:29