Skip to content

Commit

Permalink
quadkey bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Aug 30, 2024
1 parent e69e220 commit f0a4807
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 3 additions & 0 deletions packages/sdk-utils/packages/quadkey/src/Quadkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

Expand Down
12 changes: 12 additions & 0 deletions packages/sdk-utils/packages/quadkey/src/spec/Quadkey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit f0a4807

Please sign in to comment.