From 8a5fb286b6321ee33c48ed3d86eed35c251bf88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Dub=C3=A9?= Date: Tue, 21 Mar 2017 08:56:32 -0400 Subject: [PATCH 1/3] Add writeFilter method to WFS format --- src/ol/format/wfs.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ol/format/wfs.js b/src/ol/format/wfs.js index dcba956592..892fbe7caa 100644 --- a/src/ol/format/wfs.js +++ b/src/ol/format/wfs.js @@ -782,6 +782,21 @@ ol.format.WFS.GETFEATURE_SERIALIZERS_ = { }; +/** + * Encode filter as WFS `Filter` and return the Node. + * + * @param {ol.format.filter.Filter} filter Filter. + * @return {Node} Result. + * @api + */ +ol.format.WFS.writeFilter = function(filter) { + var child = ol.xml.createElementNS(ol.format.WFS.OGCNS, 'Filter'); + var objectStack = []; + ol.format.WFS.writeFilterCondition_(child, filter, objectStack); + return child; +}; + + /** * @param {Node} node Node. * @param {Array.} featureTypes Feature types. From ef1033dffc1ed32f369f25b9abb53a30d4952312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Dub=C3=A9?= Date: Tue, 21 Mar 2017 09:19:07 -0400 Subject: [PATCH 2/3] Test for ol.format.WFS.writerFilter method --- test/spec/ol/format/wfs.test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index bb65e998fd..843a2b1c5a 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -1014,4 +1014,29 @@ describe('ol.format.WFS', function() { }); + describe('when writing out a WFS Filter', function() { + it('creates a filter', function() { + var text = + '' + + ' ' + + ' ' + + ' name' + + ' Mississippi*' + + ' ' + + ' ' + + ' waterway' + + ' riverbank' + + ' ' + + ' ' + + ''; + var serialized = ol.format.WFS.writeFilter( + ol.format.filter.and( + ol.format.filter.like('name', 'Mississippi*'), + ol.format.filter.equalTo('waterway', 'riverbank') + ) + ); + expect(serialized).to.xmleql(ol.xml.parse(text)); + }); + }); + }); From 827fabc84957c0d0dfc725fd09552a5ade9a9872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Dub=C3=A9?= Date: Tue, 21 Mar 2017 10:15:32 -0400 Subject: [PATCH 3/3] Apply reviewer's comments --- src/ol/format/wfs.js | 3 +-- test/spec/ol/format/wfs.test.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ol/format/wfs.js b/src/ol/format/wfs.js index 892fbe7caa..5ad2431144 100644 --- a/src/ol/format/wfs.js +++ b/src/ol/format/wfs.js @@ -791,8 +791,7 @@ ol.format.WFS.GETFEATURE_SERIALIZERS_ = { */ ol.format.WFS.writeFilter = function(filter) { var child = ol.xml.createElementNS(ol.format.WFS.OGCNS, 'Filter'); - var objectStack = []; - ol.format.WFS.writeFilterCondition_(child, filter, objectStack); + ol.format.WFS.writeFilterCondition_(child, filter, []); return child; }; diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index 843a2b1c5a..89b76fa652 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -1017,7 +1017,7 @@ describe('ol.format.WFS', function() { describe('when writing out a WFS Filter', function() { it('creates a filter', function() { var text = - '' + + '' + ' ' + ' ' + ' name' +