Cast values containing numbers into Number objects in Filter and SLD

format to ensure correct comparison of scale denominators against map 
scale  and filters against features. Introduces a new 
OpenLayers.String.numericIf function. r=fredj,tschaub (closes #1874)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@8927 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2009-03-01 22:19:17 +00:00
parent e58d820685
commit a80e1e52c2
5 changed files with 75 additions and 8 deletions

View File

@@ -186,6 +186,18 @@ OpenLayers.String = {
*/
isNumeric: function(value) {
return OpenLayers.String.numberRegEx.test(value);
},
/**
* APIFunction: numericIf
* Converts a string that appears to be a numeric value into a number.
*
* Returns
* {Number|String} a Number if the passed value is a number, a String
* otherwise.
*/
numericIf: function(value) {
return OpenLayers.String.isNumeric(value) ? parseFloat(value) : value;
}
};

View File

@@ -168,16 +168,19 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
obj.filters.push(filter);
},
"Literal": function(node, obj) {
obj.value = this.getChildValue(node);
obj.value = OpenLayers.String.numericIf(
this.getChildValue(node));
},
"PropertyName": function(node, filter) {
filter.property = this.getChildValue(node);
},
"LowerBoundary": function(node, filter) {
filter.lowerBoundary = this.readOgcExpression(node);
filter.lowerBoundary = OpenLayers.String.numericIf(
this.readOgcExpression(node));
},
"UpperBoundary": function(node, filter) {
filter.upperBoundary = this.readOgcExpression(node);
filter.upperBoundary = OpenLayers.String.numericIf(
this.readOgcExpression(node));
},
"Intersects": function(node, obj) {
this.readSpatial(node, obj, OpenLayers.Filter.Spatial.INTERSECTS);

View File

@@ -154,13 +154,13 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
rule.elseFilter = true;
},
"MinScaleDenominator": function(node, rule) {
rule.minScaleDenominator = this.getChildValue(node);
rule.minScaleDenominator = parseFloat(this.getChildValue(node));
},
"MaxScaleDenominator": function(node, rule) {
rule.maxScaleDenominator = this.getChildValue(node);
rule.maxScaleDenominator = parseFloat(this.getChildValue(node));
},
"LineSymbolizer": function(node, rule) {
// OpenLayers doens't do painter's order, instead we extend
// OpenLayers doesn't do painter's order, instead we extend
var symbolizer = rule.symbolizer["Line"] || {};
this.readChildNodes(node, symbolizer);
// in case it didn't exist before