Skip to content

Commit e874e2b

Browse files
refactor(landing): refine the labels param parsing logic
1 parent b279694 commit e874e2b

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,20 @@ describe('WindowUrl', () => {
209209
assert.equal(mc.labels, true);
210210

211211
// aerial layer, labels enabled & debug disabled
212-
mc.updateFromUrl('?labels=true');
213-
assert.equal(mc.layerId, 'aerial');
214-
assert.equal(mc.isDebug, false);
215-
assert.equal(mc.labels, true);
212+
for (const params of ['?labels', '?labels=true']) {
213+
mc.updateFromUrl(params);
214+
assert.equal(mc.layerId, 'aerial');
215+
assert.equal(mc.isDebug, false);
216+
assert.equal(mc.labels, true);
217+
}
218+
219+
// aerial layer, labels enabled & debug enabled
220+
for (const params of ['?labels&debug', '?labels=true&debug']) {
221+
mc.updateFromUrl(params);
222+
assert.equal(mc.layerId, 'aerial');
223+
assert.equal(mc.isDebug, true);
224+
assert.equal(mc.labels, true);
225+
}
216226
});
217227

218228
it('should not enable labels by default', () => {

packages/landing/src/config.map.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,14 @@ export class MapConfig extends Emitter<MapConfigEvents> {
145145
this.style = style ?? null;
146146
this.layerId = layerId.startsWith('im_') ? layerId.slice(3) : layerId;
147147
this.tileMatrix = tileMatrix;
148-
if (labels == null) {
149-
this.labels = layerId === 'aerial' && this.isDebug === false;
148+
this.labels = false;
149+
150+
if (typeof labels === 'string') {
151+
// enable labels for any string value other than "false"
152+
if (labels !== 'false') this.labels = true;
150153
} else {
151-
this.labels = labels !== 'false';
154+
// if not in debug mode, show labels for the aerial layer by default
155+
if (layerId === 'aerial' && !this.isDebug) this.labels = true;
152156
}
153157

154158
if (this.layerId === 'topographic' && this.style == null) this.style = 'topographic';

0 commit comments

Comments
 (0)