Make ol.format.filter.or/and accept n conditions
This commit is contained in:
@@ -19,28 +19,28 @@ goog.require('ol.format.filter.Within');
|
||||
|
||||
|
||||
/**
|
||||
* Create a logical `<And>` operator between two filter conditions.
|
||||
* Create a logical `<And>` operator between two or more filter conditions.
|
||||
*
|
||||
* @param {!ol.format.filter.Filter} conditionA First filter condition.
|
||||
* @param {!ol.format.filter.Filter} conditionB Second filter condition.
|
||||
* @param {...ol.format.filter.Filter} conditions Filter conditions.
|
||||
* @returns {!ol.format.filter.And} `<And>` operator.
|
||||
* @api
|
||||
*/
|
||||
ol.format.filter.and = function(conditionA, conditionB) {
|
||||
return new ol.format.filter.And(conditionA, conditionB);
|
||||
ol.format.filter.and = function(conditions) {
|
||||
var params = [null].concat(Array.prototype.slice.call(arguments));
|
||||
return new (Function.prototype.bind.apply(ol.format.filter.And, params));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a logical `<Or>` operator between two filter conditions.
|
||||
* Create a logical `<Or>` operator between two or more filter conditions.
|
||||
*
|
||||
* @param {!ol.format.filter.Filter} conditionA First filter condition.
|
||||
* @param {!ol.format.filter.Filter} conditionB Second filter condition.
|
||||
* @param {...ol.format.filter.Filter} conditions Filter conditions.
|
||||
* @returns {!ol.format.filter.Or} `<Or>` operator.
|
||||
* @api
|
||||
*/
|
||||
ol.format.filter.or = function(conditionA, conditionB) {
|
||||
return new ol.format.filter.Or(conditionA, conditionB);
|
||||
ol.format.filter.or = function(conditions) {
|
||||
var params = [null].concat(Array.prototype.slice.call(arguments));
|
||||
return new (Function.prototype.bind.apply(ol.format.filter.Or, params));
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
goog.provide('ol.format.filter.And');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.format.filter.LogicalBinary');
|
||||
goog.require('ol.format.filter.LogicalNary');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Represents a logical `<And>` operator between two filter conditions.
|
||||
* Represents a logical `<And>` operator between two or more filter conditions.
|
||||
*
|
||||
* @constructor
|
||||
* @param {!ol.format.filter.Filter} conditionA First filter condition.
|
||||
* @param {!ol.format.filter.Filter} conditionB Second filter condition.
|
||||
* @extends {ol.format.filter.LogicalBinary}
|
||||
* @param {...ol.format.filter.Filter} conditions Conditions.
|
||||
* @extends {ol.format.filter.LogicalNary}
|
||||
* @api
|
||||
*/
|
||||
ol.format.filter.And = function(conditionA, conditionB) {
|
||||
ol.format.filter.LogicalBinary.call(this, 'And', conditionA, conditionB);
|
||||
ol.format.filter.And = function(conditions) {
|
||||
var params = ['And'].concat(Array.prototype.slice.call(arguments));
|
||||
ol.format.filter.LogicalNary.apply(this, params);
|
||||
};
|
||||
ol.inherits(ol.format.filter.And, ol.format.filter.LogicalBinary);
|
||||
ol.inherits(ol.format.filter.And, ol.format.filter.LogicalNary);
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
goog.provide('ol.format.filter.LogicalBinary');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.format.filter.Logical');
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Abstract class; normally only used for creating subclasses and not instantiated in apps.
|
||||
* Base class for WFS GetFeature binary logical filters.
|
||||
*
|
||||
* @constructor
|
||||
* @param {!string} tagName The XML tag name for this filter.
|
||||
* @param {!ol.format.filter.Filter} conditionA First filter condition.
|
||||
* @param {!ol.format.filter.Filter} conditionB Second filter condition.
|
||||
* @extends {ol.format.filter.Logical}
|
||||
*/
|
||||
ol.format.filter.LogicalBinary = function(tagName, conditionA, conditionB) {
|
||||
|
||||
ol.format.filter.Logical.call(this, tagName);
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {!ol.format.filter.Filter}
|
||||
*/
|
||||
this.conditionA = conditionA;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {!ol.format.filter.Filter}
|
||||
*/
|
||||
this.conditionB = conditionB;
|
||||
|
||||
};
|
||||
ol.inherits(ol.format.filter.LogicalBinary, ol.format.filter.Logical);
|
||||
28
src/ol/format/filter/logicalnary.js
Normal file
28
src/ol/format/filter/logicalnary.js
Normal file
@@ -0,0 +1,28 @@
|
||||
goog.provide('ol.format.filter.LogicalNary');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.format.filter.Logical');
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Abstract class; normally only used for creating subclasses and not instantiated in apps.
|
||||
* Base class for WFS GetFeature n-ary logical filters.
|
||||
*
|
||||
* @constructor
|
||||
* @param {!string} tagName The XML tag name for this filter.
|
||||
* @param {...ol.format.filter.Filter} conditions Conditions.
|
||||
* @extends {ol.format.filter.Logical}
|
||||
*/
|
||||
ol.format.filter.LogicalNary = function(tagName, conditions) {
|
||||
|
||||
ol.format.filter.Logical.call(this, tagName);
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {Array.<ol.format.filter.Filter>}
|
||||
*/
|
||||
this.conditions = Array.prototype.slice.call(arguments, 1);
|
||||
ol.asserts.assert(this.conditions.length >= 2, 57); // At least 2 conditions are required.
|
||||
};
|
||||
ol.inherits(ol.format.filter.LogicalNary, ol.format.filter.Logical);
|
||||
@@ -1,20 +1,20 @@
|
||||
goog.provide('ol.format.filter.Or');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.format.filter.LogicalBinary');
|
||||
goog.require('ol.format.filter.LogicalNary');
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Represents a logical `<Or>` operator between two filter conditions.
|
||||
* Represents a logical `<Or>` operator between two ore more filter conditions.
|
||||
*
|
||||
* @constructor
|
||||
* @param {!ol.format.filter.Filter} conditionA First filter condition.
|
||||
* @param {!ol.format.filter.Filter} conditionB Second filter condition.
|
||||
* @extends {ol.format.filter.LogicalBinary}
|
||||
* @param {...ol.format.filter.Filter} conditions Conditions.
|
||||
* @extends {ol.format.filter.LogicalNary}
|
||||
* @api
|
||||
*/
|
||||
ol.format.filter.Or = function(conditionA, conditionB) {
|
||||
ol.format.filter.LogicalBinary.call(this, 'Or', conditionA, conditionB);
|
||||
ol.format.filter.Or = function(conditions) {
|
||||
var params = ['Or'].concat(Array.prototype.slice.call(arguments));
|
||||
ol.format.filter.LogicalNary.apply(this, params);
|
||||
};
|
||||
ol.inherits(ol.format.filter.Or, ol.format.filter.LogicalBinary);
|
||||
ol.inherits(ol.format.filter.Or, ol.format.filter.LogicalNary);
|
||||
|
||||
@@ -599,23 +599,19 @@ ol.format.WFS.writeWithinFilter_ = function(node, filter, objectStack) {
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.format.filter.LogicalBinary} filter Filter.
|
||||
* @param {ol.format.filter.LogicalNary} filter Filter.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeLogicalFilter_ = function(node, filter, objectStack) {
|
||||
/** @type {ol.XmlNodeStackItem} */
|
||||
var item = {node: node};
|
||||
var conditionA = filter.conditionA;
|
||||
ol.xml.pushSerializeAndPop(item,
|
||||
ol.format.WFS.GETFEATURE_SERIALIZERS_,
|
||||
ol.xml.makeSimpleNodeFactory(conditionA.getTagName()),
|
||||
[conditionA], objectStack);
|
||||
var conditionB = filter.conditionB;
|
||||
ol.xml.pushSerializeAndPop(item,
|
||||
ol.format.WFS.GETFEATURE_SERIALIZERS_,
|
||||
ol.xml.makeSimpleNodeFactory(conditionB.getTagName()),
|
||||
[conditionB], objectStack);
|
||||
filter.conditions.forEach(function(condition) {
|
||||
ol.xml.pushSerializeAndPop(item,
|
||||
ol.format.WFS.GETFEATURE_SERIALIZERS_,
|
||||
ol.xml.makeSimpleNodeFactory(condition.getTagName()),
|
||||
[condition], objectStack);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user