Merge pull request #1093 from ahocevar/symbolizer-id
Adding counter expression function
This commit is contained in:
@@ -96,6 +96,7 @@ ol.expr.lib = {};
|
|||||||
*/
|
*/
|
||||||
ol.expr.functions = {
|
ol.expr.functions = {
|
||||||
CONCAT: 'concat',
|
CONCAT: 'concat',
|
||||||
|
COUNTER: 'counter',
|
||||||
EXTENT: 'extent',
|
EXTENT: 'extent',
|
||||||
FID: 'fid',
|
FID: 'fid',
|
||||||
GEOMETRY_TYPE: 'geometryType',
|
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.
|
* Determine if a feature's extent intersects the provided extent.
|
||||||
* @param {number} minX Minimum x-coordinate value.
|
* @param {number} minX Minimum x-coordinate value.
|
||||||
|
|||||||
@@ -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() {
|
describe('extent()', function() {
|
||||||
|
|
||||||
var nw = new ol.Feature({
|
var nw = new ol.Feature({
|
||||||
|
|||||||
Reference in New Issue
Block a user