diff --git a/packages/lambda-tiler/src/routes/__tests__/tile.style.json.test.ts b/packages/lambda-tiler/src/routes/__tests__/tile.style.json.test.ts index 0f795123b..79cfc8c05 100644 --- a/packages/lambda-tiler/src/routes/__tests__/tile.style.json.test.ts +++ b/packages/lambda-tiler/src/routes/__tests__/tile.style.json.test.ts @@ -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); + }); }); diff --git a/packages/lambda-tiler/src/routes/tile.style.json.ts b/packages/lambda-tiler/src/routes/tile.style.json.ts index 7b2e48336..3ecae0406 100644 --- a/packages/lambda-tiler/src/routes/tile.style.json.ts +++ b/packages/lambda-tiler/src/routes/tile.style.json.ts @@ -105,6 +105,15 @@ async function setStyleLabels(req: LambdaHttpRequest, style: StyleJson return; } + const layerId = new Set(); + 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;