Geoserver filter Functions support in OL filter encoding, p=igrcic,r=me (closes #3053)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11712 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -244,6 +244,7 @@
|
|||||||
"OpenLayers/Filter/Logical.js",
|
"OpenLayers/Filter/Logical.js",
|
||||||
"OpenLayers/Filter/Comparison.js",
|
"OpenLayers/Filter/Comparison.js",
|
||||||
"OpenLayers/Filter/Spatial.js",
|
"OpenLayers/Filter/Spatial.js",
|
||||||
|
"OpenLayers/Filter/Function.js",
|
||||||
"OpenLayers/Protocol.js",
|
"OpenLayers/Protocol.js",
|
||||||
"OpenLayers/Protocol/HTTP.js",
|
"OpenLayers/Protocol/HTTP.js",
|
||||||
"OpenLayers/Protocol/SimpleFilterSerializer.js",
|
"OpenLayers/Protocol/SimpleFilterSerializer.js",
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
|
||||||
|
* full list of contributors). Published under the Clear BSD license.
|
||||||
|
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||||
|
* full text of the license. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires OpenLayers/Filter.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class: OpenLayers.Filter.Function
|
||||||
|
* This class represents a filter function.
|
||||||
|
* We are using this class for creation of complex
|
||||||
|
* filters that can contain filter functions as values.
|
||||||
|
* Nesting function as other functions parameter is supported.
|
||||||
|
*
|
||||||
|
* Inherits from
|
||||||
|
* - <OpenLayers.Filter>
|
||||||
|
*/
|
||||||
|
OpenLayers.Filter.Function = OpenLayers.Class(OpenLayers.Filter, {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: name
|
||||||
|
* {String} Name of the function.
|
||||||
|
*/
|
||||||
|
name: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: params
|
||||||
|
* {Array(<OpenLayers.Filter.Function> || String || Number)} Function parameters
|
||||||
|
* For now support only other Functions, String or Number
|
||||||
|
*/
|
||||||
|
params: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor: OpenLayers.Filter.Function
|
||||||
|
* Creates a filter function.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* options - {Object} An optional object with properties to set on the
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {<OpenLayers.Filter.Function>}
|
||||||
|
*/
|
||||||
|
initialize: function(options) {
|
||||||
|
OpenLayers.Filter.prototype.initialize.apply(this, [options]);
|
||||||
|
},
|
||||||
|
|
||||||
|
CLASS_NAME: "OpenLayers.Filter.Function"
|
||||||
|
});
|
||||||
|
|
||||||
@@ -186,6 +186,10 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
"Distance": function(node, obj) {
|
"Distance": function(node, obj) {
|
||||||
obj.distance = parseInt(this.getChildValue(node));
|
obj.distance = parseInt(this.getChildValue(node));
|
||||||
obj.distanceUnits = node.getAttribute("units");
|
obj.distanceUnits = node.getAttribute("units");
|
||||||
|
},
|
||||||
|
"Function": function(node, obj) {
|
||||||
|
//TODO write decoder for it
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -233,6 +237,28 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: writeOgcExpression
|
||||||
|
* Limited support for writing OGC expressions. Currently it supports
|
||||||
|
* (<OpenLayers.Filter.Function> || String || Number)
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* value - (<OpenLayers.Filter.Function> || String || Number)
|
||||||
|
* node - {DOMElement} A parent DOM element
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {DOMElement} Updated node element.
|
||||||
|
*/
|
||||||
|
writeOgcExpression: function(value, node) {
|
||||||
|
if(value instanceof OpenLayers.Filter.Function){
|
||||||
|
var child = this.writeNode("Function", value, node);
|
||||||
|
node.appendChild(child);
|
||||||
|
} else {
|
||||||
|
this.writeNode("Literal", value, node);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: write
|
* Method: write
|
||||||
*
|
*
|
||||||
@@ -303,35 +329,39 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
},
|
},
|
||||||
"PropertyIsLessThan": function(filter) {
|
"PropertyIsLessThan": function(filter) {
|
||||||
var node = this.createElementNSPlus("ogc:PropertyIsLessThan");
|
var node = this.createElementNSPlus("ogc:PropertyIsLessThan");
|
||||||
// no ogc:expression handling for now
|
// no ogc:expression handling for PropertyName for now
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
this.writeNode("Literal", filter.value, node);
|
// handle Literals or Functions for now
|
||||||
|
this.writeOgcExpression(filter.value, node);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
"PropertyIsGreaterThan": function(filter) {
|
"PropertyIsGreaterThan": function(filter) {
|
||||||
var node = this.createElementNSPlus("ogc:PropertyIsGreaterThan");
|
var node = this.createElementNSPlus("ogc:PropertyIsGreaterThan");
|
||||||
// no ogc:expression handling for now
|
// no ogc:expression handling for PropertyName for now
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
this.writeNode("Literal", filter.value, node);
|
// handle Literals or Functions for now
|
||||||
|
this.writeOgcExpression(filter.value, node);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
"PropertyIsLessThanOrEqualTo": function(filter) {
|
"PropertyIsLessThanOrEqualTo": function(filter) {
|
||||||
var node = this.createElementNSPlus("ogc:PropertyIsLessThanOrEqualTo");
|
var node = this.createElementNSPlus("ogc:PropertyIsLessThanOrEqualTo");
|
||||||
// no ogc:expression handling for now
|
// no ogc:expression handling for PropertyName for now
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
this.writeNode("Literal", filter.value, node);
|
// handle Literals or Functions for now
|
||||||
|
this.writeOgcExpression(filter.value, node);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
"PropertyIsGreaterThanOrEqualTo": function(filter) {
|
"PropertyIsGreaterThanOrEqualTo": function(filter) {
|
||||||
var node = this.createElementNSPlus("ogc:PropertyIsGreaterThanOrEqualTo");
|
var node = this.createElementNSPlus("ogc:PropertyIsGreaterThanOrEqualTo");
|
||||||
// no ogc:expression handling for now
|
// no ogc:expression handling for PropertyName for now
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
this.writeNode("Literal", filter.value, node);
|
// handle Literals or Functions for now
|
||||||
|
this.writeOgcExpression(filter.value, node);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
"PropertyIsBetween": function(filter) {
|
"PropertyIsBetween": function(filter) {
|
||||||
var node = this.createElementNSPlus("ogc:PropertyIsBetween");
|
var node = this.createElementNSPlus("ogc:PropertyIsBetween");
|
||||||
// no ogc:expression handling for now
|
// no ogc:expression handling for PropertyName for now
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
this.writeNode("LowerBoundary", filter, node);
|
this.writeNode("LowerBoundary", filter, node);
|
||||||
this.writeNode("UpperBoundary", filter, node);
|
this.writeNode("UpperBoundary", filter, node);
|
||||||
@@ -350,13 +380,13 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
"LowerBoundary": function(filter) {
|
"LowerBoundary": function(filter) {
|
||||||
// no ogc:expression handling for now
|
// handle Literals or Functions for now
|
||||||
var node = this.createElementNSPlus("ogc:LowerBoundary");
|
var node = this.createElementNSPlus("ogc:LowerBoundary");
|
||||||
this.writeNode("Literal", filter.lowerBoundary, node);
|
this.writeOgcExpression(filter.lowerBoundary, node);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
"UpperBoundary": function(filter) {
|
"UpperBoundary": function(filter) {
|
||||||
// no ogc:expression handling for now
|
// handle Literals or Functions for now
|
||||||
var node = this.createElementNSPlus("ogc:UpperBoundary");
|
var node = this.createElementNSPlus("ogc:UpperBoundary");
|
||||||
this.writeNode("Literal", filter.upperBoundary, node);
|
this.writeNode("Literal", filter.upperBoundary, node);
|
||||||
return node;
|
return node;
|
||||||
@@ -382,6 +412,18 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
},
|
},
|
||||||
value: filter.distance
|
value: filter.distance
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
"Function": function(filter) {
|
||||||
|
var node = this.createElementNSPlus("ogc:Function", {
|
||||||
|
attributes: {
|
||||||
|
name: filter.name
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var params = filter.params;
|
||||||
|
for(var i=0, len=params.length; i<len; i++){
|
||||||
|
this.writeOgcExpression(params[i], node);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -96,16 +96,18 @@ OpenLayers.Format.Filter.v1_0_0 = OpenLayers.Class(
|
|||||||
"ogc": OpenLayers.Util.applyDefaults({
|
"ogc": OpenLayers.Util.applyDefaults({
|
||||||
"PropertyIsEqualTo": function(filter) {
|
"PropertyIsEqualTo": function(filter) {
|
||||||
var node = this.createElementNSPlus("ogc:PropertyIsEqualTo");
|
var node = this.createElementNSPlus("ogc:PropertyIsEqualTo");
|
||||||
// no ogc:expression handling for now
|
// no ogc:expression handling for PropertyName for now
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
this.writeNode("Literal", filter.value, node);
|
// handle Literals or Functions for now
|
||||||
|
this.writeOgcExpression(filter.value, node);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
"PropertyIsNotEqualTo": function(filter) {
|
"PropertyIsNotEqualTo": function(filter) {
|
||||||
var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo");
|
var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo");
|
||||||
// no ogc:expression handling for now
|
// no ogc:expression handling for PropertyName for now
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
this.writeNode("Literal", filter.value, node);
|
// handle Literals or Functions for now
|
||||||
|
this.writeOgcExpression(filter.value, node);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
"PropertyIsLike": function(filter) {
|
"PropertyIsLike": function(filter) {
|
||||||
@@ -150,6 +152,9 @@ OpenLayers.Format.Filter.v1_0_0 = OpenLayers.Class(
|
|||||||
writeSpatial: function(filter, name) {
|
writeSpatial: function(filter, name) {
|
||||||
var node = this.createElementNSPlus("ogc:"+name);
|
var node = this.createElementNSPlus("ogc:"+name);
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
|
if(filter.value instanceof OpenLayers.Filter.Function) {
|
||||||
|
this.writeNode("Function", filter.value, node);
|
||||||
|
} else {
|
||||||
var child;
|
var child;
|
||||||
if(filter.value instanceof OpenLayers.Geometry) {
|
if(filter.value instanceof OpenLayers.Geometry) {
|
||||||
child = this.writeNode("feature:_geometry", filter.value).firstChild;
|
child = this.writeNode("feature:_geometry", filter.value).firstChild;
|
||||||
@@ -160,6 +165,7 @@ OpenLayers.Format.Filter.v1_0_0 = OpenLayers.Class(
|
|||||||
child.setAttribute("srsName", filter.projection);
|
child.setAttribute("srsName", filter.projection);
|
||||||
}
|
}
|
||||||
node.appendChild(child);
|
node.appendChild(child);
|
||||||
|
}
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -108,18 +108,20 @@ OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class(
|
|||||||
var node = this.createElementNSPlus("ogc:PropertyIsEqualTo", {
|
var node = this.createElementNSPlus("ogc:PropertyIsEqualTo", {
|
||||||
attributes: {matchCase: filter.matchCase}
|
attributes: {matchCase: filter.matchCase}
|
||||||
});
|
});
|
||||||
// no ogc:expression handling for now
|
// no ogc:expression handling for PropertyName for now
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
this.writeNode("Literal", filter.value, node);
|
// handle Literals or Functions for now
|
||||||
|
this.writeOgcExpression(filter.value, node);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
"PropertyIsNotEqualTo": function(filter) {
|
"PropertyIsNotEqualTo": function(filter) {
|
||||||
var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo", {
|
var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo", {
|
||||||
attributes: {matchCase: filter.matchCase}
|
attributes: {matchCase: filter.matchCase}
|
||||||
});
|
});
|
||||||
// no ogc:expression handling for now
|
// no ogc:expression handling for PropertyName for now
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
this.writeNode("Literal", filter.value, node);
|
// handle Literals or Functions for now
|
||||||
|
this.writeOgcExpression(filter.value, node);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
"PropertyIsLike": function(filter) {
|
"PropertyIsLike": function(filter) {
|
||||||
@@ -164,6 +166,9 @@ OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class(
|
|||||||
writeSpatial: function(filter, name) {
|
writeSpatial: function(filter, name) {
|
||||||
var node = this.createElementNSPlus("ogc:"+name);
|
var node = this.createElementNSPlus("ogc:"+name);
|
||||||
this.writeNode("PropertyName", filter, node);
|
this.writeNode("PropertyName", filter, node);
|
||||||
|
if(filter.value instanceof OpenLayers.Filter.Function) {
|
||||||
|
this.writeNode("Function", filter.value, node);
|
||||||
|
} else {
|
||||||
var child;
|
var child;
|
||||||
if(filter.value instanceof OpenLayers.Geometry) {
|
if(filter.value instanceof OpenLayers.Geometry) {
|
||||||
child = this.writeNode("feature:_geometry", filter.value).firstChild;
|
child = this.writeNode("feature:_geometry", filter.value).firstChild;
|
||||||
@@ -174,6 +179,7 @@ OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class(
|
|||||||
child.setAttribute("srsName", filter.projection);
|
child.setAttribute("srsName", filter.projection);
|
||||||
}
|
}
|
||||||
node.appendChild(child);
|
node.appendChild(child);
|
||||||
|
}
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -152,6 +152,116 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_FilterFunctions(t) {
|
||||||
|
t.plan(2);
|
||||||
|
|
||||||
|
var parser = new OpenLayers.Format.Filter.v1_0_0();
|
||||||
|
|
||||||
|
//test spatial intersects with filter function
|
||||||
|
var filter = new OpenLayers.Filter.Spatial({
|
||||||
|
property: 'the_geom',
|
||||||
|
type: OpenLayers.Filter.Spatial.INTERSECTS,
|
||||||
|
value: new OpenLayers.Filter.Function({
|
||||||
|
name : 'querySingle',
|
||||||
|
params: ['sf:restricted', 'the_geom', 'cat=3']
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
var out =
|
||||||
|
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||||
|
'<ogc:Intersects>' +
|
||||||
|
'<ogc:PropertyName>the_geom</ogc:PropertyName>' +
|
||||||
|
'<ogc:Function name="querySingle">' +
|
||||||
|
'<ogc:Literal>sf:restricted</ogc:Literal>' +
|
||||||
|
'<ogc:Literal>the_geom</ogc:Literal>' +
|
||||||
|
'<ogc:Literal>cat=3</ogc:Literal>' +
|
||||||
|
'</ogc:Function>' +
|
||||||
|
'</ogc:Intersects>' +
|
||||||
|
'</ogc:Filter>';
|
||||||
|
|
||||||
|
|
||||||
|
var node = parser.write(filter);
|
||||||
|
|
||||||
|
//test writer
|
||||||
|
t.xml_eq(node, out, "spatial intersect filter with functions correctly written");
|
||||||
|
|
||||||
|
//test logical filter with custom function
|
||||||
|
filter = new OpenLayers.Filter.Logical({
|
||||||
|
type: OpenLayers.Filter.Logical.AND,
|
||||||
|
filters: [
|
||||||
|
new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
|
||||||
|
property: "FOO",
|
||||||
|
value: new OpenLayers.Filter.Function({
|
||||||
|
name : 'customFunction',
|
||||||
|
params : ['param1', 'param2']
|
||||||
|
})
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
out =
|
||||||
|
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||||
|
'<ogc:And>' +
|
||||||
|
'<ogc:PropertyIsNotEqualTo>' +
|
||||||
|
'<ogc:PropertyName>FOO</ogc:PropertyName>' +
|
||||||
|
'<ogc:Function name="customFunction">' +
|
||||||
|
'<ogc:Literal>param1</ogc:Literal>' +
|
||||||
|
'<ogc:Literal>param2</ogc:Literal>' +
|
||||||
|
'</ogc:Function>' +
|
||||||
|
'</ogc:PropertyIsNotEqualTo>' +
|
||||||
|
'</ogc:And>' +
|
||||||
|
'</ogc:Filter>';
|
||||||
|
|
||||||
|
node = parser.write(filter);
|
||||||
|
|
||||||
|
//test writer
|
||||||
|
t.xml_eq(node, out, "comparison filter with filter functions correctly written");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_NestedFilterFunctions(t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
//test spatial dwithin with nested filter function
|
||||||
|
var filter = new OpenLayers.Filter.Spatial({
|
||||||
|
property: 'the_geom',
|
||||||
|
type: OpenLayers.Filter.Spatial.DWITHIN,
|
||||||
|
value: new OpenLayers.Filter.Function({
|
||||||
|
name : 'collectGeometries',
|
||||||
|
params: [
|
||||||
|
new OpenLayers.Filter.Function({
|
||||||
|
name : 'queryCollection',
|
||||||
|
params: ['sf:roads', 'the_geom', 'INCLUDE']
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
distanceUnits: "meters",
|
||||||
|
distance: 200
|
||||||
|
});
|
||||||
|
|
||||||
|
var out =
|
||||||
|
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||||
|
'<ogc:DWithin>' +
|
||||||
|
'<ogc:PropertyName>the_geom</ogc:PropertyName>' +
|
||||||
|
'<ogc:Function name="collectGeometries">' +
|
||||||
|
'<ogc:Function name="queryCollection">' +
|
||||||
|
'<ogc:Literal>sf:roads</ogc:Literal>' +
|
||||||
|
'<ogc:Literal>the_geom</ogc:Literal>' +
|
||||||
|
'<ogc:Literal>INCLUDE</ogc:Literal>' +
|
||||||
|
'</ogc:Function>' +
|
||||||
|
'</ogc:Function>' +
|
||||||
|
'<ogc:Distance units="meters">200</ogc:Distance>' +
|
||||||
|
'</ogc:DWithin>' +
|
||||||
|
'</ogc:Filter>';
|
||||||
|
|
||||||
|
var parser = new OpenLayers.Format.Filter.v1_0_0();
|
||||||
|
var node = parser.write(filter);
|
||||||
|
|
||||||
|
//test writer
|
||||||
|
t.xml_eq(node, out, "spatial dwithin filter with nested functions correctly written");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -203,6 +203,118 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_FilterFunctions(t) {
|
||||||
|
t.plan(2);
|
||||||
|
|
||||||
|
var parser = new OpenLayers.Format.Filter.v1_1_0();
|
||||||
|
|
||||||
|
//test spatial intersects with filter function
|
||||||
|
var filter = new OpenLayers.Filter.Spatial({
|
||||||
|
property: 'the_geom',
|
||||||
|
type: OpenLayers.Filter.Spatial.INTERSECTS,
|
||||||
|
value: new OpenLayers.Filter.Function({
|
||||||
|
name : 'querySingle',
|
||||||
|
params: ['sf:restricted', 'the_geom', 'cat=3']
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
var out =
|
||||||
|
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||||
|
'<ogc:Intersects>' +
|
||||||
|
'<ogc:PropertyName>the_geom</ogc:PropertyName>' +
|
||||||
|
'<ogc:Function name="querySingle">' +
|
||||||
|
'<ogc:Literal>sf:restricted</ogc:Literal>' +
|
||||||
|
'<ogc:Literal>the_geom</ogc:Literal>' +
|
||||||
|
'<ogc:Literal>cat=3</ogc:Literal>' +
|
||||||
|
'</ogc:Function>' +
|
||||||
|
'</ogc:Intersects>' +
|
||||||
|
'</ogc:Filter>';
|
||||||
|
|
||||||
|
|
||||||
|
var node = parser.write(filter);
|
||||||
|
|
||||||
|
//test writer
|
||||||
|
t.xml_eq(node, out, "spatial intersect filter with functions correctly written");
|
||||||
|
|
||||||
|
//test logical filter with custom function
|
||||||
|
filter = new OpenLayers.Filter.Logical({
|
||||||
|
type: OpenLayers.Filter.Logical.AND,
|
||||||
|
filters: [
|
||||||
|
new OpenLayers.Filter.Comparison({
|
||||||
|
type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
|
||||||
|
matchCase: false,
|
||||||
|
property: "FOO",
|
||||||
|
value: new OpenLayers.Filter.Function({
|
||||||
|
name : 'customFunction',
|
||||||
|
params : ['param1', 'param2']
|
||||||
|
})
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
out =
|
||||||
|
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||||
|
'<ogc:And>' +
|
||||||
|
'<ogc:PropertyIsNotEqualTo matchCase="false">' +
|
||||||
|
'<ogc:PropertyName>FOO</ogc:PropertyName>' +
|
||||||
|
'<ogc:Function name="customFunction">' +
|
||||||
|
'<ogc:Literal>param1</ogc:Literal>' +
|
||||||
|
'<ogc:Literal>param2</ogc:Literal>' +
|
||||||
|
'</ogc:Function>' +
|
||||||
|
'</ogc:PropertyIsNotEqualTo>' +
|
||||||
|
'</ogc:And>' +
|
||||||
|
'</ogc:Filter>';
|
||||||
|
|
||||||
|
node = parser.write(filter);
|
||||||
|
|
||||||
|
//test writer
|
||||||
|
t.xml_eq(node, out, "comparison filter with filter functions correctly written");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_NestedFilterFunctions(t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
//test spatial dwithin with nested filter function
|
||||||
|
var filter = new OpenLayers.Filter.Spatial({
|
||||||
|
property: 'the_geom',
|
||||||
|
type: OpenLayers.Filter.Spatial.DWITHIN,
|
||||||
|
value: new OpenLayers.Filter.Function({
|
||||||
|
name : 'collectGeometries',
|
||||||
|
params: [
|
||||||
|
new OpenLayers.Filter.Function({
|
||||||
|
name : 'queryCollection',
|
||||||
|
params: ['sf:roads', 'the_geom', 'INCLUDE']
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
distanceUnits: "meters",
|
||||||
|
distance: 200
|
||||||
|
});
|
||||||
|
|
||||||
|
var out =
|
||||||
|
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||||
|
'<ogc:DWithin>' +
|
||||||
|
'<ogc:PropertyName>the_geom</ogc:PropertyName>' +
|
||||||
|
'<ogc:Function name="collectGeometries">' +
|
||||||
|
'<ogc:Function name="queryCollection">' +
|
||||||
|
'<ogc:Literal>sf:roads</ogc:Literal>' +
|
||||||
|
'<ogc:Literal>the_geom</ogc:Literal>' +
|
||||||
|
'<ogc:Literal>INCLUDE</ogc:Literal>' +
|
||||||
|
'</ogc:Function>' +
|
||||||
|
'</ogc:Function>' +
|
||||||
|
'<ogc:Distance units="meters">200</ogc:Distance>' +
|
||||||
|
'</ogc:DWithin>' +
|
||||||
|
'</ogc:Filter>';
|
||||||
|
|
||||||
|
var parser = new OpenLayers.Format.Filter.v1_1_0();
|
||||||
|
var node = parser.write(filter);
|
||||||
|
|
||||||
|
//test writer
|
||||||
|
t.xml_eq(node, out, "spatial dwithin filter with nested functions correctly written");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user