Skip to content

Commit

Permalink
fix duplicate layer test, enforce layer id uniqueness (#6147)
Browse files Browse the repository at this point in the history
* fix duplicate layer test, enforce layer id uniqueness

* remove unneeded stub
  • Loading branch information
mollymerp authored Feb 13, 2018
1 parent e077b78 commit b713e25
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,11 @@ class Style extends Evented {

const id = layerObject.id;

if (this.getLayer(id)) {
this.fire('error', {error: new Error(`Layer with id "${id}" already exists on this map`)});
return;
}

if (typeof layerObject.source === 'object') {
this.addSource(id, layerObject.source);
layerObject = util.clone(layerObject);
Expand Down
4 changes: 1 addition & 3 deletions test/unit/style/style.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,15 +997,13 @@ test('Style#addLayer', (t) => {
const layer = {id: 'background', type: 'background'};

style.on('error', (e) => {
t.deepEqual(e.layer, {id: 'background'});
t.notOk(/duplicate/.match(e.error.message));
t.match(e.error, /already exists/);
t.end();
});

style.on('style.load', () => {
style.addLayer(layer);
style.addLayer(layer);
t.end();
});
});

Expand Down

0 comments on commit b713e25

Please sign in to comment.