Files
PMTiles/serverless/shared/index.ts
Brandon Liu 6f5479439b add getTileJson method to PMTiles class [#239, #247] (#453)
* add getTileJson method to PMTiles class [#239, #247]
* update docs related to FetchSource and headers [#397]
2024-09-18 15:57:14 +08:00

36 lines
886 B
TypeScript

export const pmtiles_path = (name: string, setting?: string): string => {
if (setting) {
return setting.replaceAll("{name}", name);
}
return name + ".pmtiles";
};
const TILE =
/^\/(?<NAME>[0-9a-zA-Z\/!\-_\.\*\'\(\)]+)\/(?<Z>\d+)\/(?<X>\d+)\/(?<Y>\d+).(?<EXT>[a-z]+)$/;
const TILESET = /^\/(?<NAME>[0-9a-zA-Z\/!\-_\.\*\'\(\)]+).json$/;
export const tile_path = (
path: string
): {
ok: boolean;
name: string;
tile?: [number, number, number];
ext: string;
} => {
const tile_match = path.match(TILE);
if (tile_match) {
const g = tile_match.groups!;
return { ok: true, name: g.NAME, tile: [+g.Z, +g.X, +g.Y], ext: g.EXT };
}
const tileset_match = path.match(TILESET);
if (tileset_match) {
const g = tileset_match.groups!;
return { ok: true, name: g.NAME, ext: "json" };
}
return { ok: false, name: "", tile: [0, 0, 0], ext: "" };
};