style: format terrain traffic fire and bike-share modules

This commit is contained in:
Sameh Khamis committed 2026-09-11 21:57:51 -07:00
1 parent f4054469d5
commit a2d6461b52
13 files changed
+638 -213

No files matched your search

+14 -8
View File
@@ -29,7 +29,8 @@ const MERCATOR_LAT_LIMIT = 85.05112878;
* @returns {boolean} True when the coordinate is a fetchable tile.
*/
export function isValidTileCoord(z, x, y) {
if (!Number.isInteger(z) || !Number.isInteger(x) || !Number.isInteger(y)) return false;
if (!Number.isInteger(z) || !Number.isInteger(x) || !Number.isInteger(y))
return false;
if (z < MIN_TILE_ZOOM || z > MAX_TILE_ZOOM) return false;
const n = 2 ** z;
return x >= 0 && x < n && y >= 0 && y < n;
@@ -47,11 +48,14 @@ export function isValidTileCoord(z, x, y) {
*/
export function lonLatToTile(lon, lat, z) {
const n = 2 ** z;
const clampedLat = Math.max(-MERCATOR_LAT_LIMIT, Math.min(MERCATOR_LAT_LIMIT, lat));
const clampedLat = Math.max(
-MERCATOR_LAT_LIMIT,
Math.min(MERCATOR_LAT_LIMIT, lat),
);
const latRad = (clampedLat * Math.PI) / 180;
const x = Math.floor(((lon + 180) / 360) * n);
const y = Math.floor(
((1 - Math.log(Math.tan(latRad) + 1 / Math.cos(latRad)) / Math.PI) / 2) * n
((1 - Math.log(Math.tan(latRad) + 1 / Math.cos(latRad)) / Math.PI) / 2) * n,
);
return {
x: Math.max(0, Math.min(n - 1, x)),
@@ -70,7 +74,8 @@ export function lonLatToTile(lon, lat, z) {
export function tileToBBox(z, x, y) {
const n = 2 ** z;
const lonAt = (col) => (col / n) * 360 - 180;
const latAt = (row) => (Math.atan(Math.sinh(Math.PI * (1 - (2 * row) / n))) * 180) / Math.PI;
const latAt = (row) =>
(Math.atan(Math.sinh(Math.PI * (1 - (2 * row) / n))) * 180) / Math.PI;
return {
west: lonAt(x),
east: lonAt(x + 1),
@@ -132,10 +137,11 @@ export function utcDayKey(epochMs = Date.now()) {
* @returns {{date:string, count:number}} Valid state for `dayKey`.
*/
export function normalizeBudget(state, dayKey) {
const valid = Boolean(state)
&& state.date === dayKey
&& Number.isFinite(state.count)
&& state.count >= 0;
const valid =
Boolean(state) &&
state.date === dayKey &&
Number.isFinite(state.count) &&
state.count >= 0;
return valid ? state : { date: dayKey, count: 0 };
}