diff --git a/src/ol/format/wfs.js b/src/ol/format/wfs.js index dcba956592..5ad2431144 100644 --- a/src/ol/format/wfs.js +++ b/src/ol/format/wfs.js @@ -782,6 +782,20 @@ 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'); + ol.format.WFS.writeFilterCondition_(child, filter, []); + return child; +}; + + /** * @param {Node} node Node. * @param {Array.} featureTypes Feature types. diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index bb65e998fd..89b76fa652 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)); + }); + }); + });