Allow registration of custom functions for expressions

This commit is contained in:
Tim Schaub
2013-06-21 11:13:20 -06:00
parent 8e8b26805f
commit 233595ac75
4 changed files with 23 additions and 8 deletions

View File

@@ -1 +1,2 @@
@exportSymbol ol.expression.parse
@exportSymbol ol.expression.register

View File

@@ -32,7 +32,7 @@ ol.expression.evaluateFeature = function(expr, opt_feature) {
/**
* Parse an expression
* Parse an expression.
* @param {string} source The expression source (e.g. `'foo + 2'`).
* @return {ol.expression.Expression} An expression instance that can be
* evaluated within some scope to provide a value.
@@ -43,6 +43,18 @@ ol.expression.parse = function(source) {
};
/**
* Register a library function to be used in expressions.
* @param {string} name The function name (e.g. 'myFunc').
* @param {function(this:ol.Feature)} func The function to be called in an
* expression. This function will be called with a feature as the `this`
* argument when the expression is evaluated in the context of a features.
*/
ol.expression.register = function(name, func) {
ol.expression.lib[name] = func;
};
/**
* Determines whether an expression is a call expression that calls one of the
* `ol.expression.lib` functions.