From f0a480757417a1130c1fac272de96d44e4c0479e Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Thu, 29 Aug 2024 18:02:30 -0700 Subject: [PATCH] quadkey bug fix --- package.json | 2 +- packages/sdk-utils/packages/quadkey/src/Quadkey.ts | 3 +++ .../packages/quadkey/src/spec/Quadkey.spec.ts | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c694c8c11c..610dfc7ae7 100644 --- a/package.json +++ b/package.json @@ -125,4 +125,4 @@ "access": "public" }, "resolutions_comment": "We set the above resolutions to make sure we pull in the latest versions of these packages even if some sub packages request earlier versions" -} +} \ No newline at end of file diff --git a/packages/sdk-utils/packages/quadkey/src/Quadkey.ts b/packages/sdk-utils/packages/quadkey/src/Quadkey.ts index 6933c572a8..f7e7ee9495 100644 --- a/packages/sdk-utils/packages/quadkey/src/Quadkey.ts +++ b/packages/sdk-utils/packages/quadkey/src/Quadkey.ts @@ -55,6 +55,9 @@ export class Quadkey { } get base4Hash() { + if (this.id === 0n && this.zoom === 0) { + return '' + } return this.id.toString(4).padStart(this.zoom, '0') } diff --git a/packages/sdk-utils/packages/quadkey/src/spec/Quadkey.spec.ts b/packages/sdk-utils/packages/quadkey/src/spec/Quadkey.spec.ts index 04516ff492..49b91cd2ca 100644 --- a/packages/sdk-utils/packages/quadkey/src/spec/Quadkey.spec.ts +++ b/packages/sdk-utils/packages/quadkey/src/spec/Quadkey.spec.ts @@ -10,4 +10,16 @@ describe('Quadkey', () => { expect(center?.lat).toBe(48.378_236) expect(center?.lng).toBe(-146.25) }) + test('Zero Children', () => { + const qk = Quadkey.Zero + expect(qk.base16String).toBe('00000000000000000000000000000000000000000000000000000000000000') + expect(qk.zoom).toBe(0) + expect(qk.base4Hash).toBe('') + const children = qk?.children + expect(children?.length).toBe(4) + expect(children?.[0].base4Hash).toBe('0') + expect(children?.[1].base4Hash).toBe('1') + expect(children?.[2].base4Hash).toBe('2') + expect(children?.[3].base4Hash).toBe('3') + }) })