mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 02:10:18 +01:00
20 lines
577 B
JavaScript
20 lines
577 B
JavaScript
export class TileNumber {
|
|
constructor(x, y) {
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
equals(other) {
|
|
return this.x === other.x && this.y === other.y;
|
|
}
|
|
}
|
|
|
|
export function latLngToTileNumber(latLng, tileSize) {
|
|
const numTilesX = 2 ** tileSize;
|
|
const numTilesY = 2 ** tileSize;
|
|
const lngDegrees = latLng.lng;
|
|
const latRadians = latLng.lat * (Math.PI / 180);
|
|
return new L.Point(
|
|
numTilesX * ((lngDegrees + 180) / 360),
|
|
numTilesY * (1 - Math.log(Math.tan(latRadians) + 1 / Math.cos(latRadians)) / Math.PI) / 2
|
|
);
|
|
} |