Allow user to customize literal encoding
As suggested by @mpriour, it would be nice if the user could determine how date values are encoded in literal elements. Extending this beyond date values, we can provide an `encodeLiteral` method that can be overridden to provide application specific behavior.
This commit is contained in:
@@ -247,6 +247,25 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
obj.filters.push(filter);
|
obj.filters.push(filter);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: encodeLiteral
|
||||||
|
* Generates the string representation of a value for use in <Literal>
|
||||||
|
* elements. The default encoder writes Date values as ISO 8601
|
||||||
|
* strings.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* value - {Object} Literal value to encode
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {String} String representation of the provided value.
|
||||||
|
*/
|
||||||
|
encodeLiteral: function(value) {
|
||||||
|
if (value instanceof Date) {
|
||||||
|
value = OpenLayers.Date.toISOString(value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: writeOgcExpression
|
* Method: writeOgcExpression
|
||||||
* Limited support for writing OGC expressions. Currently it supports
|
* Limited support for writing OGC expressions. Currently it supports
|
||||||
@@ -406,11 +425,8 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
"Literal": function(value) {
|
"Literal": function(value) {
|
||||||
if (value instanceof Date) {
|
|
||||||
value = OpenLayers.Date.toISOString(value);
|
|
||||||
}
|
|
||||||
return this.createElementNSPlus("ogc:Literal", {
|
return this.createElementNSPlus("ogc:Literal", {
|
||||||
value: value
|
value: this.encodeLiteral(value)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
"LowerBoundary": function(filter) {
|
"LowerBoundary": function(filter) {
|
||||||
|
|||||||
Reference in New Issue
Block a user