Skip to content

Commit 5d2d9c6

Browse files
authored
fix(lambda-tiler): NZTM terrain been multiplied twice. BM-1122 (#3373)
### Motivation Basemap terrain exaggeration for NZTM been multiplied twice. ![image](https://github.com/user-attachments/assets/4e7b4a77-431c-4f0e-be5d-206787ae2452) ![image](https://github.com/user-attachments/assets/e8a64789-7e70-4bb9-97f8-c8cac4e06e36) ### Modifications We have manually multiplied the NZTM terrain exaggeration when converting the style json earlier, however, we got default setting to fix them as 4.4 in `DefaultExaggeration`, so we don't need to covert the exaggeration twice to make it too large. ### Verification Local test and unit test. ![image](https://github.com/user-attachments/assets/42f35f6f-6410-4ccd-87f6-c007f9faae7f)
1 parent 5ce567f commit 5d2d9c6

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

packages/lambda-tiler/src/routes/__tests__/tile.style.json.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import assert from 'node:assert';
22
import { afterEach, before, beforeEach, describe, it } from 'node:test';
33

44
import { ConfigProviderMemory, SourceRaster, StyleJson } from '@basemaps/config';
5-
import { Terrain } from '@basemaps/config/src/config/vector.style.js';
5+
import { DefaultExaggeration, Terrain } from '@basemaps/config/build/config/vector.style.js';
6+
import { Nztm2000QuadTms } from '@basemaps/geo';
67
import { Env } from '@basemaps/shared';
78
import { createSandbox } from 'sinon';
89

@@ -441,7 +442,7 @@ describe('/v1/styles', () => {
441442
},
442443
],
443444
terrain: {
444-
exaggeration: 1.1,
445+
exaggeration: DefaultExaggeration[Nztm2000QuadTms.identifier],
445446
},
446447
},
447448
};

packages/lambda-tiler/src/routes/tile.style.json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export interface StyleConfig {
9090
/**
9191
* Turn on the terrain setting in the style json
9292
*/
93-
function setStyleTerrain(style: StyleJson, terrain: string, tileMatrix: TileMatrixSet): void {
93+
export function setStyleTerrain(style: StyleJson, terrain: string, tileMatrix: TileMatrixSet): void {
9494
const source = Object.keys(style.sources).find((s) => s === terrain);
9595
if (source == null) throw new LambdaHttpResponse(400, `Terrain: ${terrain} does not exists in the style source.`);
9696
style.terrain = {

packages/lambda-tiler/src/util/__test__/nztm.style.test.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import assert from 'node:assert';
22
import { describe, it } from 'node:test';
33

44
import { StyleJson } from '@basemaps/config';
5+
import { GoogleTms, Nztm2000QuadTms } from '@basemaps/geo';
56

7+
import { setStyleTerrain } from '../../routes/tile.style.json.js';
68
import { convertStyleToNztmStyle } from '../nztm.style.js';
79

810
describe('NZTM2000QuadStyle', () => {
@@ -25,9 +27,6 @@ describe('NZTM2000QuadStyle', () => {
2527

2628
convertStyleToNztmStyle(baseStyle);
2729
assert.equal(baseStyle.terrain?.exaggeration, 1.1);
28-
29-
convertStyleToNztmStyle(baseStyle, false);
30-
assert.equal(baseStyle.terrain?.exaggeration, 4.4);
3130
});
3231

3332
it('should convert min/maxzooms', () => {
@@ -39,13 +38,24 @@ describe('NZTM2000QuadStyle', () => {
3938
assert.deepEqual(newStyle.layers[0], { minzoom: 3, maxzoom: 8, id: 'something', type: '' });
4039
});
4140

42-
it('should offset terrain', () => {
43-
const newStyle = convertStyleToNztmStyle({
41+
it('should not offset terrain for WebMecator', () => {
42+
const testStyle: StyleJson = {
4443
...fakeStyle,
45-
terrain: { exaggeration: 1.1, source: 'abc' },
46-
});
44+
sources: { 'LINZ-Terrain': { type: 'raster-dem', tiles: ['https://example.com/{z}/{x}/{y}.png'] } },
45+
};
46+
setStyleTerrain(testStyle, 'LINZ-Terrain', GoogleTms);
47+
48+
assert.deepEqual(testStyle.terrain, { exaggeration: 1.2, source: 'LINZ-Terrain' });
49+
});
50+
51+
it('should offset terrain for NZTM', () => {
52+
const testStyle: StyleJson = {
53+
...fakeStyle,
54+
sources: { 'LINZ-Terrain': { type: 'raster-dem', tiles: ['https://example.com/{z}/{x}/{y}.png'] } },
55+
};
56+
setStyleTerrain(testStyle, 'LINZ-Terrain', Nztm2000QuadTms);
4757

48-
assert.deepEqual(newStyle.terrain, { exaggeration: 4.4, source: 'abc' });
58+
assert.deepEqual(testStyle.terrain, { exaggeration: 4.4, source: 'LINZ-Terrain' });
4959
});
5060

5161
it('should convert stops inside of paint and layout', () => {

packages/lambda-tiler/src/util/nztm.style.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,5 @@ export function convertStyleToNztmStyle(inputStyle: StyleJson, clone: boolean =
3737
}
3838
}
3939

40-
/** Based on {@link DefaultExaggeration} offsetting by 2 two levels changes the exaggeration needed by approx 4x */
41-
if (style.terrain) style.terrain.exaggeration = style.terrain.exaggeration * 4;
42-
4340
return style;
4441
}

0 commit comments

Comments
 (0)