From 0484e45c892423af5c9af31101b8b066584afe5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Harrtell?= Date: Tue, 11 Aug 2020 15:46:40 +0200 Subject: [PATCH] Fix WFS 2.0.0 GetFeature response parsing --- src/ol/format/WFS.js | 14 +- test/spec/ol/format/wfs.test.js | 133 ++++++++++++++---- test/spec/ol/format/wfs/2.0.0/GetFeature.xml | 20 --- test/spec/ol/format/wfs/2.0.0/GetFeature2.xml | 41 ------ 4 files changed, 117 insertions(+), 91 deletions(-) delete mode 100644 test/spec/ol/format/wfs/2.0.0/GetFeature.xml delete mode 100644 test/spec/ol/format/wfs/2.0.0/GetFeature2.xml diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index a2985a97dd..b31fb5b120 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -40,6 +40,9 @@ const FEATURE_COLLECTION_PARSERS = { 'bounds' ), }, + 'http://www.opengis.net/wfs/2.0': { + 'member': makeArrayPusher(GMLBase.prototype.readFeaturesInternal), + }, }; /** @@ -326,12 +329,15 @@ class WFS extends XMLFeature { assign(context, this.getReadOptions(node, opt_options ? opt_options : {})); const objectStack = [context]; - this.gmlFormat_.FEATURE_COLLECTION_PARSERS[GMLNS][ - 'featureMember' - ] = makeArrayPusher(GMLBase.prototype.readFeaturesInternal); + let featuresNS; + if (this.version_ === '2.0.0') { + featuresNS = FEATURE_COLLECTION_PARSERS; + } else { + featuresNS = this.gmlFormat_.FEATURE_COLLECTION_PARSERS; + } let features = pushParseAndPop( [], - this.gmlFormat_.FEATURE_COLLECTION_PARSERS, + featuresNS, node, objectStack, this.gmlFormat_ diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index b8c5fd5e9b..c7aaf5fe89 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -1387,28 +1387,113 @@ describe('ol.format.WFS', function () { }); describe('WFS 2.0.0', function () { - let getFeatureXml; - let getFeatureXml2; + const geometryXml = ` + + + + + 590431 4915204 590430 + 4915205 590429 4915204 590430 + 4915203 590431 4915204 + + + + `.trim(); + + const getFeatureSimpleXml = ` + + + + + + + + + + `.trim(); + + const getFeatureComplexXml = ` + + + + + + + + sf:the_geom + ${geometryXml} + + + + + + `.trim(); + + const getFeatureSimpleXmlResponse = ` + + + + + + + 590529 4914625 + + + 3 + Beetle site + + + + `.trim(); before(function (done) { proj4.defs( 'http://www.opengis.net/def/crs/EPSG/0/26713', '+proj=utm +zone=13 +ellps=clrk66 +datum=NAD27 +units=m +no_defs' ); + proj4.defs( + 'urn:ogc:def:crs:EPSG::26713', + '+proj=utm +zone=13 +ellps=clrk66 +datum=NAD27 +units=m +no_defs' + ); register(proj4); - afterLoadText('spec/ol/format/wfs/2.0.0/GetFeature2.xml', function (xml) { - getFeatureXml2 = xml; - afterLoadText('spec/ol/format/wfs/2.0.0/GetFeature.xml', function ( - xml - ) { - getFeatureXml = xml; - done(); - }); - }); + done(); }); after(function () { delete proj4.defs['http://www.opengis.net/def/crs/EPSG/0/26713']; + delete proj4.defs['urn:ogc:def:crs:EPSG::26713']; clearAllProjections(); addCommon(); }); @@ -1424,26 +1509,14 @@ describe('ol.format.WFS', function () { featurePrefix: 'sf', filter, }); - expect(serialized).to.xmleql(parse(getFeatureXml)); + expect(serialized).to.xmleql(parse(getFeatureSimpleXml)); }); it('can writeGetFeature query with negated disjoint spatial filter', function () { const wfs = new WFS({ version: '2.0.0', }); - const geometryNode = parse( - ` - - - - 590431 4915204 590430 - 4915205 590429 4915204 590430 - 4915203 590431 4915204 - - - ` - ); + const geometryNode = parse(geometryXml); const geometry = new GML32().readGeometryElement(geometryNode, [{}]); const filter = notFilter(disjointFilter('sf:the_geom', geometry)); const serialized = wfs.writeGetFeature({ @@ -1452,7 +1525,15 @@ describe('ol.format.WFS', function () { featurePrefix: 'sf', filter, }); - expect(serialized).to.xmleql(parse(getFeatureXml2)); + expect(serialized).to.xmleql(parse(getFeatureComplexXml)); + }); + + it('can parse a basic GetFeature response', function () { + const wfs = new WFS({ + version: '2.0.0', + }); + const features = wfs.readFeatures(parse(getFeatureSimpleXmlResponse)); + expect(features.length).to.be(1); }); }); }); diff --git a/test/spec/ol/format/wfs/2.0.0/GetFeature.xml b/test/spec/ol/format/wfs/2.0.0/GetFeature.xml deleted file mode 100644 index 20e1b43f8c..0000000000 --- a/test/spec/ol/format/wfs/2.0.0/GetFeature.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - diff --git a/test/spec/ol/format/wfs/2.0.0/GetFeature2.xml b/test/spec/ol/format/wfs/2.0.0/GetFeature2.xml deleted file mode 100644 index 2e7add1b68..0000000000 --- a/test/spec/ol/format/wfs/2.0.0/GetFeature2.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - sf:the_geom - - - - - - 590431 4915204 590430 - 4915205 590429 4915204 590430 - 4915203 590431 4915204 - - - - - - - -