Merge pull request #1093 from ahocevar/symbolizer-id

Adding counter expression function
This commit is contained in:
ahocevar
2013-10-03 12:16:02 -07:00
2 changed files with 27 additions and 0 deletions

View File

@@ -96,6 +96,7 @@ ol.expr.lib = {};
*/
ol.expr.functions = {
CONCAT: 'concat',
COUNTER: 'counter',
EXTENT: 'extent',
FID: 'fid',
GEOMETRY_TYPE: 'geometryType',
@@ -126,6 +127,23 @@ ol.expr.lib[ol.expr.functions.CONCAT] = function(var_args) {
};
/**
* Returns a counter which increases every time this function is called.
* @param {number=} opt_start Start. If not provided, the counter starts at 1.
* @return {number} Counter.
*/
ol.expr.lib[ol.expr.functions.COUNTER] = (function() {
var counter = 0;
return function(opt_start) {
var result = ++counter;
if (goog.isDef(opt_start)) {
result += opt_start;
}
return result;
};
})();
/**
* Determine if a feature's extent intersects the provided extent.
* @param {number} minX Minimum x-coordinate value.

View File

@@ -674,6 +674,15 @@ describe('ol.expr.lib', function() {
});
describe('counter()', function() {
var counter = parse('counter()');
var counterWithStart = parse('counter(1000)');
var start = evaluate(counter);
expect(evaluate(counter).to.be(start + 1));
expect(evaluate(counter).to.be(start + 2));
expect(evaluate(counterWithStart).to.be(start + 3 + 1000));
});
describe('extent()', function() {
var nw = new ol.Feature({