Building an expression with constructors instead of ol.expr.parse
This commit is contained in:
@@ -12,6 +12,8 @@ goog.require('ol.expr.Identifier');
|
|||||||
goog.require('ol.expr.Literal');
|
goog.require('ol.expr.Literal');
|
||||||
goog.require('ol.expr.Logical');
|
goog.require('ol.expr.Logical');
|
||||||
goog.require('ol.expr.LogicalOp');
|
goog.require('ol.expr.LogicalOp');
|
||||||
|
goog.require('ol.expr.Math');
|
||||||
|
goog.require('ol.expr.MathOp');
|
||||||
goog.require('ol.expr.Not');
|
goog.require('ol.expr.Not');
|
||||||
goog.require('ol.expr.functions');
|
goog.require('ol.expr.functions');
|
||||||
goog.require('ol.parser.XML');
|
goog.require('ol.parser.XML');
|
||||||
@@ -28,34 +30,49 @@ ol.parser.ogc.Filter_v1 = function() {
|
|||||||
this.readers = {
|
this.readers = {
|
||||||
'http://www.opengis.net/ogc': {
|
'http://www.opengis.net/ogc': {
|
||||||
_expression: function(node) {
|
_expression: function(node) {
|
||||||
var obj, source = '';
|
var expressions = [];
|
||||||
|
var obj, value, numValue, expr;
|
||||||
for (var child = node.firstChild; child; child = child.nextSibling) {
|
for (var child = node.firstChild; child; child = child.nextSibling) {
|
||||||
switch (child.nodeType) {
|
switch (child.nodeType) {
|
||||||
case 1:
|
case 1:
|
||||||
obj = this.readNode(child);
|
obj = this.readNode(child);
|
||||||
if (obj.property) {
|
if (obj.property) {
|
||||||
var name = obj.property.getName();
|
expressions.push(obj.property);
|
||||||
source += (source !== '') ? '+' + name : name;
|
|
||||||
} else if (goog.isDef(obj.value)) {
|
} else if (goog.isDef(obj.value)) {
|
||||||
return obj.value;
|
return obj.value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3: // text node
|
case 3: // text node
|
||||||
case 4: // cdata section
|
case 4: // cdata section
|
||||||
if (source !== '') {
|
value = goog.string.trim(child.nodeValue);
|
||||||
source += '+';
|
// no need to concatenate empty strings
|
||||||
}
|
if (value) {
|
||||||
if (isNaN(goog.string.toNumber(child.nodeValue))) {
|
// check for numeric values
|
||||||
source += goog.string.quote(goog.string.trim(child.nodeValue));
|
numValue = goog.string.toNumber(value);
|
||||||
} else {
|
if (!isNaN(numValue)) {
|
||||||
source += goog.string.trim(child.nodeValue);
|
value = numValue;
|
||||||
|
}
|
||||||
|
expressions.push(new ol.expr.Literal(value));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ol.expr.parse(source);
|
// if we have more than one property or literal, we concatenate them
|
||||||
|
var num = expressions.length;
|
||||||
|
if (num === 1) {
|
||||||
|
expr = expressions[0];
|
||||||
|
} else {
|
||||||
|
expr = new ol.expr.Literal('');
|
||||||
|
if (num > 1) {
|
||||||
|
var add = ol.expr.MathOp.ADD;
|
||||||
|
for (var i = 0; i < num; ++i) {
|
||||||
|
expr = new ol.expr.Math(add, expr, expressions[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return expr;
|
||||||
},
|
},
|
||||||
'Filter': function(node, obj) {
|
'Filter': function(node, obj) {
|
||||||
var container = {
|
var container = {
|
||||||
|
|||||||
Reference in New Issue
Block a user