mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 02:41:09 +00:00
* add getTileJson method to PMTiles class [#239, #247] * update docs related to FetchSource and headers [#397]
36 lines
886 B
TypeScript
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: "" };
|
|
}; |