Skip to content

refactor(landing): refine the labels param parsing logic #3413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/landing/src/__tests__/map.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,20 @@ describe('WindowUrl', () => {
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);
for (const params of ['?labels', '?labels=true']) {
mc.updateFromUrl(params);
assert.equal(mc.layerId, 'aerial');
assert.equal(mc.isDebug, false);
assert.equal(mc.labels, true);
}

// aerial layer, labels enabled & debug enabled
for (const params of ['?labels&debug', '?labels=true&debug']) {
mc.updateFromUrl(params);
assert.equal(mc.layerId, 'aerial');
assert.equal(mc.isDebug, true);
assert.equal(mc.labels, true);
}
});

it('should not enable labels by default', () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/landing/src/config.map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ export class MapConfig extends Emitter<MapConfigEvents> {
this.style = style ?? null;
this.layerId = layerId.startsWith('im_') ? layerId.slice(3) : layerId;
this.tileMatrix = tileMatrix;
if (labels == null) {
this.labels = layerId === 'aerial' && this.isDebug === false;
this.labels = false;

if (typeof labels === 'string') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the typing for .get is URLSearchParam.get(name: string): string | null; so it can only ever be a string or null,

so labels == null is clearer to me over typeof

For example:

new URLSearchParameters('x=1').get('x') // '1'

// enable labels for any string value other than "false"
if (labels !== 'false') this.labels = true;
} else {
this.labels = labels !== 'false';
// if not in debug mode, show labels for the aerial layer by default
if (layerId === 'aerial' && !this.isDebug) this.labels = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally try and avoid !foo as that triggers type cohersion causing you to think of all the horrible values that javascript would consider to be truthy.

We generally try to be as explicit as possible, so this.isDebug === false would be my preference

}

if (this.layerId === 'topographic' && this.style == null) this.style = 'topographic';
Expand Down
Loading