Chore: improve types, add checks

This commit is contained in:
Pieter Vander Vennet 2025-04-03 02:12:59 +02:00
parent 6e4879fb0d
commit 4b3e1fad4f
3 changed files with 17 additions and 10 deletions

View file

@ -86,7 +86,7 @@ export class Tiles {
static asGeojson(zIndex: number, x?: number, y?: number): Feature<Polygon> {
let z = zIndex
if (x === undefined) {
;[z, x, y] = Tiles.tile_from_index(zIndex)
[z, x, y] = Tiles.tile_from_index(zIndex)
}
const bounds = Tiles.tile_bounds_lon_lat(z, x, y)
return new BBox(bounds).asGeoJson()
@ -154,17 +154,17 @@ export class Tiles {
return (180 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)))
}
private static lon2tile(lon, zoom) {
private static lon2tile(lon: number, zoom: number): number {
return Math.floor(((lon + 180) / 360) * Math.pow(2, zoom))
}
private static lat2tile(lat, zoom) {
private static lat2tile(lat: number, zoom: number): number {
return Math.floor(
((1 -
Math.log(Math.tan((lat * Math.PI) / 180) + 1 / Math.cos((lat * Math.PI) / 180)) /
Math.log(Math.tan((lat * Math.PI) / 180) + 1 / Math.cos((lat * Math.PI) / 180)) /
Math.PI) /
2) *
Math.pow(2, zoom)
Math.pow(2, zoom)
)
}
}