Skip to content

Commit

Permalink
feat(lambda-tiler): Ensure terrain source for all style json configs. (
Browse files Browse the repository at this point in the history
…#3299)

### Motivation

We need to ensure a terrain source in all style json configs before the
production release. Then we could do another config release for add
terrain source into style config.
linz/basemaps-config#916

### Modifications

Check and add terrain source for get style config api.

### Verification


![image](https://github.com/linz/basemaps/assets/12163920/01544ba9-469f-4a5f-ba9a-9d97502e2fc3)
  • Loading branch information
Wentao-Kuang authored Jun 26, 2024
1 parent 52fbf80 commit 13aedf8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
51 changes: 49 additions & 2 deletions packages/lambda-tiler/src/routes/__tests__/tile.style.json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,54 @@ describe('/v1/styles', () => {
]);
});

const fakeStyleConfig = {
const fakeVectorStyleConfig = {
id: 'test',
name: 'test',
sources: {
basemaps_vector: {
type: 'vector',
url: `/vector`,
},
},
layers: [
{
layout: {
visibility: 'visible',
},
paint: {
'background-color': 'rgba(206, 229, 242, 1)',
},
id: 'Background1',
type: 'background',
minzoom: 0,
},
],
};

const fakeVectorRecord = {
id: 'st_topolite',
name: 'topolite',
style: fakeVectorStyleConfig,
};

it('should ensure terrain for all style config', async () => {
const request = mockUrlRequest('/v1/styles/topolite.json', '?terrain=LINZ-Terrain', Api.header);
config.put(fakeVectorRecord);
config.put(TileSetElevation);

const res = await handler.router.handle(request);
assert.equal(res.status, 200, res.statusDescription);

const body = JSON.parse(Buffer.from(res.body, 'base64').toString()) as StyleJson;
const rasterDemSource = body.sources['LINZ-Terrain'] as unknown as SourceRaster;

assert.deepEqual(rasterDemSource.type, 'raster-dem');
assert.deepEqual(rasterDemSource.tiles, [
`https://tiles.test/v1/tiles/elevation/WebMercatorQuad/{z}/{x}/{y}.png?api=${Api.key}&pipeline=terrain-rgb`,
]);
});

const fakeAerialStyleConfig = {
id: 'test',
name: 'test',
sources: {
Expand Down Expand Up @@ -306,7 +353,7 @@ describe('/v1/styles', () => {
const fakeAerialRecord = {
id: 'st_aerial',
name: 'aerial',
style: fakeStyleConfig,
style: fakeAerialStyleConfig,
};

it('should set terrain via parameter for style config', async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/lambda-tiler/src/routes/tile.style.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ export async function styleJsonGet(req: LambdaHttpRequest<StyleGet>): Promise<La
styleConfig.style.layers.filter((f) => !excluded.has(f.id.toLowerCase())),
);

// Ensure elevation for style json config
// TODO: We should remove this after adding terrain source into style configs. PR-916
await ensureTerrain(req, tileMatrix, apiKey, style);

// Add terrain in style
if (terrain) setStyleTerrain(style, terrain);

Expand Down

0 comments on commit 13aedf8

Please sign in to comment.