Skip to content

Commit

Permalink
fix(lambda-tiler): NZTM terrain been multiplied twice. BM-1122 (#3373)
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
Wentao-Kuang authored Nov 21, 2024
1 parent 5ce567f commit 5d2d9c6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import assert from 'node:assert';
import { afterEach, before, beforeEach, describe, it } from 'node:test';

import { ConfigProviderMemory, SourceRaster, StyleJson } from '@basemaps/config';
import { Terrain } from '@basemaps/config/src/config/vector.style.js';
import { DefaultExaggeration, Terrain } from '@basemaps/config/build/config/vector.style.js';
import { Nztm2000QuadTms } from '@basemaps/geo';
import { Env } from '@basemaps/shared';
import { createSandbox } from 'sinon';

Expand Down Expand Up @@ -441,7 +442,7 @@ describe('/v1/styles', () => {
},
],
terrain: {
exaggeration: 1.1,
exaggeration: DefaultExaggeration[Nztm2000QuadTms.identifier],
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/lambda-tiler/src/routes/tile.style.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface StyleConfig {
/**
* Turn on the terrain setting in the style json
*/
function setStyleTerrain(style: StyleJson, terrain: string, tileMatrix: TileMatrixSet): void {
export function setStyleTerrain(style: StyleJson, terrain: string, tileMatrix: TileMatrixSet): void {
const source = Object.keys(style.sources).find((s) => s === terrain);
if (source == null) throw new LambdaHttpResponse(400, `Terrain: ${terrain} does not exists in the style source.`);
style.terrain = {
Expand Down
26 changes: 18 additions & 8 deletions packages/lambda-tiler/src/util/__test__/nztm.style.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import assert from 'node:assert';
import { describe, it } from 'node:test';

import { StyleJson } from '@basemaps/config';
import { GoogleTms, Nztm2000QuadTms } from '@basemaps/geo';

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

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

convertStyleToNztmStyle(baseStyle);
assert.equal(baseStyle.terrain?.exaggeration, 1.1);

convertStyleToNztmStyle(baseStyle, false);
assert.equal(baseStyle.terrain?.exaggeration, 4.4);
});

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

it('should offset terrain', () => {
const newStyle = convertStyleToNztmStyle({
it('should not offset terrain for WebMecator', () => {
const testStyle: StyleJson = {
...fakeStyle,
terrain: { exaggeration: 1.1, source: 'abc' },
});
sources: { 'LINZ-Terrain': { type: 'raster-dem', tiles: ['https://example.com/{z}/{x}/{y}.png'] } },
};
setStyleTerrain(testStyle, 'LINZ-Terrain', GoogleTms);

assert.deepEqual(testStyle.terrain, { exaggeration: 1.2, source: 'LINZ-Terrain' });
});

it('should offset terrain for NZTM', () => {
const testStyle: StyleJson = {
...fakeStyle,
sources: { 'LINZ-Terrain': { type: 'raster-dem', tiles: ['https://example.com/{z}/{x}/{y}.png'] } },
};
setStyleTerrain(testStyle, 'LINZ-Terrain', Nztm2000QuadTms);

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

it('should convert stops inside of paint and layout', () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/lambda-tiler/src/util/nztm.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,5 @@ export function convertStyleToNztmStyle(inputStyle: StyleJson, clone: boolean =
}
}

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

return style;
}

0 comments on commit 5d2d9c6

Please sign in to comment.