Merge pull request #920 from tschaub/point-examples

Cast to number when creating literals from symbolizers where literal properties must be numeric.
This commit is contained in:
Tim Schaub
2013-08-26 11:57:09 -07:00
17 changed files with 11226 additions and 53 deletions

View File

@@ -95,6 +95,7 @@ ol.expr.lib = {};
* @enum {string}
*/
ol.expr.functions = {
CONCAT: 'concat',
EXTENT: 'extent',
FID: 'fid',
GEOMETRY_TYPE: 'geometryType',
@@ -108,6 +109,22 @@ ol.expr.functions = {
};
/**
* Concatenate strings. All provided arguments will be cast to string and
* concatenated.
* @param {...string} var_args Strings to concatenate.
* @return {string} All input arguments concatenated as strings.
* @this {ol.Feature}
*/
ol.expr.lib[ol.expr.functions.CONCAT] = function(var_args) {
var str = '';
for (var i = 0, ii = arguments.length; i < ii; ++i) {
str += String(arguments[i]);
}
return str;
};
/**
* Determine if a feature's extent intersects the provided extent.
* @param {number} minX Minimum x-coordinate value.

View File

@@ -483,11 +483,6 @@ ol.expr.Math.prototype.evaluate = function(opt_scope, opt_fns, opt_this) {
var result;
var rightVal = this.right_.evaluate(opt_scope, opt_fns, opt_this);
var leftVal = this.left_.evaluate(opt_scope, opt_fns, opt_this);
/**
* TODO: throw if rightVal, leftVal not numbers - this would require the use
* of a concat function for strings but it would let us serialize these as
* math functions where available elsewhere
*/
var op = this.operator_;
if (op === ol.expr.MathOp.ADD) {

View File

@@ -12,8 +12,6 @@ goog.require('ol.expr.Identifier');
goog.require('ol.expr.Literal');
goog.require('ol.expr.Logical');
goog.require('ol.expr.LogicalOp');
goog.require('ol.expr.Math');
goog.require('ol.expr.MathOp');
goog.require('ol.expr.Not');
goog.require('ol.expr.functions');
goog.require('ol.parser.XML');
@@ -64,13 +62,9 @@ ol.parser.ogc.Filter_v1 = function() {
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]);
}
}
expr = new ol.expr.Call(
new ol.expr.Identifier(ol.expr.functions.CONCAT),
expressions);
}
return expr;
},

View File

@@ -64,9 +64,8 @@ ol.style.Fill.prototype.createLiteral = function(featureOrType) {
goog.asserts.assertString(
color, 'color must be a string');
var opacity = ol.expr.evaluateFeature(this.opacity_, feature);
goog.asserts.assertNumber(
opacity, 'color must be a number');
var opacity = Number(ol.expr.evaluateFeature(this.opacity_, feature));
goog.asserts.assert(!isNaN(opacity), 'opacity must be a number');
literal = new ol.style.PolygonLiteral({
fillColor: color,

View File

@@ -90,21 +90,21 @@ ol.style.Icon.prototype.createLiteral = function(featureOrType) {
var width;
if (!goog.isNull(this.width_)) {
width = ol.expr.evaluateFeature(this.width_, feature);
goog.asserts.assertNumber(width, 'width must be a number');
width = Number(ol.expr.evaluateFeature(this.width_, feature));
goog.asserts.assert(!isNaN(width), 'width must be a number');
}
var height;
if (!goog.isNull(this.height_)) {
height = ol.expr.evaluateFeature(this.height_, feature);
height = Number(ol.expr.evaluateFeature(this.height_, feature));
goog.asserts.assertNumber(height, 'height must be a number');
}
var opacity = ol.expr.evaluateFeature(this.opacity_, feature);
goog.asserts.assertNumber(opacity, 'opacity must be a number');
var opacity = Number(ol.expr.evaluateFeature(this.opacity_, feature));
goog.asserts.assert(!isNaN(opacity), 'opacity must be a number');
var rotation = ol.expr.evaluateFeature(this.rotation_, feature);
goog.asserts.assertNumber(rotation, 'rotation must be a number');
var rotation = Number(ol.expr.evaluateFeature(this.rotation_, feature));
goog.asserts.assert(!isNaN(rotation), 'rotation must be a number');
literal = new ol.style.IconLiteral({
url: url,

View File

@@ -73,17 +73,17 @@ ol.style.Shape.prototype.createLiteral = function(featureOrType) {
var literal = null;
if (type === ol.geom.GeometryType.POINT ||
type === ol.geom.GeometryType.MULTIPOINT) {
var size = ol.expr.evaluateFeature(this.size_, feature);
goog.asserts.assertNumber(size, 'size must be a number');
var size = Number(ol.expr.evaluateFeature(this.size_, feature));
goog.asserts.assert(!isNaN(size), 'size must be a number');
var fillColor, fillOpacity;
if (!goog.isNull(this.fill_)) {
fillColor = ol.expr.evaluateFeature(this.fill_.getColor(), feature);
goog.asserts.assertString(
fillColor, 'fillColor must be a string');
fillOpacity = ol.expr.evaluateFeature(this.fill_.getOpacity(), feature);
goog.asserts.assertNumber(
fillOpacity, 'fillOpacity must be a number');
fillOpacity = Number(ol.expr.evaluateFeature(
this.fill_.getOpacity(), feature));
goog.asserts.assert(!isNaN(fillOpacity), 'fillOpacity must be a number');
}
var strokeColor, strokeOpacity, strokeWidth;
@@ -91,13 +91,13 @@ ol.style.Shape.prototype.createLiteral = function(featureOrType) {
strokeColor = ol.expr.evaluateFeature(this.stroke_.getColor(), feature);
goog.asserts.assertString(
strokeColor, 'strokeColor must be a string');
strokeOpacity = ol.expr.evaluateFeature(this.stroke_.getOpacity(),
feature);
goog.asserts.assertNumber(
strokeOpacity, 'strokeOpacity must be a number');
strokeWidth = ol.expr.evaluateFeature(this.stroke_.getWidth(), feature);
goog.asserts.assertNumber(
strokeWidth, 'strokeWidth must be a number');
strokeOpacity = Number(ol.expr.evaluateFeature(
this.stroke_.getOpacity(), feature));
goog.asserts.assert(!isNaN(strokeOpacity),
'strokeOpacity must be a number');
strokeWidth = Number(ol.expr.evaluateFeature(
this.stroke_.getWidth(), feature));
goog.asserts.assert(!isNaN(strokeWidth), 'strokeWidth must be a number');
}
literal = new ol.style.ShapeLiteral({

View File

@@ -71,13 +71,13 @@ ol.style.Stroke.prototype.createLiteral = function(featureOrType) {
this.color_, feature);
goog.asserts.assertString(color, 'color must be a string');
var opacity = ol.expr.evaluateFeature(
this.opacity_, feature);
goog.asserts.assertNumber(opacity, 'opacity must be a number');
var opacity = Number(ol.expr.evaluateFeature(
this.opacity_, feature));
goog.asserts.assert(!isNaN(opacity), 'opacity must be a number');
var width = ol.expr.evaluateFeature(
this.width_, feature);
goog.asserts.assertNumber(width, 'width must be a number');
var width = Number(ol.expr.evaluateFeature(
this.width_, feature));
goog.asserts.assert(!isNaN(width), 'width must be a number');
var literal = null;
if (type === ol.geom.GeometryType.LINESTRING ||

View File

@@ -84,14 +84,14 @@ ol.style.Text.prototype.createLiteral = function(featureOrType) {
var fontFamily = ol.expr.evaluateFeature(this.fontFamily_, feature);
goog.asserts.assertString(fontFamily, 'fontFamily must be a string');
var fontSize = ol.expr.evaluateFeature(this.fontSize_, feature);
goog.asserts.assertNumber(fontSize, 'fontSize must be a number');
var fontSize = Number(ol.expr.evaluateFeature(this.fontSize_, feature));
goog.asserts.assert(!isNaN(fontSize), 'fontSize must be a number');
var text = ol.expr.evaluateFeature(this.text_, feature);
goog.asserts.assertString(text, 'text must be a string');
var opacity = ol.expr.evaluateFeature(this.opacity_, feature);
goog.asserts.assertNumber(opacity, 'opacity must be a number');
var opacity = Number(ol.expr.evaluateFeature(this.opacity_, feature));
goog.asserts.assert(!isNaN(opacity), 'opacity must be a number');
return new ol.style.TextLiteral({
color: color,