mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 19:01:08 +00:00
js: export more classes, root_entries list method
This commit is contained in:
17
js/index.ts
17
js/index.ts
@@ -225,7 +225,7 @@ export interface Source {
|
|||||||
getKey: () => string;
|
getKey: () => string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class FileSource implements Source {
|
export class FileSource implements Source {
|
||||||
file: File;
|
file: File;
|
||||||
|
|
||||||
constructor(file: File) {
|
constructor(file: File) {
|
||||||
@@ -243,7 +243,7 @@ class FileSource implements Source {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FetchSource implements Source {
|
export class FetchSource implements Source {
|
||||||
url: string;
|
url: string;
|
||||||
|
|
||||||
constructor(url: string) {
|
constructor(url: string) {
|
||||||
@@ -279,7 +279,7 @@ interface CacheEntry {
|
|||||||
buffer: Promise<DataView>;
|
buffer: Promise<DataView>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LRUCacheSource implements Source {
|
export class LRUCacheSource implements Source {
|
||||||
entries: Map<number, CacheEntry>;
|
entries: Map<number, CacheEntry>;
|
||||||
maxEntries: number;
|
maxEntries: number;
|
||||||
source: Source;
|
source: Source;
|
||||||
@@ -327,7 +327,7 @@ class LRUCacheSource implements Source {
|
|||||||
export class PMTiles {
|
export class PMTiles {
|
||||||
source: Source;
|
source: Source;
|
||||||
|
|
||||||
constructor(source: any, maxLeaves = 64) {
|
constructor(source: string | Source, maxLeaves = 64) {
|
||||||
if (typeof source === "string") {
|
if (typeof source === "string") {
|
||||||
this.source = new LRUCacheSource(new FetchSource(source), maxLeaves);
|
this.source = new LRUCacheSource(new FetchSource(source), maxLeaves);
|
||||||
} else {
|
} else {
|
||||||
@@ -356,6 +356,15 @@ export class PMTiles {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async root_entries(): Promise<Entry[]> {
|
||||||
|
const root = await this.fetchRoot();
|
||||||
|
let entries = [];
|
||||||
|
for (var i = 0; i < root.header.root_entries; i++) {
|
||||||
|
entries.push(parseEntry(root.dir,i));
|
||||||
|
}
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
async metadata(): Promise<any> {
|
async metadata(): Promise<any> {
|
||||||
const root = await this.fetchRoot();
|
const root = await this.fetchRoot();
|
||||||
const dec = new TextDecoder("utf-8");
|
const dec = new TextDecoder("utf-8");
|
||||||
|
|||||||
Reference in New Issue
Block a user