Skip to content

Commit

Permalink
feat(landing): enable labels upon first visit BM-1101 (#3364)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
tawera-manaena authored Nov 3, 2024
1 parent dcc8a9b commit af656bf
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
46 changes: 46 additions & 0 deletions packages/landing/src/__tests__/map.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
10 changes: 7 additions & 3 deletions packages/landing/src/config.map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class MapConfig extends Emitter<MapConfigEvents> {
}

get isDebug(): boolean {
return this.debug.debug;
return this.debug.debug === true;
}

/** Map location in WGS84 */
Expand Down Expand Up @@ -128,7 +128,7 @@ export class MapConfig extends Emitter<MapConfigEvents> {
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);
Expand All @@ -145,7 +145,11 @@ export class MapConfig extends Emitter<MapConfigEvents> {
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);
Expand Down

0 comments on commit af656bf

Please sign in to comment.