Skip to content

Commit b279694

Browse files
fix(landing): update the set of labels disabled layers BM-1230 (#3412)
### Motivation We have now published the Shortbread vector map stylesheets into Basemaps. However, attempting to view any of them, with the labels enabled, results in a `400 Bad Request` response. #### Example Attempting to view the `topographic-v2` layer results in a blank map as fetching the style fails: | https://basemaps.linz.govt.nz/?style=topographic-v2&i=topographic&labels=true | | - | | ![][img_before] | The blank map is caused by the stylesheet request preserving the `labels` parameter instead of trimming it off: ``` https://basemaps.linz.govt.nz/v1/styles/topographic-v2.json?api={api_key}&labels=true ``` The request then returns the following `400` status response: ``` {"id":"01JQ30CEPF9CDXBFMN9229S0WV","status":400,"message":"Cannot merge styles with duplicate layerIds: Parcels-Ln","correlationId":"01JQ30CEPG8AKWBZK5VXHH2TZ3"} ``` ### Modifications - Updated the set of layers for which to disable labels. - Added tests to verify that the landing package trims off the `labels` param for such layers. ### Verification I have verified locally that the Shortbread vector map layers show on the map regardless of whether the `labels` parameter is present in the URL, similar to the `topographic` layer. #### Example Viewing the `topographic-v2` layer (locally) now shows the map as expected: | http://localhost:5000/?style=topographic-v2&i=topographic&labels=true | | - | | ![][img_after] | The stylesheet request now trims off the `labels` parameter instead of preserving it: ``` https://basemaps.linz.govt.nz/v1/styles/topographic-v2.json?api={api_key} ``` The request now returns the following `200` status response (snippet): ``` { "id": "st_topographic-v2", "version": 8, ... } ``` <!-- TODO: Say how you tested your changes. --> [img_before]: https://github.com/user-attachments/assets/9d75c80a-c8c2-4c27-ab51-b4bf09a6cc5d [img_after]: https://github.com/user-attachments/assets/10fb7211-3b3c-4ee8-870d-d9084e2b4ff7
1 parent 3c687ac commit b279694

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/landing/src/__tests__/map.config.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, it } from 'node:test';
33

44
import { GoogleTms, Nztm2000QuadTms, Nztm2000Tms } from '@basemaps/geo';
55

6+
import { LabelsDisabledLayers } from '../components/map.label.js';
67
import { Config } from '../config.js';
78
import { MapConfig } from '../config.map.js';
89
import { MapOptionType, WindowUrl } from '../url.js';
@@ -175,6 +176,31 @@ describe('WindowUrl', () => {
175176
assert.equal(mc.layerId, '01EDA2YFXH2JN264VG1HKBT625');
176177
});
177178

179+
it('should preserve the labels param', () => {
180+
const url = WindowUrl.toTileUrl({
181+
urlType: MapOptionType.Style,
182+
tileMatrix: GoogleTms,
183+
layerId: 'aerial',
184+
style: 'aerial',
185+
labels: true,
186+
});
187+
assert.equal(url.includes('labels=true'), true);
188+
});
189+
190+
it('should discard the labels param', () => {
191+
for (const style of LabelsDisabledLayers.values()) {
192+
const url = WindowUrl.toTileUrl({
193+
urlType: MapOptionType.Style,
194+
tileMatrix: GoogleTms,
195+
layerId: 'topographic',
196+
style,
197+
labels: true,
198+
});
199+
200+
assert.equal(url.includes('labels=true'), false);
201+
}
202+
});
203+
178204
it('should enable labels by default', () => {
179205
// aerial layer & debug disabled
180206
mc.updateFromUrl('');

packages/landing/src/components/map.label.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import { IControl } from 'maplibre-gl';
22

33
import { Config, GaEvent, gaEvent } from '../config.js';
44

5-
export const LabelsDisabledLayers = new Set(['topographic', 'topolite', 'topo-raster']);
5+
export const LabelsDisabledLayers = new Set([
6+
'labels',
7+
'labels-v2',
8+
'topographic',
9+
'topographic-v2',
10+
'topolite',
11+
'topolite-v2',
12+
'topo-raster',
13+
]);
614

715
export class MapLabelControl implements IControl {
816
map?: maplibregl.Map;

0 commit comments

Comments
 (0)