From 88dfa6a264a8da65bb38b86dd49a93c33013844b Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Thu, 14 Nov 2024 14:55:25 +1300 Subject: [PATCH 1/2] Fix NZTM terrain exaggeration been multiplyed twice/ --- packages/lambda-tiler/src/util/nztm.style.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/lambda-tiler/src/util/nztm.style.ts b/packages/lambda-tiler/src/util/nztm.style.ts index d297617f1..b3ca78cff 100644 --- a/packages/lambda-tiler/src/util/nztm.style.ts +++ b/packages/lambda-tiler/src/util/nztm.style.ts @@ -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; } From c19dd8bf09fa4a115ece29d8dca6a4e295c00fdf Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Thu, 14 Nov 2024 15:40:49 +1300 Subject: [PATCH 2/2] Fix the broken tests --- .../routes/__tests__/tile.style.json.test.ts | 5 ++-- .../src/routes/tile.style.json.ts | 2 +- .../src/util/__test__/nztm.style.test.ts | 26 +++++++++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) 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 d15ec5f91..edec5c4fa 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 @@ -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'; @@ -441,7 +442,7 @@ describe('/v1/styles', () => { }, ], terrain: { - exaggeration: 1.1, + exaggeration: DefaultExaggeration[Nztm2000QuadTms.identifier], }, }, }; diff --git a/packages/lambda-tiler/src/routes/tile.style.json.ts b/packages/lambda-tiler/src/routes/tile.style.json.ts index efa7c7044..327a8ef3e 100644 --- a/packages/lambda-tiler/src/routes/tile.style.json.ts +++ b/packages/lambda-tiler/src/routes/tile.style.json.ts @@ -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 = { diff --git a/packages/lambda-tiler/src/util/__test__/nztm.style.test.ts b/packages/lambda-tiler/src/util/__test__/nztm.style.test.ts index ba907ee14..622d42bc7 100644 --- a/packages/lambda-tiler/src/util/__test__/nztm.style.test.ts +++ b/packages/lambda-tiler/src/util/__test__/nztm.style.test.ts @@ -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', () => { @@ -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', () => { @@ -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', () => {