From 4c561d085e05bc7cb54c5199f9996c1eb9612825 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Tue, 9 Jul 2024 14:50:39 +1200 Subject: [PATCH 1/6] Support NZTM200quad terrain and add default LINZ-Terrain into debug --- packages/config/src/config/vector.style.ts | 10 ++++++ .../src/routes/tile.style.json.ts | 11 ++++--- packages/landing/src/components/debug.tsx | 13 +++++--- packages/landing/src/components/map.tsx | 32 +++++++++---------- packages/landing/src/config.debug.ts | 1 - 5 files changed, 40 insertions(+), 27 deletions(-) diff --git a/packages/config/src/config/vector.style.ts b/packages/config/src/config/vector.style.ts index d1fc92958..146925c10 100644 --- a/packages/config/src/config/vector.style.ts +++ b/packages/config/src/config/vector.style.ts @@ -1,5 +1,15 @@ +import { GoogleTms, Nztm2000QuadTms } from '@basemaps/geo'; + import { ConfigBase } from './base.js'; +/** + * Default Terrain exaggeration settings for different projection + */ +export const DefaultExaggeration = { + [Nztm2000QuadTms.identifier]: 4.4, + [GoogleTms.identifier]: 1.2, +}; + export interface SourceVector { type: 'vector'; url: string; diff --git a/packages/lambda-tiler/src/routes/tile.style.json.ts b/packages/lambda-tiler/src/routes/tile.style.json.ts index 6178e9e4b..5b1135f90 100644 --- a/packages/lambda-tiler/src/routes/tile.style.json.ts +++ b/packages/lambda-tiler/src/routes/tile.style.json.ts @@ -1,4 +1,5 @@ import { ConfigId, ConfigPrefix, ConfigTileSetRaster, Layer, Sources, StyleJson, TileSetType } from '@basemaps/config'; +import { DefaultExaggeration } from '@basemaps/config/build/config/vector.style.js'; import { GoogleTms, TileMatrixSet, TileMatrixSets } from '@basemaps/geo'; import { Env, toQueryString } from '@basemaps/shared'; import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda'; @@ -80,12 +81,12 @@ export interface StyleGet { }; } -function setStyleTerrain(style: StyleJson, terrain: string): void { +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} is not exists in the style source.`); style.terrain = { source, - exaggeration: 1.2, + exaggeration: DefaultExaggeration[tileMatrix.identifier] ?? DefaultExaggeration[GoogleTms.identifier], }; } @@ -142,7 +143,7 @@ export async function tileSetToStyle( await ensureTerrain(req, tileMatrix, apiKey, style); // Add terrain in style - if (terrain) setStyleTerrain(style, terrain); + if (terrain) setStyleTerrain(style, terrain, tileMatrix); const data = Buffer.from(JSON.stringify(style)); @@ -225,7 +226,7 @@ export async function tileSetOutputToStyle( await ensureTerrain(req, tileMatrix, apiKey, style); // Add terrain in style - if (terrain) setStyleTerrain(style, terrain); + if (terrain) setStyleTerrain(style, terrain, tileMatrix); const data = Buffer.from(JSON.stringify(style)); @@ -276,7 +277,7 @@ export async function styleJsonGet(req: LambdaHttpRequest): Promise { return; } - const target = getTerrainForSource(sourceId, Config.map.tileMatrix.projection); + const target = getTerrainForSource(sourceId, Config.map.tileMatrix); // no changes if (currentTerrain?.source === sourceId && currentTerrain?.exaggeration === target.exaggeration) return; @@ -423,7 +424,9 @@ export class Debug extends Component<{ map: maplibregl.Map }, DebugState> { getSourcesIds(type: string): string[] { const style = this.props.map.getStyle(); - return Object.keys(style.sources).filter((id) => id.startsWith('basemaps') && style.sources[id].type === type); + return Object.keys(style.sources).filter( + (id) => (id.startsWith('basemaps') || id.startsWith('LINZ')) && style.sources[id].type === type, + ); } renderRasterSourceDropdown(): ReactNode | null { @@ -602,9 +605,9 @@ export class Debug extends Component<{ map: maplibregl.Map }, DebugState> { * @param projection current projection * @returns */ -function getTerrainForSource(sourceId: string, projection: Epsg): { source: string; exaggeration: number } { +function getTerrainForSource(sourceId: string, tileMatrix: TileMatrixSet): { source: string; exaggeration: number } { return { source: sourceId, - exaggeration: projection.code === Epsg.Nztm2000.code ? 4.4 : 1.1, + exaggeration: DefaultExaggeration[tileMatrix.identifier] ?? DefaultExaggeration[GoogleTms.identifier], }; } diff --git a/packages/landing/src/components/map.tsx b/packages/landing/src/components/map.tsx index ef3cddf9c..c7b4e4b68 100644 --- a/packages/landing/src/components/map.tsx +++ b/packages/landing/src/components/map.tsx @@ -1,3 +1,4 @@ +import { DefaultExaggeration } from '@basemaps/config/build/config/vector.style.js'; import { GoogleTms, LocationUrl } from '@basemaps/geo'; import maplibre, { RasterLayerSpecification } from 'maplibre-gl'; import { Component, ReactNode } from 'react'; @@ -96,24 +97,23 @@ export class Basemaps extends Component Date: Tue, 9 Jul 2024 15:14:19 +1200 Subject: [PATCH 2/6] Add comments for NZTM exaggeration. --- packages/config/src/config/vector.style.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/config/src/config/vector.style.ts b/packages/config/src/config/vector.style.ts index 146925c10..33faa259e 100644 --- a/packages/config/src/config/vector.style.ts +++ b/packages/config/src/config/vector.style.ts @@ -4,6 +4,7 @@ import { ConfigBase } from './base.js'; /** * Default Terrain exaggeration settings for different projection + * NZTM terrain is too flat, it offsets the zoom level by 2 which means everything is approx 4x smaller than Google. */ export const DefaultExaggeration = { [Nztm2000QuadTms.identifier]: 4.4, From 6c69169bb0051fbb2b6317150ea3539162ec6522 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Thu, 11 Jul 2024 14:23:00 +1200 Subject: [PATCH 3/6] Exclude hillshade for get raster source --- packages/landing/src/components/debug.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/landing/src/components/debug.tsx b/packages/landing/src/components/debug.tsx index 3c12d2745..b4fed2dc8 100644 --- a/packages/landing/src/components/debug.tsx +++ b/packages/landing/src/components/debug.tsx @@ -456,9 +456,11 @@ export class Debug extends Component<{ map: maplibregl.Map }, DebugState> { getSourcesIds(type: string): string[] { const style = this.props.map.getStyle(); - return Object.keys(style.sources).filter( - (id) => (id.startsWith('basemaps') || id.startsWith('LINZ')) && style.sources[id].type === type, - ); + if (type === 'raster-dem') { + return Object.keys(style.sources).filter((id) => !id.startsWith(HillShadePrefix) && style.sources[id].type === type); + } else if (type === 'raster') { + return Object.keys(style.sources).filter((id) => id.startsWith('basemaps') && style.sources[id].type === type); + } else throw new Error('Only support to get raster or raster-dem sources for debug dropdown.'); } renderRasterSourceDropdown(): ReactNode | null { From f9f0f23463272b559d9e648ad9c328101f57b1a8 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Fri, 12 Jul 2024 07:31:37 +1200 Subject: [PATCH 4/6] Fix format --- packages/landing/src/components/debug.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/landing/src/components/debug.tsx b/packages/landing/src/components/debug.tsx index b4fed2dc8..9e7f418b7 100644 --- a/packages/landing/src/components/debug.tsx +++ b/packages/landing/src/components/debug.tsx @@ -457,7 +457,9 @@ export class Debug extends Component<{ map: maplibregl.Map }, DebugState> { getSourcesIds(type: string): string[] { const style = this.props.map.getStyle(); if (type === 'raster-dem') { - return Object.keys(style.sources).filter((id) => !id.startsWith(HillShadePrefix) && style.sources[id].type === type); + return Object.keys(style.sources).filter( + (id) => !id.startsWith(HillShadePrefix) && style.sources[id].type === type, + ); } else if (type === 'raster') { return Object.keys(style.sources).filter((id) => id.startsWith('basemaps') && style.sources[id].type === type); } else throw new Error('Only support to get raster or raster-dem sources for debug dropdown.'); From 8168a2d48b7e4e54ee2fe282fbc0e5e851a5d3f1 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Mon, 15 Jul 2024 14:18:01 +1200 Subject: [PATCH 5/6] Test 3d screenshots --- .github/workflows/screenshot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index 62becb63a..66ad85701 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -40,7 +40,7 @@ jobs: # Wait for the server to start timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:5000/v1/version)" != "200" ]]; do sleep 0.5; done' || false - docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1.5.0 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots + docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots - name: Save snapshots uses: getsentry/action-visual-snapshot@v2 From d69400bd44ecf3cf59a5af03c1fbb2d4215aaeee Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Tue, 16 Jul 2024 08:34:57 +1200 Subject: [PATCH 6/6] Update .github/workflows/screenshot.yml --- .github/workflows/screenshot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index 66ad85701..62becb63a 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -40,7 +40,7 @@ jobs: # Wait for the server to start timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:5000/v1/version)" != "200" ]]; do sleep 0.5; done' || false - docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots + docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1.5.0 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots - name: Save snapshots uses: getsentry/action-visual-snapshot@v2