Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lambda-tiler): NZTM terrain been multiplied twice. BM-1122 #3373

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading