From af656bfe72e8afb3b072cf18d2dbbb538709127c Mon Sep 17 00:00:00 2001 From: Tawera Manaena Date: Mon, 4 Nov 2024 09:43:27 +1300 Subject: [PATCH] feat(landing): enable labels upon first visit BM-1101 (#3364) ### Motivation As a Basemaps user, I would like to see labels when I arrive at the site so I can see the context of the imagery displayed to me. ### Modifications - Updated the **landing** package so that labels are enabled upon first visit to the site via the default Basemaps URL (https://basemaps.linz.govt.nz). Situations where labels are **not enabled** upon first visit: - The `labels` URL query string is `false`, e.g. https://basemaps.linz.govt.nz/?labels=false - The `debug` URL query string is present, e.g. https://basemaps.linz.govt.nz/?debug ### Verification - Added additional tests to the **landing** package's `map.config.test` test suite. #### Labels should be enabled | https://basemaps.linz.govt.nz | | - | | ![][default] | | Viewing the **aerial** layer and not in debug mode. Enable labels upon first visit. | #### Labels should be disabled | https://basemaps.linz.govt.nz/?labels=false | | - | | ![][labels=false] | | The `labels` query string is present and equals `false`. Don't enable labels upon first visit. | | https://basemaps.linz.govt.nz/?debug | | - | | ![][debug] | | In debug mode. Don't enable labels upon first visit. | | https://basemaps.linz.govt.nz/?i=ashburton-2023-0.1m | | - | | ![][individual_layer] | | _Adjusted viewport to show imagery_ | | Not viewing the `aerial` layer. Don't enable labels upon first visit. | --- Resolves bug: [BM-1114](https://toitutewhenua.atlassian.net/browse/BM-1114) [default]: https://github.com/user-attachments/assets/1b450c01-3409-400e-b794-6eccc6582021 [labels=false]: https://github.com/user-attachments/assets/2ca74653-d868-4420-8fd4-4e22273efa7d [debug]: https://github.com/user-attachments/assets/462ac80d-a603-47a7-9b9b-683b59988521 [individual_layer]: https://github.com/user-attachments/assets/bac0f8a7-9a67-4683-880b-5a5fe484ae8b [BM-1114]: https://toitutewhenua.atlassian.net/browse/BM-1114?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --- .../landing/src/__tests__/map.config.test.ts | 46 +++++++++++++++++++ packages/landing/src/config.map.ts | 10 ++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/packages/landing/src/__tests__/map.config.test.ts b/packages/landing/src/__tests__/map.config.test.ts index a4de5f406..cf91ec0d7 100644 --- a/packages/landing/src/__tests__/map.config.test.ts +++ b/packages/landing/src/__tests__/map.config.test.ts @@ -174,4 +174,50 @@ describe('WindowUrl', () => { mc.updateFromUrl('i=01EDA2YFXH2JN264VG1HKBT625'); assert.equal(mc.layerId, '01EDA2YFXH2JN264VG1HKBT625'); }); + + it('should enable labels by default', () => { + // aerial layer & debug disabled + mc.updateFromUrl(''); + assert.equal(mc.layerId, 'aerial'); + assert.equal(mc.isDebug, false); + assert.equal(mc.labels, true); + + // aerial layer, labels enabled & debug disabled + mc.updateFromUrl('?labels=true'); + assert.equal(mc.layerId, 'aerial'); + assert.equal(mc.isDebug, false); + assert.equal(mc.labels, true); + }); + + it('should not enable labels by default', () => { + // aerial layer, but labels disabled + mc.updateFromUrl('?labels=false'); + assert.equal(mc.layerId, 'aerial'); + assert.equal(mc.isDebug, false); + assert.equal(mc.labels, false); + + // aerial layer, but debug enabled + mc.updateFromUrl('?debug'); + assert.equal(mc.layerId, 'aerial'); + assert.equal(mc.isDebug, true); + assert.equal(mc.labels, false); + + // aerial layer, labels disabled & debug enabled + mc.updateFromUrl('?labels=false&debug'); + assert.equal(mc.layerId, 'aerial'); + assert.equal(mc.isDebug, true); + assert.equal(mc.labels, false); + + // debug disabled, but individual layer + mc.updateFromUrl('i=abc123'); + assert.equal(mc.layerId, 'abc123'); + assert.equal(mc.isDebug, false); + assert.equal(mc.labels, false); + + // individual layer & debug enabled + mc.updateFromUrl('i=abc123&debug'); + assert.equal(mc.layerId, 'abc123'); + assert.equal(mc.isDebug, true); + assert.equal(mc.labels, false); + }); }); diff --git a/packages/landing/src/config.map.ts b/packages/landing/src/config.map.ts index 09c528a85..2d0a899fe 100644 --- a/packages/landing/src/config.map.ts +++ b/packages/landing/src/config.map.ts @@ -69,7 +69,7 @@ export class MapConfig extends Emitter { } get isDebug(): boolean { - return this.debug.debug; + return this.debug.debug === true; } /** Map location in WGS84 */ @@ -128,7 +128,7 @@ export class MapConfig extends Emitter { const config = urlParams.get('c') ?? urlParams.get('config'); const layerId = urlParams.get('i') ?? style ?? 'aerial'; const terrain = urlParams.get('t') ?? urlParams.get('terrain'); - const labels = Boolean(urlParams.get('labels')); + const labels = urlParams.get('labels'); const projectionParam = (urlParams.get('p') ?? urlParams.get('tileMatrix') ?? GoogleTms.identifier).toLowerCase(); let tileMatrix = TileMatrixSets.All.find((f) => f.identifier.toLowerCase() === projectionParam); @@ -145,7 +145,11 @@ export class MapConfig extends Emitter { this.style = style ?? null; this.layerId = layerId.startsWith('im_') ? layerId.slice(3) : layerId; this.tileMatrix = tileMatrix; - this.labels = labels; + if (labels == null) { + this.labels = layerId === 'aerial' && this.isDebug === false; + } else { + this.labels = labels !== 'false'; + } if (this.layerId === 'topographic' && this.style == null) this.style = 'topographic'; this.emit('tileMatrix', this.tileMatrix);