diff --git a/examples/style-rules.js b/examples/style-rules.js index de8839a7b7..82d14b86e3 100644 --- a/examples/style-rules.js +++ b/examples/style-rules.js @@ -1,8 +1,8 @@ -goog.require('ol.Expression'); goog.require('ol.Map'); goog.require('ol.RendererHint'); goog.require('ol.View2D'); goog.require('ol.control.defaults'); +goog.require('ol.expression'); goog.require('ol.filter.Filter'); goog.require('ol.filter.Geometry'); goog.require('ol.geom.GeometryType'); @@ -24,7 +24,7 @@ var style = new ol.style.Style({rules: [ }), symbolizers: [ new ol.style.Line({ - strokeColor: new ol.Expression('color'), + strokeColor: ol.expression.parse('color'), strokeWidth: 4, opacity: 1 }) @@ -41,7 +41,7 @@ var style = new ol.style.Style({rules: [ opacity: 1 }), new ol.style.Line({ - strokeColor: new ol.Expression('color'), + strokeColor: ol.expression.parse('color'), strokeWidth: 2, opacity: 1 }) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index fa584f9332..b7b5a2e460 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -519,34 +519,35 @@ /** * @typedef {Object} ol.style.IconOptions - * @property {string|ol.Expression} url Icon image url. - * @property {number|ol.Expression|undefined} width Width of the icon in pixels. - * Default is the width of the icon image. - * @property {number|ol.Expression|undefined} height Height of the icon in - * pixels. Default is the height of the icon image. - * @property {number|ol.Expression|undefined} opacity Icon opacity (0-1). - * @property {number|ol.Expression|undefined} rotation Rotation in degrees - * (0-360). + * @property {string|ol.expression.Expression} url Icon image url. + * @property {number|ol.expression.Expression|undefined} width Width of the icon + * in pixels. Default is the width of the icon image. + * @property {number|ol.expression.Expression|undefined} height Height of the + * icon in pixels. Default is the height of the icon image. + * @property {number|ol.expression.Expression|undefined} opacity Icon opacity + * (0-1). + * @property {number|ol.expression.Expression|undefined} rotation Rotation in + * degrees (0-360). */ /** * @typedef {Object} ol.style.LineOptions - * @property {string|ol.Expression|undefined} strokeColor Stroke color as hex - * color code. - * @property {number|ol.Expression|undefined} strokeWidth Stroke width in - * pixels. - * @property {number|ol.Expression|undefined} opacity Opacity (0-1). + * @property {string|ol.expression.Expression|undefined} strokeColor Stroke + * color as hex color code. + * @property {number|ol.expression.Expression|undefined} strokeWidth Stroke + * width in pixels. + * @property {number|ol.expression.Expression|undefined} opacity Opacity (0-1). */ /** * @typedef {Object} ol.style.PolygonOptions - * @property {string|ol.Expression|undefined} fillColor Fill color as hex color - * code. - * @property {string|ol.Expression|undefined} strokeColor Stroke color as hex - * color code. - * @property {number|ol.Expression|undefined} strokeWidth Stroke width in - * pixels. - * @property {number|ol.Expression|undefined} opacity Opacity (0-1). + * @property {string|ol.expression.Expression|undefined} fillColor Fill color as + * hex color code. + * @property {string|ol.expression.Expression|undefined} strokeColor Stroke + * color as hex color code. + * @property {number|ol.expression.Expression|undefined} strokeWidth Stroke + * width in pixels. + * @property {number|ol.expression.Expression|undefined} opacity Opacity (0-1). */ /** @@ -558,14 +559,14 @@ /** * @typedef {Object} ol.style.ShapeOptions * @property {ol.style.ShapeType|undefined} type Type. - * @property {number|ol.Expression|undefined} size Size in pixels. - * @property {string|ol.Expression|undefined} fillColor Fill color as hex color - * code. - * @property {string|ol.Expression|undefined} strokeColor Stroke color as hex - * color code. - * @property {number|ol.Expression|undefined} strokeWidth Stroke width in - * pixels. - * @property {number|ol.Expression|undefined} opacity Opacity (0-1). + * @property {number|ol.expression.Expression|undefined} size Size in pixels. + * @property {string|ol.expression.Expression|undefined} fillColor Fill color as + * hex color code. + * @property {string|ol.expression.Expression|undefined} strokeColor Stroke + * color as hex color code. + * @property {number|ol.expression.Expression|undefined} strokeWidth Stroke + * width in pixels. + * @property {number|ol.expression.Expression|undefined} opacity Opacity (0-1). */ /** diff --git a/src/ol/expression.exports b/src/ol/expression.exports deleted file mode 100644 index 911b8a12c6..0000000000 --- a/src/ol/expression.exports +++ /dev/null @@ -1 +0,0 @@ -@exportSymbol ol.Expression diff --git a/src/ol/expression.js b/src/ol/expression.js deleted file mode 100644 index 7b1370ae0d..0000000000 --- a/src/ol/expression.js +++ /dev/null @@ -1,80 +0,0 @@ -goog.provide('ol.Expression'); -goog.provide('ol.ExpressionLiteral'); - - - -/** - * Create a new expression. Expressions are used for instance to bind - * symbolizer properties to feature attributes. - * - * Example: - * - * // take the color from the color attribute - * color: new ol.Expression('color'); - * // take the strokeWidth from the width attribute and multiply by 2. - * strokeWidth: new ol.Expression('width*2'); - * - * @constructor - * @param {string} source Expression to be evaluated. - */ -ol.Expression = function(source) { - - /** - * @type {string} - * @private - */ - this.source_ = source; - -}; - - -/** - * Evaluate the expression and return the result. - * - * @param {Object=} opt_thisArg Object to use as this when evaluating the - * expression. If not provided, the global object will be used. - * @param {Object=} opt_scope Evaluation scope. All properties of this object - * will be available as variables when evaluating the expression. If not - * provided, the global object will be used. - * @return {*} Result of the expression. - */ -ol.Expression.prototype.evaluate = function(opt_thisArg, opt_scope) { - var thisArg = goog.isDef(opt_thisArg) ? opt_thisArg : goog.global, - scope = goog.isDef(opt_scope) ? opt_scope : goog.global, - names = [], - values = []; - - for (var name in scope) { - names.push(name); - values.push(scope[name]); - } - - var evaluator = new Function(names.join(','), 'return ' + this.source_); - return evaluator.apply(thisArg, values); -}; - - - -/** - * @constructor - * @extends {ol.Expression} - * @param {*} value Literal value. - */ -ol.ExpressionLiteral = function(value) { - - /** - * @type {*} - * @private - */ - this.value_ = value; - -}; -goog.inherits(ol.ExpressionLiteral, ol.Expression); - - -/** - * @inheritDoc - */ -ol.ExpressionLiteral.prototype.evaluate = function(opt_thisArg, opt_scope) { - return this.value_; -}; diff --git a/src/ol/style/icon.js b/src/ol/style/icon.js index 2be1658c24..4a3b148a10 100644 --- a/src/ol/style/icon.js +++ b/src/ol/style/icon.js @@ -3,8 +3,8 @@ goog.provide('ol.style.IconLiteral'); goog.provide('ol.style.IconType'); goog.require('goog.asserts'); -goog.require('ol.Expression'); -goog.require('ol.ExpressionLiteral'); +goog.require('ol.expression.Expression'); +goog.require('ol.expression.Literal'); goog.require('ol.style.Point'); goog.require('ol.style.PointLiteral'); @@ -69,47 +69,47 @@ ol.style.Icon = function(options) { goog.asserts.assert(options.url, 'url must be set'); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ - this.url_ = (options.url instanceof ol.Expression) ? - options.url : new ol.ExpressionLiteral(options.url); + this.url_ = (options.url instanceof ol.expression.Expression) ? + options.url : new ol.expression.Literal(options.url); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.width_ = !goog.isDef(options.width) ? null : - (options.width instanceof ol.Expression) ? - options.width : new ol.ExpressionLiteral(options.width); + (options.width instanceof ol.expression.Expression) ? + options.width : new ol.expression.Literal(options.width); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.height_ = !goog.isDef(options.height) ? null : - (options.height instanceof ol.Expression) ? - options.height : new ol.ExpressionLiteral(options.height); + (options.height instanceof ol.expression.Expression) ? + options.height : new ol.expression.Literal(options.height); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.opacity_ = !goog.isDef(options.opacity) ? - new ol.ExpressionLiteral(ol.style.IconDefaults.opacity) : - (options.opacity instanceof ol.Expression) ? - options.opacity : new ol.ExpressionLiteral(options.opacity); + new ol.expression.Literal(ol.style.IconDefaults.opacity) : + (options.opacity instanceof ol.expression.Expression) ? + options.opacity : new ol.expression.Literal(options.opacity); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.rotation_ = !goog.isDef(options.rotation) ? - new ol.ExpressionLiteral(ol.style.IconDefaults.rotation) : - (options.rotation instanceof ol.Expression) ? - options.rotation : new ol.ExpressionLiteral(options.rotation); + new ol.expression.Literal(ol.style.IconDefaults.rotation) : + (options.rotation instanceof ol.expression.Expression) ? + options.rotation : new ol.expression.Literal(options.rotation); }; @@ -121,24 +121,25 @@ ol.style.Icon = function(options) { ol.style.Icon.prototype.createLiteral = function(feature) { var attrs = feature && feature.getAttributes(); - var url = /** @type {string} */ (this.url_.evaluate(feature, attrs)); + var url = /** @type {string} */ (this.url_.evaluate(attrs, null, feature)); goog.asserts.assert(goog.isString(url) && url != '#', 'url must be a string'); var width = /** @type {number|undefined} */ (goog.isNull(this.width_) ? - undefined : this.width_.evaluate(feature, attrs)); + undefined : this.width_.evaluate(attrs, null, feature)); goog.asserts.assert(!goog.isDef(width) || goog.isNumber(width), 'width must be undefined or a number'); var height = /** @type {number|undefined} */ (goog.isNull(this.height_) ? - undefined : this.height_.evaluate(feature, attrs)); + undefined : this.height_.evaluate(attrs, null, feature)); goog.asserts.assert(!goog.isDef(height) || goog.isNumber(height), 'height must be undefined or a number'); - var opacity = /** {@type {number} */ (this.opacity_.evaluate(feature, attrs)); + var opacity = /** {@type {number} */ (this.opacity_.evaluate(attrs, null, + feature)); goog.asserts.assertNumber(opacity, 'opacity must be a number'); var rotation = - /** {@type {number} */ (this.rotation_.evaluate(feature, attrs)); + /** {@type {number} */ (this.rotation_.evaluate(attrs, null, feature)); goog.asserts.assertNumber(rotation, 'rotation must be a number'); return new ol.style.IconLiteral({ diff --git a/src/ol/style/line.js b/src/ol/style/line.js index 95460b8d45..e226ea085c 100644 --- a/src/ol/style/line.js +++ b/src/ol/style/line.js @@ -2,8 +2,8 @@ goog.provide('ol.style.Line'); goog.provide('ol.style.LineLiteral'); goog.require('goog.asserts'); -goog.require('ol.Expression'); -goog.require('ol.ExpressionLiteral'); +goog.require('ol.expression.Expression'); +goog.require('ol.expression.Literal'); goog.require('ol.style.Symbolizer'); goog.require('ol.style.SymbolizerLiteral'); @@ -63,31 +63,31 @@ ol.style.Line = function(options) { goog.base(this); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.strokeColor_ = !goog.isDef(options.strokeColor) ? - new ol.ExpressionLiteral(ol.style.LineDefaults.strokeColor) : - (options.strokeColor instanceof ol.Expression) ? - options.strokeColor : new ol.ExpressionLiteral(options.strokeColor); + new ol.expression.Literal(ol.style.LineDefaults.strokeColor) : + (options.strokeColor instanceof ol.expression.Expression) ? + options.strokeColor : new ol.expression.Literal(options.strokeColor); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.strokeWidth_ = !goog.isDef(options.strokeWidth) ? - new ol.ExpressionLiteral(ol.style.LineDefaults.strokeWidth) : - (options.strokeWidth instanceof ol.Expression) ? - options.strokeWidth : new ol.ExpressionLiteral(options.strokeWidth); + new ol.expression.Literal(ol.style.LineDefaults.strokeWidth) : + (options.strokeWidth instanceof ol.expression.Expression) ? + options.strokeWidth : new ol.expression.Literal(options.strokeWidth); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.opacity_ = !goog.isDef(options.opacity) ? - new ol.ExpressionLiteral(ol.style.LineDefaults.opacity) : - (options.opacity instanceof ol.Expression) ? - options.opacity : new ol.ExpressionLiteral(options.opacity); + new ol.expression.Literal(ol.style.LineDefaults.opacity) : + (options.opacity instanceof ol.expression.Expression) ? + options.opacity : new ol.expression.Literal(options.opacity); }; goog.inherits(ol.style.Line, ol.style.Symbolizer); @@ -104,13 +104,13 @@ ol.style.Line.prototype.createLiteral = function(opt_feature) { attrs = feature.getAttributes(); } - var strokeColor = this.strokeColor_.evaluate(feature, attrs); + var strokeColor = this.strokeColor_.evaluate(attrs, null, feature); goog.asserts.assertString(strokeColor, 'strokeColor must be a string'); - var strokeWidth = this.strokeWidth_.evaluate(feature, attrs); + var strokeWidth = this.strokeWidth_.evaluate(attrs, null, feature); goog.asserts.assertNumber(strokeWidth, 'strokeWidth must be a number'); - var opacity = this.opacity_.evaluate(feature, attrs); + var opacity = this.opacity_.evaluate(attrs, null, feature); goog.asserts.assertNumber(opacity, 'opacity must be a number'); return new ol.style.LineLiteral({ diff --git a/src/ol/style/polygon.js b/src/ol/style/polygon.js index b207a1ebec..6c1a296ccb 100644 --- a/src/ol/style/polygon.js +++ b/src/ol/style/polygon.js @@ -2,8 +2,8 @@ goog.provide('ol.style.Polygon'); goog.provide('ol.style.PolygonLiteral'); goog.require('goog.asserts'); -goog.require('ol.Expression'); -goog.require('ol.ExpressionLiteral'); +goog.require('ol.expression.Expression'); +goog.require('ol.expression.Literal'); goog.require('ol.style.Symbolizer'); goog.require('ol.style.SymbolizerLiteral'); @@ -80,13 +80,13 @@ ol.style.Polygon = function(options) { goog.base(this); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.fillColor_ = !goog.isDefAndNotNull(options.fillColor) ? null : - (options.fillColor instanceof ol.Expression) ? - options.fillColor : new ol.ExpressionLiteral(options.fillColor); + (options.fillColor instanceof ol.expression.Expression) ? + options.fillColor : new ol.expression.Literal(options.fillColor); // stroke handling - if any stroke property is supplied, use defaults var strokeColor = null, @@ -96,24 +96,26 @@ ol.style.Polygon = function(options) { goog.isDefAndNotNull(options.strokeWidth)) { strokeColor = !goog.isDefAndNotNull(options.strokeColor) ? - new ol.ExpressionLiteral(ol.style.PolygonDefaults.strokeColor) : - (options.strokeColor instanceof ol.Expression) ? - options.strokeColor : new ol.ExpressionLiteral(options.strokeColor); + new ol.expression.Literal(ol.style.PolygonDefaults.strokeColor) : + (options.strokeColor instanceof ol.expression.Expression) ? + options.strokeColor : + new ol.expression.Literal(options.strokeColor); strokeWidth = !goog.isDef(options.strokeWidth) ? - new ol.ExpressionLiteral(ol.style.PolygonDefaults.strokeWidth) : - (options.strokeWidth instanceof ol.Expression) ? - options.strokeWidth : new ol.ExpressionLiteral(options.strokeWidth); + new ol.expression.Literal(ol.style.PolygonDefaults.strokeWidth) : + (options.strokeWidth instanceof ol.expression.Expression) ? + options.strokeWidth : + new ol.expression.Literal(options.strokeWidth); } /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.strokeColor_ = strokeColor; /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.strokeWidth_ = strokeWidth; @@ -124,13 +126,13 @@ ol.style.Polygon = function(options) { 'Stroke or fill properties must be provided'); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.opacity_ = !goog.isDef(options.opacity) ? - new ol.ExpressionLiteral(ol.style.PolygonDefaults.opacity) : - (options.opacity instanceof ol.Expression) ? - options.opacity : new ol.ExpressionLiteral(options.opacity); + new ol.expression.Literal(ol.style.PolygonDefaults.opacity) : + (options.opacity instanceof ol.expression.Expression) ? + options.opacity : new ol.expression.Literal(options.opacity); }; goog.inherits(ol.style.Polygon, ol.style.Symbolizer); @@ -149,17 +151,17 @@ ol.style.Polygon.prototype.createLiteral = function(opt_feature) { var fillColor = goog.isNull(this.fillColor_) ? undefined : - /** @type {string} */ (this.fillColor_.evaluate(feature, attrs)); + /** @type {string} */ (this.fillColor_.evaluate(attrs, null, feature)); goog.asserts.assert(!goog.isDef(fillColor) || goog.isString(fillColor)); var strokeColor = goog.isNull(this.strokeColor_) ? undefined : - /** @type {string} */ (this.strokeColor_.evaluate(feature, attrs)); + /** @type {string} */ (this.strokeColor_.evaluate(attrs, null, feature)); goog.asserts.assert(!goog.isDef(strokeColor) || goog.isString(strokeColor)); var strokeWidth = goog.isNull(this.strokeWidth_) ? undefined : - /** @type {number} */ (this.strokeWidth_.evaluate(feature, attrs)); + /** @type {number} */ (this.strokeWidth_.evaluate(attrs, null, feature)); goog.asserts.assert(!goog.isDef(strokeWidth) || goog.isNumber(strokeWidth)); goog.asserts.assert( @@ -167,7 +169,7 @@ ol.style.Polygon.prototype.createLiteral = function(opt_feature) { (goog.isDef(strokeColor) && goog.isDef(strokeWidth)), 'either fill style or strokeColor and strokeWidth must be defined'); - var opacity = this.opacity_.evaluate(feature, attrs); + var opacity = this.opacity_.evaluate(attrs, null, feature); goog.asserts.assertNumber(opacity, 'opacity must be a number'); return new ol.style.PolygonLiteral({ diff --git a/src/ol/style/shape.js b/src/ol/style/shape.js index acc8a98f8d..a2b2ea9063 100644 --- a/src/ol/style/shape.js +++ b/src/ol/style/shape.js @@ -3,8 +3,8 @@ goog.provide('ol.style.ShapeLiteral'); goog.provide('ol.style.ShapeType'); goog.require('goog.asserts'); -goog.require('ol.Expression'); -goog.require('ol.ExpressionLiteral'); +goog.require('ol.expression.Expression'); +goog.require('ol.expression.Literal'); goog.require('ol.style.Point'); goog.require('ol.style.PointLiteral'); @@ -106,22 +106,22 @@ ol.style.Shape = function(options) { options.type : ol.style.ShapeDefaults.type); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.size_ = !goog.isDef(options.size) ? - new ol.ExpressionLiteral(ol.style.ShapeDefaults.size) : - (options.size instanceof ol.Expression) ? - options.size : new ol.ExpressionLiteral(options.size); + new ol.expression.Literal(ol.style.ShapeDefaults.size) : + (options.size instanceof ol.expression.Expression) ? + options.size : new ol.expression.Literal(options.size); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.fillColor_ = !goog.isDefAndNotNull(options.fillColor) ? null : - (options.fillColor instanceof ol.Expression) ? - options.fillColor : new ol.ExpressionLiteral(options.fillColor); + (options.fillColor instanceof ol.expression.Expression) ? + options.fillColor : new ol.expression.Literal(options.fillColor); // stroke handling - if any stroke property is supplied, use defaults var strokeColor = null, @@ -131,24 +131,26 @@ ol.style.Shape = function(options) { goog.isDefAndNotNull(options.strokeWidth)) { strokeColor = !goog.isDefAndNotNull(options.strokeColor) ? - new ol.ExpressionLiteral(ol.style.ShapeDefaults.strokeColor) : - (options.strokeColor instanceof ol.Expression) ? - options.strokeColor : new ol.ExpressionLiteral(options.strokeColor); + new ol.expression.Literal(ol.style.ShapeDefaults.strokeColor) : + (options.strokeColor instanceof ol.expression.Expression) ? + options.strokeColor : + new ol.expression.Literal(options.strokeColor); strokeWidth = !goog.isDef(options.strokeWidth) ? - new ol.ExpressionLiteral(ol.style.ShapeDefaults.strokeWidth) : - (options.strokeWidth instanceof ol.Expression) ? - options.strokeWidth : new ol.ExpressionLiteral(options.strokeWidth); + new ol.expression.Literal(ol.style.ShapeDefaults.strokeWidth) : + (options.strokeWidth instanceof ol.expression.Expression) ? + options.strokeWidth : + new ol.expression.Literal(options.strokeWidth); } /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.strokeColor_ = strokeColor; /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.strokeWidth_ = strokeWidth; @@ -159,13 +161,13 @@ ol.style.Shape = function(options) { 'Stroke or fill properties must be provided'); /** - * @type {ol.Expression} + * @type {ol.expression.Expression} * @private */ this.opacity_ = !goog.isDef(options.opacity) ? - new ol.ExpressionLiteral(ol.style.ShapeDefaults.opacity) : - (options.opacity instanceof ol.Expression) ? - options.opacity : new ol.ExpressionLiteral(options.opacity); + new ol.expression.Literal(ol.style.ShapeDefaults.opacity) : + (options.opacity instanceof ol.expression.Expression) ? + options.opacity : new ol.expression.Literal(options.opacity); }; @@ -181,22 +183,22 @@ ol.style.Shape.prototype.createLiteral = function(opt_feature) { attrs = feature.getAttributes(); } - var size = this.size_.evaluate(feature, attrs); + var size = this.size_.evaluate(attrs, null, feature); goog.asserts.assertNumber(size, 'size must be a number'); var fillColor = goog.isNull(this.fillColor_) ? undefined : - /** @type {string} */ (this.fillColor_.evaluate(feature, attrs)); + /** @type {string} */ (this.fillColor_.evaluate(attrs, null, feature)); goog.asserts.assert(!goog.isDef(fillColor) || goog.isString(fillColor)); var strokeColor = goog.isNull(this.strokeColor_) ? undefined : - /** @type {string} */ (this.strokeColor_.evaluate(feature, attrs)); + /** @type {string} */ (this.strokeColor_.evaluate(attrs, null, feature)); goog.asserts.assert(!goog.isDef(strokeColor) || goog.isString(strokeColor)); var strokeWidth = goog.isNull(this.strokeWidth_) ? undefined : - /** @type {number} */ (this.strokeWidth_.evaluate(feature, attrs)); + /** @type {number} */ (this.strokeWidth_.evaluate(attrs, null, feature)); goog.asserts.assert(!goog.isDef(strokeWidth) || goog.isNumber(strokeWidth)); goog.asserts.assert( @@ -204,7 +206,7 @@ ol.style.Shape.prototype.createLiteral = function(opt_feature) { (goog.isDef(strokeColor) && goog.isDef(strokeWidth)), 'either fill style or strokeColor and strokeWidth must be defined'); - var opacity = this.opacity_.evaluate(feature, attrs); + var opacity = this.opacity_.evaluate(attrs, null, feature); goog.asserts.assertNumber(opacity, 'opacity must be a number'); return new ol.style.ShapeLiteral({ diff --git a/test/spec/ol/expression.test.js b/test/spec/ol/expression.test.js deleted file mode 100644 index fb9735d1d2..0000000000 --- a/test/spec/ol/expression.test.js +++ /dev/null @@ -1,78 +0,0 @@ -goog.provide('ol.test.Expression'); - -describe('ol.Expression', function() { - - describe('constructor', function() { - it('creates an expression', function() { - var exp = new ol.Expression('foo'); - expect(exp).to.be.a(ol.Expression); - }); - }); - - describe('#evaluate()', function() { - - it('evaluates and returns the result', function() { - // test cases here with unique values only (lack of messages in expect) - var cases = [{ - source: '42', result: 42 - }, { - source: '10 + 10', result: 20 - }, { - source: '"a" + "b"', result: 'ab' - }, { - source: 'Math.floor(Math.PI)', result: 3 - }, { - source: 'ol', result: ol - }, { - source: 'this', result: goog.global - }]; - - var c, exp; - for (var i = 0, ii = cases.length; i < ii; ++i) { - c = cases[i]; - exp = new ol.Expression(c.source); - expect(exp.evaluate()).to.be(c.result); - } - }); - - it('accepts an optional this argument', function() { - function Thing() { - this.works = true; - }; - - var exp = new ol.Expression('this.works ? "yes" : "no"'); - expect(exp.evaluate(new Thing())).to.be('yes'); - expect(exp.evaluate({})).to.be('no'); - }); - - it('accepts an optional scope argument', function() { - var exp; - var scope = { - greeting: 'hello world', - punctuation: '!', - pick: function(array, index) { - return array[index]; - } - }; - - // access two members in the scope - exp = new ol.Expression('greeting + punctuation'); - expect(exp.evaluate({}, scope)).to.be('hello world!'); - - // call a function in the scope - exp = new ol.Expression( - 'pick([10, 42, "chicken"], 2) + Math.floor(Math.PI)'); - expect(exp.evaluate({}, scope)).to.be('chicken3'); - - }); - - it('throws on error', function() { - var exp = new ol.Expression('@*)$(&'); - expect(function() {exp.evaluate()}).to.throwException(); - }); - - }); - -}); - -goog.require('ol.Expression'); diff --git a/test/spec/ol/layer/vectorlayer.test.js b/test/spec/ol/layer/vectorlayer.test.js index 243750fb35..5deba1c925 100644 --- a/test/spec/ol/layer/vectorlayer.test.js +++ b/test/spec/ol/layer/vectorlayer.test.js @@ -107,7 +107,7 @@ describe('ol.layer.Vector', function() { symbolizers: [ new ol.style.Line({ strokeWidth: 2, - strokeColor: new ol.Expression('colorProperty'), + strokeColor: ol.expression.parse('colorProperty'), opacity: 1 }) ] @@ -144,7 +144,7 @@ describe('ol.layer.Vector', function() { it('groups equal symbolizers also when defined on features', function() { var symbolizer = new ol.style.Line({ strokeWidth: 3, - strokeColor: new ol.Expression('colorProperty'), + strokeColor: ol.expression.parse('colorProperty'), opacity: 1 }); var anotherSymbolizer = new ol.style.Line({ @@ -177,8 +177,8 @@ describe('ol.layer.Vector', function() { }); goog.require('goog.dispose'); -goog.require('ol.Expression'); goog.require('ol.Feature'); +goog.require('ol.expression'); goog.require('ol.filter.Extent'); goog.require('ol.filter.Geometry'); goog.require('ol.filter.Logical'); diff --git a/test/spec/ol/style/line.test.js b/test/spec/ol/style/line.test.js index eaf2471dfb..f57d4a71fa 100644 --- a/test/spec/ol/style/line.test.js +++ b/test/spec/ol/style/line.test.js @@ -42,8 +42,8 @@ describe('ol.style.Line', function() { it('accepts expressions', function() { var symbolizer = new ol.style.Line({ - opacity: new ol.Expression('value / 100'), - strokeWidth: ol.Expression('widthAttr') + opacity: ol.expression.parse('value / 100'), + strokeWidth: ol.expression.parse('widthAttr') }); expect(symbolizer).to.be.a(ol.style.Line); }); @@ -54,8 +54,8 @@ describe('ol.style.Line', function() { it('evaluates expressions with the given feature', function() { var symbolizer = new ol.style.Line({ - opacity: new ol.Expression('value / 100'), - strokeWidth: ol.Expression('widthAttr') + opacity: ol.expression.parse('value / 100'), + strokeWidth: ol.expression.parse('widthAttr') }); var feature = new ol.Feature({ @@ -73,7 +73,7 @@ describe('ol.style.Line', function() { }); -goog.require('ol.Expression'); goog.require('ol.Feature'); +goog.require('ol.expression'); goog.require('ol.style.Line'); goog.require('ol.style.LineLiteral'); diff --git a/test/spec/ol/style/polygon.test.js b/test/spec/ol/style/polygon.test.js index b56bb1b160..e8a9453899 100644 --- a/test/spec/ol/style/polygon.test.js +++ b/test/spec/ol/style/polygon.test.js @@ -45,8 +45,8 @@ describe('ol.style.Polygon', function() { it('accepts expressions', function() { var symbolizer = new ol.style.Polygon({ - opacity: new ol.Expression('value / 100'), - fillColor: new ol.Expression('fillAttr') + opacity: ol.expression.parse('value / 100'), + fillColor: ol.expression.parse('fillAttr') }); expect(symbolizer).to.be.a(ol.style.Polygon); }); @@ -57,8 +57,8 @@ describe('ol.style.Polygon', function() { it('evaluates expressions with the given feature', function() { var symbolizer = new ol.style.Polygon({ - opacity: new ol.Expression('value / 100'), - fillColor: new ol.Expression('fillAttr') + opacity: ol.expression.parse('value / 100'), + fillColor: ol.expression.parse('fillAttr') }); var feature = new ol.Feature({ @@ -89,7 +89,7 @@ describe('ol.style.Polygon', function() { }); -goog.require('ol.Expression'); goog.require('ol.Feature'); +goog.require('ol.expression'); goog.require('ol.style.Polygon'); goog.require('ol.style.PolygonLiteral'); diff --git a/test/spec/ol/style/shape.test.js b/test/spec/ol/style/shape.test.js index 361ddc6727..90a1158f06 100644 --- a/test/spec/ol/style/shape.test.js +++ b/test/spec/ol/style/shape.test.js @@ -51,8 +51,8 @@ describe('ol.style.Shape', function() { it('accepts expressions', function() { var symbolizer = new ol.style.Shape({ - size: new ol.Expression('sizeAttr'), - strokeColor: new ol.Expression('color') + size: ol.expression.parse('sizeAttr'), + strokeColor: ol.expression.parse('color') }); expect(symbolizer).to.be.a(ol.style.Shape); }); @@ -63,8 +63,8 @@ describe('ol.style.Shape', function() { it('evaluates expressions with the given feature', function() { var symbolizer = new ol.style.Shape({ - size: new ol.Expression('sizeAttr'), - opacity: new ol.Expression('opacityAttr'), + size: ol.expression.parse('sizeAttr'), + opacity: ol.expression.parse('opacityAttr'), fillColor: '#BADA55' }); @@ -99,8 +99,8 @@ describe('ol.style.Shape', function() { it('applies default type if none provided', function() { var symbolizer = new ol.style.Shape({ - size: new ol.Expression('sizeAttr'), - opacity: new ol.Expression('opacityAttr'), + size: ol.expression.parse('sizeAttr'), + opacity: ol.expression.parse('opacityAttr'), fillColor: '#BADA55' }); @@ -119,8 +119,8 @@ describe('ol.style.Shape', function() { }); -goog.require('ol.Expression'); goog.require('ol.Feature'); +goog.require('ol.expression'); goog.require('ol.style.Shape'); goog.require('ol.style.ShapeLiteral'); goog.require('ol.style.ShapeType');