Involves additions to (there will be subsequent pull requests for other classes): - ol.Attribution - ol.Collection - ol.Expression - ol.Feature - ol.Geolocation - ol.Map - ol.Object - ol.Overlay - ol.Projection - ol.View2D - ol.control.Attribution - ol.control.Control - ol.control.FullScreen - ol.control.Logo - ol.control.MousePosition - ol.control.ScaleLine - ol.control.Zoom - ol.control.ZoomSlider - ol.dom.Input - ol.filter.Filter - ol.filter.Geometry - ol.filter.Logical
81 lines
1.9 KiB
JavaScript
81 lines
1.9 KiB
JavaScript
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_;
|
|
};
|