Skip to content

Commit

Permalink
Fix default calculation for categorical zoom-and-property functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Apr 28, 2017
1 parent d3b39cb commit 4060679
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/style-spec/function/index.js
Expand Up @@ -108,6 +108,7 @@ function createFunction(parameters, propertySpec) {
zoom: zoom,
type: parameters.type,
property: parameters.property,
default: parameters.default,
stops: []
};
zoomStops.push(zoom);
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,50 @@
{
"version": 8,
"metadata": {
"test": {
"height": 64,
"width": 64
}
},
"sources": {
"geojson": {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {
"foo": "bar"
},
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
}
}
}
},
"layers": [
{
"id": "circle",
"type": "circle",
"source": "geojson",
"paint": {
"circle-color": {
"type": "categorical",
"property": "foo",
"stops": [
[
{
"value": "nonesuch",
"zoom": 0
},
"red"
]
],
"default": "green"
}
}
}
]
}
17 changes: 17 additions & 0 deletions test/unit/style-spec/function.test.js
Expand Up @@ -715,6 +715,23 @@ test('categorical function', (t) => {
t.end();
});

t.test('string zoom-and-property function default', (t) => {
const f = createFunction({
property: 'foo',
type: 'categorical',
stops: [[{zoom: 0, value: 'bar'}, 'zero']],
default: 'default'
}, {
type: 'string'
});

t.equal(f(0, {}), 'default');
t.equal(f(0, {foo: 3}), 'default');
t.equal(f(0, {foo: 'bar'}), 'zero');

t.end();
});

t.test('strict type checking', (t) => {
const numberKeys = createFunction({
property: 'foo',
Expand Down

0 comments on commit 4060679

Please sign in to comment.