diff --git a/examples/vector-wfs-getfeature.js b/examples/vector-wfs-getfeature.js index 81921ca813..81c61a312d 100644 --- a/examples/vector-wfs-getfeature.js +++ b/examples/vector-wfs-getfeature.js @@ -1,6 +1,10 @@ import Map from '../src/ol/Map.js'; import View from '../src/ol/View.js'; -import _ol_format_filter_ from '../src/ol/format/filter.js'; +import { + equalTo as equalToFilter, + like as likeFilter, + and as andFilter +} from '../src/ol/format/filter.js'; import WFS from '../src/ol/format/WFS.js'; import GeoJSON from '../src/ol/format/GeoJSON.js'; import TileLayer from '../src/ol/layer/Tile.js'; @@ -46,9 +50,9 @@ const featureRequest = new WFS().writeGetFeature({ featurePrefix: 'osm', featureTypes: ['water_areas'], outputFormat: 'application/json', - filter: _ol_format_filter_.and( - _ol_format_filter_.like('name', 'Mississippi*'), - _ol_format_filter_.equalTo('waterway', 'riverbank') + filter: andFilter( + likeFilter('name', 'Mississippi*'), + equalToFilter('waterway', 'riverbank') ) }); diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index a423f27e2d..8230a0cd0c 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -6,7 +6,7 @@ import {assert} from '../asserts.js'; import GML2 from '../format/GML2.js'; import GML3 from '../format/GML3.js'; import GMLBase from '../format/GMLBase.js'; -import _ol_format_filter_ from '../format/filter.js'; +import {and as andFilter, bbox as bboxFilter} from '../format/filter.js'; import XMLFeature from '../format/XMLFeature.js'; import XSD from '../format/XSD.js'; import Geometry from '../geom/Geometry.js'; @@ -959,11 +959,11 @@ WFS.prototype.writeGetFeature = function(options) { if (options.bbox) { assert(options.geometryName, 12); // `options.geometryName` must also be provided when `options.bbox` is set - const bbox = _ol_format_filter_.bbox( + const bbox = bboxFilter( /** @type {string} */ (options.geometryName), options.bbox, options.srsName); if (filter) { // if bbox and filter are both set, combine the two into a single filter - filter = _ol_format_filter_.and(filter, bbox); + filter = andFilter(filter, bbox); } else { filter = bbox; } diff --git a/src/ol/format/filter.js b/src/ol/format/filter.js index 9565523a7c..125496b55c 100644 --- a/src/ol/format/filter.js +++ b/src/ol/format/filter.js @@ -1,24 +1,23 @@ /** * @module ol/format/filter */ -import _ol_format_filter_And_ from '../format/filter/And.js'; -import _ol_format_filter_Bbox_ from '../format/filter/Bbox.js'; -import _ol_format_filter_Contains_ from '../format/filter/Contains.js'; -import _ol_format_filter_During_ from '../format/filter/During.js'; -import _ol_format_filter_EqualTo_ from '../format/filter/EqualTo.js'; -import _ol_format_filter_GreaterThan_ from '../format/filter/GreaterThan.js'; -import _ol_format_filter_GreaterThanOrEqualTo_ from '../format/filter/GreaterThanOrEqualTo.js'; -import _ol_format_filter_Intersects_ from '../format/filter/Intersects.js'; -import _ol_format_filter_IsBetween_ from '../format/filter/IsBetween.js'; -import _ol_format_filter_IsLike_ from '../format/filter/IsLike.js'; -import _ol_format_filter_IsNull_ from '../format/filter/IsNull.js'; -import _ol_format_filter_LessThan_ from '../format/filter/LessThan.js'; -import _ol_format_filter_LessThanOrEqualTo_ from '../format/filter/LessThanOrEqualTo.js'; -import _ol_format_filter_Not_ from '../format/filter/Not.js'; -import _ol_format_filter_NotEqualTo_ from '../format/filter/NotEqualTo.js'; -import _ol_format_filter_Or_ from '../format/filter/Or.js'; -import _ol_format_filter_Within_ from '../format/filter/Within.js'; -const _ol_format_filter_ = {}; +import And from '../format/filter/And.js'; +import Bbox from '../format/filter/Bbox.js'; +import Contains from '../format/filter/Contains.js'; +import During from '../format/filter/During.js'; +import EqualTo from '../format/filter/EqualTo.js'; +import GreaterThan from '../format/filter/GreaterThan.js'; +import GreaterThanOrEqualTo from '../format/filter/GreaterThanOrEqualTo.js'; +import Intersects from '../format/filter/Intersects.js'; +import IsBetween from '../format/filter/IsBetween.js'; +import IsLike from '../format/filter/IsLike.js'; +import IsNull from '../format/filter/IsNull.js'; +import LessThan from '../format/filter/LessThan.js'; +import LessThanOrEqualTo from '../format/filter/LessThanOrEqualTo.js'; +import Not from '../format/filter/Not.js'; +import NotEqualTo from '../format/filter/NotEqualTo.js'; +import Or from '../format/filter/Or.js'; +import Within from '../format/filter/Within.js'; /** @@ -28,10 +27,10 @@ const _ol_format_filter_ = {}; * @returns {!ol.format.filter.And} `` operator. * @api */ -_ol_format_filter_.and = function(conditions) { +export function and(conditions) { const params = [null].concat(Array.prototype.slice.call(arguments)); - return new (Function.prototype.bind.apply(_ol_format_filter_And_, params)); -}; + return new (Function.prototype.bind.apply(And, params)); +} /** @@ -41,10 +40,10 @@ _ol_format_filter_.and = function(conditions) { * @returns {!ol.format.filter.Or} `` operator. * @api */ -_ol_format_filter_.or = function(conditions) { +export function or(conditions) { const params = [null].concat(Array.prototype.slice.call(arguments)); - return new (Function.prototype.bind.apply(_ol_format_filter_Or_, params)); -}; + return new (Function.prototype.bind.apply(Or, params)); +} /** @@ -54,9 +53,9 @@ _ol_format_filter_.or = function(conditions) { * @returns {!ol.format.filter.Not} `` operator. * @api */ -_ol_format_filter_.not = function(condition) { - return new _ol_format_filter_Not_(condition); -}; +export function not(condition) { + return new Not(condition); +} /** @@ -70,9 +69,9 @@ _ol_format_filter_.not = function(condition) { * @returns {!ol.format.filter.Bbox} `` operator. * @api */ -_ol_format_filter_.bbox = function(geometryName, extent, opt_srsName) { - return new _ol_format_filter_Bbox_(geometryName, extent, opt_srsName); -}; +export function bbox(geometryName, extent, opt_srsName) { + return new Bbox(geometryName, extent, opt_srsName); +} /** * Create a `` operator to test whether a geometry-valued property @@ -85,9 +84,9 @@ _ol_format_filter_.bbox = function(geometryName, extent, opt_srsName) { * @returns {!ol.format.filter.Contains} `` operator. * @api */ -_ol_format_filter_.contains = function(geometryName, geometry, opt_srsName) { - return new _ol_format_filter_Contains_(geometryName, geometry, opt_srsName); -}; +export function contains(geometryName, geometry, opt_srsName) { + return new Contains(geometryName, geometry, opt_srsName); +} /** * Create a `` operator to test whether a geometry-valued property @@ -100,9 +99,9 @@ _ol_format_filter_.contains = function(geometryName, geometry, opt_srsName) { * @returns {!ol.format.filter.Intersects} `` operator. * @api */ -_ol_format_filter_.intersects = function(geometryName, geometry, opt_srsName) { - return new _ol_format_filter_Intersects_(geometryName, geometry, opt_srsName); -}; +export function intersects(geometryName, geometry, opt_srsName) { + return new Intersects(geometryName, geometry, opt_srsName); +} /** * Create a `` operator to test whether a geometry-valued property @@ -115,9 +114,9 @@ _ol_format_filter_.intersects = function(geometryName, geometry, opt_srsName) { * @returns {!ol.format.filter.Within} `` operator. * @api */ -_ol_format_filter_.within = function(geometryName, geometry, opt_srsName) { - return new _ol_format_filter_Within_(geometryName, geometry, opt_srsName); -}; +export function within(geometryName, geometry, opt_srsName) { + return new Within(geometryName, geometry, opt_srsName); +} /** @@ -129,9 +128,9 @@ _ol_format_filter_.within = function(geometryName, geometry, opt_srsName) { * @returns {!ol.format.filter.EqualTo} `` operator. * @api */ -_ol_format_filter_.equalTo = function(propertyName, expression, opt_matchCase) { - return new _ol_format_filter_EqualTo_(propertyName, expression, opt_matchCase); -}; +export function equalTo(propertyName, expression, opt_matchCase) { + return new EqualTo(propertyName, expression, opt_matchCase); +} /** @@ -143,9 +142,9 @@ _ol_format_filter_.equalTo = function(propertyName, expression, opt_matchCase) { * @returns {!ol.format.filter.NotEqualTo} `` operator. * @api */ -_ol_format_filter_.notEqualTo = function(propertyName, expression, opt_matchCase) { - return new _ol_format_filter_NotEqualTo_(propertyName, expression, opt_matchCase); -}; +export function notEqualTo(propertyName, expression, opt_matchCase) { + return new NotEqualTo(propertyName, expression, opt_matchCase); +} /** @@ -156,9 +155,9 @@ _ol_format_filter_.notEqualTo = function(propertyName, expression, opt_matchCase * @returns {!ol.format.filter.LessThan} `` operator. * @api */ -_ol_format_filter_.lessThan = function(propertyName, expression) { - return new _ol_format_filter_LessThan_(propertyName, expression); -}; +export function lessThan(propertyName, expression) { + return new LessThan(propertyName, expression); +} /** @@ -169,9 +168,9 @@ _ol_format_filter_.lessThan = function(propertyName, expression) { * @returns {!ol.format.filter.LessThanOrEqualTo} `` operator. * @api */ -_ol_format_filter_.lessThanOrEqualTo = function(propertyName, expression) { - return new _ol_format_filter_LessThanOrEqualTo_(propertyName, expression); -}; +export function lessThanOrEqualTo(propertyName, expression) { + return new LessThanOrEqualTo(propertyName, expression); +} /** @@ -182,9 +181,9 @@ _ol_format_filter_.lessThanOrEqualTo = function(propertyName, expression) { * @returns {!ol.format.filter.GreaterThan} `` operator. * @api */ -_ol_format_filter_.greaterThan = function(propertyName, expression) { - return new _ol_format_filter_GreaterThan_(propertyName, expression); -}; +export function greaterThan(propertyName, expression) { + return new GreaterThan(propertyName, expression); +} /** @@ -195,9 +194,9 @@ _ol_format_filter_.greaterThan = function(propertyName, expression) { * @returns {!ol.format.filter.GreaterThanOrEqualTo} `` operator. * @api */ -_ol_format_filter_.greaterThanOrEqualTo = function(propertyName, expression) { - return new _ol_format_filter_GreaterThanOrEqualTo_(propertyName, expression); -}; +export function greaterThanOrEqualTo(propertyName, expression) { + return new GreaterThanOrEqualTo(propertyName, expression); +} /** @@ -208,9 +207,9 @@ _ol_format_filter_.greaterThanOrEqualTo = function(propertyName, expression) { * @returns {!ol.format.filter.IsNull} `` operator. * @api */ -_ol_format_filter_.isNull = function(propertyName) { - return new _ol_format_filter_IsNull_(propertyName); -}; +export function isNull(propertyName) { + return new IsNull(propertyName); +} /** @@ -223,9 +222,9 @@ _ol_format_filter_.isNull = function(propertyName) { * @returns {!ol.format.filter.IsBetween} `` operator. * @api */ -_ol_format_filter_.between = function(propertyName, lowerBoundary, upperBoundary) { - return new _ol_format_filter_IsBetween_(propertyName, lowerBoundary, upperBoundary); -}; +export function between(propertyName, lowerBoundary, upperBoundary) { + return new IsBetween(propertyName, lowerBoundary, upperBoundary); +} /** @@ -244,11 +243,11 @@ _ol_format_filter_.between = function(propertyName, lowerBoundary, upperBoundary * @returns {!ol.format.filter.IsLike} `` operator. * @api */ -_ol_format_filter_.like = function(propertyName, pattern, +export function like(propertyName, pattern, opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) { - return new _ol_format_filter_IsLike_(propertyName, pattern, + return new IsLike(propertyName, pattern, opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase); -}; +} /** @@ -260,7 +259,6 @@ _ol_format_filter_.like = function(propertyName, pattern, * @returns {!ol.format.filter.During} `` operator. * @api */ -_ol_format_filter_.during = function(propertyName, begin, end) { - return new _ol_format_filter_During_(propertyName, begin, end); -}; -export default _ol_format_filter_; +export function during(propertyName, begin, end) { + return new During(propertyName, begin, end); +} diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index f6ce58026b..c34fe4e37c 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -1,7 +1,24 @@ import Feature from '../../../../src/ol/Feature.js'; import GML2 from '../../../../src/ol/format/GML2.js'; import WFS from '../../../../src/ol/format/WFS.js'; -import _ol_format_filter_ from '../../../../src/ol/format/filter.js'; +import { + and as andFilter, + bbox as bboxFilter, + between as betweenFilter, + contains as containsFilter, + during as duringFilter, + equalTo as equalToFilter, + greaterThan as greaterThanFilter, + greaterThanOrEqualTo as greaterThanOrEqualToFilter, + intersects as intersectsFilter, + isNull as isNullFilter, + lessThan as lessThanFilter, + lessThanOrEqualTo as lessThanOrEqualToFilter, + like as likeFilter, + not as notFilter, + or as orFilter, + within as withinFilter +} from '../../../../src/ol/format/filter.js'; import LineString from '../../../../src/ol/geom/LineString.js'; import MultiLineString from '../../../../src/ol/geom/MultiLineString.js'; import MultiPoint from '../../../../src/ol/geom/MultiPoint.js'; @@ -306,7 +323,7 @@ describe('ol.format.WFS', function() { featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: _ol_format_filter_.equalTo('name', 'New York', false) + filter: equalToFilter('name', 'New York', false) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); @@ -334,9 +351,9 @@ describe('ol.format.WFS', function() { featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: _ol_format_filter_.or( - _ol_format_filter_.equalTo('name', 'New York'), - _ol_format_filter_.equalTo('area', 1234)) + filter: orFilter( + equalToFilter('name', 'New York'), + equalToFilter('area', 1234)) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); @@ -376,14 +393,14 @@ describe('ol.format.WFS', function() { featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: _ol_format_filter_.or( - _ol_format_filter_.and( - _ol_format_filter_.greaterThan('area', 100), - _ol_format_filter_.greaterThanOrEqualTo('pop', 20000) + filter: orFilter( + andFilter( + greaterThanFilter('area', 100), + greaterThanOrEqualToFilter('pop', 20000) ), - _ol_format_filter_.and( - _ol_format_filter_.lessThan('area', 100), - _ol_format_filter_.lessThanOrEqualTo('pop', 20000) + andFilter( + lessThanFilter('area', 100), + lessThanOrEqualToFilter('pop', 20000) ) ) }); @@ -408,7 +425,7 @@ describe('ol.format.WFS', function() { featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: _ol_format_filter_.between('area', 100, 1000) + filter: betweenFilter('area', 100, 1000) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); @@ -429,7 +446,7 @@ describe('ol.format.WFS', function() { featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: _ol_format_filter_.isNull('area') + filter: isNullFilter('area') }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); @@ -451,7 +468,7 @@ describe('ol.format.WFS', function() { featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: _ol_format_filter_.like('name', 'New*') + filter: likeFilter('name', 'New*') }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); @@ -473,7 +490,7 @@ describe('ol.format.WFS', function() { featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: _ol_format_filter_.like('name', 'New*', '*', '.', '!', false) + filter: likeFilter('name', 'New*', '*', '.', '!', false) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); @@ -497,7 +514,7 @@ describe('ol.format.WFS', function() { featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: _ol_format_filter_.not(_ol_format_filter_.equalTo('name', 'New York')) + filter: notFilter(equalToFilter('name', 'New York')) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); @@ -533,10 +550,10 @@ describe('ol.format.WFS', function() { featureNS: 'http://www.openplans.org/topp', featurePrefix: 'topp', featureTypes: ['states'], - filter: _ol_format_filter_.and( - _ol_format_filter_.equalTo('name', 'New York'), - _ol_format_filter_.bbox('the_geom', [1, 2, 3, 4], 'urn:ogc:def:crs:EPSG::4326'), - _ol_format_filter_.greaterThan('population', 2000000) + filter: andFilter( + equalToFilter('name', 'New York'), + bboxFilter('the_geom', [1, 2, 3, 4], 'urn:ogc:def:crs:EPSG::4326'), + greaterThanFilter('population', 2000000) ) }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); @@ -565,7 +582,7 @@ describe('ol.format.WFS', function() { const serialized = new WFS().writeGetFeature({ srsName: 'EPSG:4326', featureTypes: ['area'], - filter: _ol_format_filter_.contains( + filter: containsFilter( 'the_geom', new Polygon([[ [10, 20], @@ -602,7 +619,7 @@ describe('ol.format.WFS', function() { const serialized = new WFS().writeGetFeature({ srsName: 'EPSG:4326', featureTypes: ['area'], - filter: _ol_format_filter_.intersects( + filter: intersectsFilter( 'the_geom', new Polygon([[ [10, 20], @@ -639,7 +656,7 @@ describe('ol.format.WFS', function() { const serialized = new WFS().writeGetFeature({ srsName: 'EPSG:4326', featureTypes: ['area'], - filter: _ol_format_filter_.within( + filter: withinFilter( 'the_geom', new Polygon([[ [10, 20], @@ -679,7 +696,7 @@ describe('ol.format.WFS', function() { const serialized = new WFS().writeGetFeature({ srsName: 'EPSG:4326', featureTypes: ['states'], - filter: _ol_format_filter_.during('date_prop', '2010-01-20T00:00:00Z', '2012-12-31T00:00:00Z') + filter: duringFilter('date_prop', '2010-01-20T00:00:00Z', '2012-12-31T00:00:00Z') }); expect(serialized.firstElementChild).to.xmleql(_ol_xml_.parse(text)); }); @@ -1298,9 +1315,9 @@ describe('ol.format.WFS', function() { ' ' + ''; const serialized = WFS.writeFilter( - _ol_format_filter_.and( - _ol_format_filter_.like('name', 'Mississippi*'), - _ol_format_filter_.equalTo('waterway', 'riverbank') + andFilter( + likeFilter('name', 'Mississippi*'), + equalToFilter('waterway', 'riverbank') ) ); expect(serialized).to.xmleql(_ol_xml_.parse(text));