refactor: expose portable source record protocols

This commit is contained in:
Sameh Khamis committed 2026-09-14 19:36:32 -07:00
1 parent 6fa25c349a
commit ea6c8653b3
12 files changed
+370 -192

No files matched your search

+16 -2
View File
@@ -26,12 +26,26 @@ const MERCATOR_LAT_LIMIT = 85.05112878;
* @param {number} z - Zoom level; integer within [MIN_TILE_ZOOM, MAX_TILE_ZOOM].
* @param {number} x - Tile column; integer within [0, 2^z - 1].
* @param {number} y - Tile row; integer within [0, 2^z - 1].
* @param {{minZoom?: number, maxZoom?: number}} [bounds] Supported source zooms.
* @returns {boolean} True when the coordinate is a fetchable tile.
*/
export function isValidTileCoord(z, x, y) {
export function isValidTileCoord(
z,
x,
y,
{ minZoom = MIN_TILE_ZOOM, maxZoom = MAX_TILE_ZOOM } = {},
) {
if (!Number.isInteger(z) || !Number.isInteger(x) || !Number.isInteger(y))
return false;
if (z < MIN_TILE_ZOOM || z > MAX_TILE_ZOOM) return false;
if (
!Number.isInteger(minZoom) ||
!Number.isInteger(maxZoom) ||
minZoom < 0 ||
maxZoom > 30 ||
minZoom > maxZoom
)
return false;
if (z < minZoom || z > maxZoom) return false;
const n = 2 ** z;
return x >= 0 && x < n && y >= 0 && y < n;
}