Skip to content

Commit

Permalink
Fix addVector bug. Fixes #22.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevage committed Apr 11, 2021
1 parent 23da831 commit 7d13e64
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.js
Expand Up @@ -427,18 +427,20 @@ Object.assign(Utils.prototype, {
.map(l => l.id);
},

addVector(id, props) {
addVector(id, props, extraProps = {}) {
if (typeof props === 'string') {
if (props.match(/\{z\}/)) {
return this.addSource(id, {
type: 'vector',
tiles: [props],
...extraProps,
});
} else {
// mapbox://, http://.../index.json
return this.addSource(id, {
type: 'vector',
url: props,
...extraProps,
});
}
} else {
Expand Down
20 changes: 20 additions & 0 deletions src/index.test.js
Expand Up @@ -459,6 +459,14 @@ describe('Streamlined addVector', () => {
url: 'mapbox://foo.blah',
});
});
test('addVector("mapbox://", { maxzoom: 13 })', () => {
map.U.addVector('mysource', 'mapbox://foo.blah', { maxzoom: 13 });
expect(map.getStyle().sources['mysource']).toEqual({
type: 'vector',
url: 'mapbox://foo.blah',
maxzoom: 13,
});
});
test('addVector("http://tiles.example.com/tiles/{z}/{x}/{y}.pbf")', () => {
map.U.addVector(
'mysource',
Expand All @@ -469,6 +477,18 @@ describe('Streamlined addVector', () => {
tiles: ['http://tiles.example.com/tiles/{z}/{x}/{y}.pbf'],
});
});
test('addVector("http://tiles.example.com/tiles/{z}/{x}/{y}.pbf", { maxzoom: 13 })', () => {
map.U.addVector(
'mysource',
'http://tiles.example.com/tiles/{z}/{x}/{y}.pbf',
{ maxzoom: 13 }
);
expect(map.getStyle().sources['mysource']).toEqual({
type: 'vector',
tiles: ['http://tiles.example.com/tiles/{z}/{x}/{y}.pbf'],
maxzoom: 13,
});
});
});

describe('Adding layers to a source', () => {
Expand Down

0 comments on commit 7d13e64

Please sign in to comment.