Merge pull request #11890 from walkermatt/wfs_filter_version
Fix WFS writeFilter
This commit is contained in:
@@ -1323,12 +1323,13 @@ function writeTimeInstant(node, time) {
|
||||
* Encode filter as WFS `Filter` and return the Node.
|
||||
*
|
||||
* @param {import("./filter/Filter.js").default} filter Filter.
|
||||
* @param {string} version Version.
|
||||
* @param {string} opt_version WFS version. If not provided defaults to '1.1.0'
|
||||
* @return {Node} Result.
|
||||
* @api
|
||||
*/
|
||||
export function writeFilter(filter, version) {
|
||||
const child = createElementNS(OGCNS[version], 'Filter');
|
||||
export function writeFilter(filter, opt_version) {
|
||||
const version = opt_version || '1.1.0';
|
||||
const child = createElementNS(getFilterNS(version), 'Filter');
|
||||
const context = {
|
||||
node: child,
|
||||
};
|
||||
|
||||
@@ -1457,20 +1457,33 @@ describe('ol.format.WFS', function () {
|
||||
});
|
||||
|
||||
describe('when writing out a WFS Filter', function () {
|
||||
it('creates a filter', function () {
|
||||
const text =
|
||||
'<Filter xmlns="http://www.opengis.net/ogc">' +
|
||||
' <And>' +
|
||||
' <PropertyIsLike wildCard="*" singleChar="." escapeChar="!">' +
|
||||
' <PropertyName>name</PropertyName>' +
|
||||
' <Literal>Mississippi*</Literal>' +
|
||||
' </PropertyIsLike>' +
|
||||
' <PropertyIsEqualTo>' +
|
||||
' <PropertyName>waterway</PropertyName>' +
|
||||
' <Literal>riverbank</Literal>' +
|
||||
' </PropertyIsEqualTo>' +
|
||||
' </And>' +
|
||||
'</Filter>';
|
||||
const wfs1Filter =
|
||||
'<Filter xmlns="http://www.opengis.net/ogc">' +
|
||||
' <And>' +
|
||||
' <PropertyIsLike wildCard="*" singleChar="." escapeChar="!">' +
|
||||
' <PropertyName>name</PropertyName>' +
|
||||
' <Literal>Mississippi*</Literal>' +
|
||||
' </PropertyIsLike>' +
|
||||
' <PropertyIsEqualTo>' +
|
||||
' <PropertyName>waterway</PropertyName>' +
|
||||
' <Literal>riverbank</Literal>' +
|
||||
' </PropertyIsEqualTo>' +
|
||||
' </And>' +
|
||||
'</Filter>';
|
||||
const wfs2Filter =
|
||||
'<Filter xmlns="http://www.opengis.net/fes/2.0">' +
|
||||
' <And>' +
|
||||
' <PropertyIsLike wildCard="*" singleChar="." escapeChar="!">' +
|
||||
' <ValueReference>name</ValueReference>' +
|
||||
' <Literal>Mississippi*</Literal>' +
|
||||
' </PropertyIsLike>' +
|
||||
' <PropertyIsEqualTo>' +
|
||||
' <ValueReference>waterway</ValueReference>' +
|
||||
' <Literal>riverbank</Literal>' +
|
||||
' </PropertyIsEqualTo>' +
|
||||
' </And>' +
|
||||
'</Filter>';
|
||||
it('creates a WFS 1.x.x filter', function () {
|
||||
const serialized = writeFilter(
|
||||
andFilter(
|
||||
likeFilter('name', 'Mississippi*'),
|
||||
@@ -1478,7 +1491,26 @@ describe('ol.format.WFS', function () {
|
||||
),
|
||||
'1.1.0'
|
||||
);
|
||||
expect(serialized).to.xmleql(parse(text));
|
||||
expect(serialized).to.xmleql(parse(wfs1Filter));
|
||||
});
|
||||
it('defaults to creating a WFS 1.x.x filter if no version specified', function () {
|
||||
const serialized = writeFilter(
|
||||
andFilter(
|
||||
likeFilter('name', 'Mississippi*'),
|
||||
equalToFilter('waterway', 'riverbank')
|
||||
)
|
||||
);
|
||||
expect(serialized).to.xmleql(parse(wfs1Filter));
|
||||
});
|
||||
it('creates a WFS 2.x.x filter', function () {
|
||||
const serialized = writeFilter(
|
||||
andFilter(
|
||||
likeFilter('name', 'Mississippi*'),
|
||||
equalToFilter('waterway', 'riverbank')
|
||||
),
|
||||
'2.0.0'
|
||||
);
|
||||
expect(serialized).to.xmleql(parse(wfs2Filter));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user