From 7261e255660fde5ac005bea2f738d44f4a67c9a0 Mon Sep 17 00:00:00 2001 From: Jannes Bolling Date: Wed, 14 Oct 2020 19:07:31 +0200 Subject: [PATCH] fix distanceWithin for WFS2.0 --- src/ol/format/WFS.js | 6 ++++- test/spec/ol/format/wfs.test.js | 46 +++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index 86865fe477..e433aba72a 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -1087,7 +1087,11 @@ function writeDWithinFilter(node, filter, objectStack) { writeSpatialFilter(node, filter, objectStack); const distance = createElementNS(getFilterNS(version), 'Distance'); writeStringTextNode(distance, filter.distance.toString()); - distance.setAttribute('uom', filter.unit); + if (version === '2.0.0') { + distance.setAttribute('uom', filter.unit); + } else { + distance.setAttribute('units', filter.unit); + } node.appendChild(distance); } diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index 2607bd51c2..4881d588c1 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -687,7 +687,7 @@ describe('ol.format.WFS', function () { expect(serialized.firstElementChild).to.xmleql(parse(text)); }); - it('creates a dwithin filter', function () { + it('creates a dwithin filter for WFS 1.x', function () { const text = '' + ' ' + ' ' + - ' 10' + + ' 10' + ' ' + ' ' + ''; @@ -729,6 +729,48 @@ describe('ol.format.WFS', function () { expect(serialized.firstElementChild).to.xmleql(parse(text)); }); + it('creates a dwithin filter for WFS 2.0', function () { + const text = + '' + + ' ' + + ' ' + + ' the_geom' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 10 20 10 25 15 25 15 20 10 20' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 10' + + ' ' + + ' ' + + ''; + const serialized = new WFS({version: '2.0.0'}).writeGetFeature({ + srsName: 'EPSG:4326', + featureTypes: ['area'], + filter: dwithinFilter( + 'the_geom', + new Polygon([ + [ + [10, 20], + [10, 25], + [15, 25], + [15, 20], + [10, 20], + ], + ]), + 10, + 'm' + ), + }); + expect(serialized.firstElementChild).to.xmleql(parse(text)); + }); + it('creates During property filter', function () { const text = '