diff --git a/index.js b/index.js index b5ffd50..ca7e30f 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,7 @@ function createFunction(parameters, defaultType) { var stop = parameters.stops[s]; if (featureFunctions[stop[0].zoom] === undefined) { featureFunctions[stop[0].zoom] = { + zoom: stop[0].zoom, type: parameters.type, property: parameters.property, stops: [] @@ -41,7 +42,7 @@ function createFunction(parameters, defaultType) { } for (var z in featureFunctions) { - featureFunctionStops.push([parseInt(z), createFunction(featureFunctions[z])]); + featureFunctionStops.push([featureFunctions[z].zoom, createFunction(featureFunctions[z])]); } fun = function(zoom, feature) { return evaluateExponentialFunction({ stops: featureFunctionStops, base: parameters.base }, zoom)(zoom, feature); diff --git a/test/test.js b/test/test.js index 9cf02b4..7989afa 100644 --- a/test/test.js +++ b/test/test.js @@ -176,6 +176,26 @@ test('function types', function(t) { t.end(); }); + + t.test('fractional zoom', function(t) { + var f = MapboxGLFunction({ + type: 'exponential', + property: 'prop', + base: 1, + stops: [ + [{ zoom: 1.9, value: 0 }, 4], + [{ zoom: 2.1, value: 0 }, 8] + ] + }); + + t.equal(f(1.9, { prop: 1 }), 4); + t.equal(f(2, { prop: 1 }), 6); + t.equal(f(2.1, { prop: 1 }), 8); + + t.end(); + }); + + });