Skip to content

Commit

Permalink
fix zoom + feature functions for fractional zooms
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Apr 19, 2016
1 parent 08bcfb8 commit a0a3773
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand All @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});


});


Expand Down

0 comments on commit a0a3773

Please sign in to comment.