Skip to content

Commit

Permalink
fix(lambda-tiler): do not join layers where ids would be duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Aug 26, 2024
1 parent 49524c0 commit b1298fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/lambda-tiler/src/routes/__tests__/tile.style.json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,15 @@ describe('/v1/styles', () => {
assert.equal(body.sources['basemaps_vector']?.type, 'vector');
assert.equal(body.layers.length, 2);
});

it('should error when joining layers with duplicate ids', async () => {
const fakeStyle = { id: 'st_labels', name: 'labels', style: fakeVectorStyleConfig };
config.put(fakeStyle);
config.put(TileSetAerial);

const request = mockUrlRequest('/v1/styles/labels.json', `?labels=true`, Api.header);
const res = await handler.router.handle(request);
assert.equal(res.status, 400, res.statusDescription);
assert.equal(res.statusDescription.includes('Background1'), true);
});
});
9 changes: 9 additions & 0 deletions packages/lambda-tiler/src/routes/tile.style.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ async function setStyleLabels(req: LambdaHttpRequest<StyleGet>, style: StyleJson
return;
}

const layerId = new Set<string>();
for (const l of style.layers) layerId.add(l.id);

for (const newLayers of labels.style.layers) {
if (layerId.has(newLayers.id)) {
throw new LambdaHttpResponse(400, 'Cannot merge styles with duplicate layerIds: ' + newLayers.id);
}
}

if (style.glyphs == null) style.glyphs = labels.style.glyphs;
if (style.sprite == null) style.sprite = labels.style.sprite;
if (style.sky == null) style.sky = labels.style.sky;
Expand Down

0 comments on commit b1298fa

Please sign in to comment.