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:
bartvde
2011-03-17 15:47:28 +00:00
parent 2e00e2e442
commit dbd08a10a3
7 changed files with 349 additions and 20 deletions

View File

@@ -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"
});

View File

@@ -186,6 +186,10 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
"Distance": function(node, obj) {
obj.distance = parseInt(this.getChildValue(node));
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;
},
/**
* 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
*
@@ -303,35 +329,39 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
},
"PropertyIsLessThan": function(filter) {
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("Literal", filter.value, node);
// handle Literals or Functions for now
this.writeOgcExpression(filter.value, node);
return node;
},
"PropertyIsGreaterThan": function(filter) {
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("Literal", filter.value, node);
// handle Literals or Functions for now
this.writeOgcExpression(filter.value, node);
return node;
},
"PropertyIsLessThanOrEqualTo": function(filter) {
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("Literal", filter.value, node);
// handle Literals or Functions for now
this.writeOgcExpression(filter.value, node);
return node;
},
"PropertyIsGreaterThanOrEqualTo": function(filter) {
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("Literal", filter.value, node);
// handle Literals or Functions for now
this.writeOgcExpression(filter.value, node);
return node;
},
"PropertyIsBetween": function(filter) {
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("LowerBoundary", filter, node);
this.writeNode("UpperBoundary", filter, node);
@@ -350,13 +380,13 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
});
},
"LowerBoundary": function(filter) {
// no ogc:expression handling for now
// handle Literals or Functions for now
var node = this.createElementNSPlus("ogc:LowerBoundary");
this.writeNode("Literal", filter.lowerBoundary, node);
this.writeOgcExpression(filter.lowerBoundary, node);
return node;
},
"UpperBoundary": function(filter) {
// no ogc:expression handling for now
// handle Literals or Functions for now
var node = this.createElementNSPlus("ogc:UpperBoundary");
this.writeNode("Literal", filter.upperBoundary, node);
return node;
@@ -382,6 +412,18 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
},
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;
}
}
},

View File

@@ -96,16 +96,18 @@ OpenLayers.Format.Filter.v1_0_0 = OpenLayers.Class(
"ogc": OpenLayers.Util.applyDefaults({
"PropertyIsEqualTo": function(filter) {
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("Literal", filter.value, node);
// handle Literals or Functions for now
this.writeOgcExpression(filter.value, node);
return node;
},
"PropertyIsNotEqualTo": function(filter) {
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("Literal", filter.value, node);
// handle Literals or Functions for now
this.writeOgcExpression(filter.value, node);
return node;
},
"PropertyIsLike": function(filter) {
@@ -150,6 +152,9 @@ OpenLayers.Format.Filter.v1_0_0 = OpenLayers.Class(
writeSpatial: function(filter, name) {
var node = this.createElementNSPlus("ogc:"+name);
this.writeNode("PropertyName", filter, node);
if(filter.value instanceof OpenLayers.Filter.Function) {
this.writeNode("Function", filter.value, node);
} else {
var child;
if(filter.value instanceof OpenLayers.Geometry) {
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);
}
node.appendChild(child);
}
return node;
},

View File

@@ -108,18 +108,20 @@ OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class(
var node = this.createElementNSPlus("ogc:PropertyIsEqualTo", {
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("Literal", filter.value, node);
// handle Literals or Functions for now
this.writeOgcExpression(filter.value, node);
return node;
},
"PropertyIsNotEqualTo": function(filter) {
var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo", {
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("Literal", filter.value, node);
// handle Literals or Functions for now
this.writeOgcExpression(filter.value, node);
return node;
},
"PropertyIsLike": function(filter) {
@@ -164,6 +166,9 @@ OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class(
writeSpatial: function(filter, name) {
var node = this.createElementNSPlus("ogc:"+name);
this.writeNode("PropertyName", filter, node);
if(filter.value instanceof OpenLayers.Filter.Function) {
this.writeNode("Function", filter.value, node);
} else {
var child;
if(filter.value instanceof OpenLayers.Geometry) {
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);
}
node.appendChild(child);
}
return node;
},