re-prettier pmtiles.ts; add prettier task

This commit is contained in:
Brandon Liu
2022-02-17 14:18:27 +08:00
parent c4560be9a2
commit 802b5e46fd
2 changed files with 364 additions and 379 deletions

View File

@@ -15,7 +15,8 @@
"build-tsc": "tsc --declaration --outdir dist", "build-tsc": "tsc --declaration --outdir dist",
"build": "npm run build-iife && npm run build-esm && npm run build-tsc", "build": "npm run build-iife && npm run build-esm && npm run build-tsc",
"test": "node -r esbuild-runner/register pmtiles.test.ts", "test": "node -r esbuild-runner/register pmtiles.test.ts",
"tsc": "tsc --noEmit --watch" "tsc": "tsc --noEmit --watch",
"prettier": "prettier --write pmtiles.ts"
}, },
"homepage": "https://github.com/protomaps/pmtiles", "homepage": "https://github.com/protomaps/pmtiles",
"author": "Brandon Liu", "author": "Brandon Liu",

View File

@@ -82,10 +82,7 @@ const queryView = (
} else if (cmp < 0) { } else if (cmp < 0) {
n = k - 1; n = k - 1;
} else { } else {
return [ return [getUint48(view, k * 17 + 7), view.getUint32(k * 17 + 13, true)];
getUint48(view, k * 17 + 7),
view.getUint32(k * 17 + 13, true),
];
} }
} }
return null; return null;
@@ -293,10 +290,7 @@ export class PMTiles {
let resp = await fetch(this.url, { let resp = await fetch(this.url, {
headers: { headers: {
Range: Range:
"bytes=" + "bytes=" + entry.offset + "-" + (entry.offset + entry.length - 1),
entry.offset +
"-" +
(entry.offset + entry.length - 1),
}, },
}); });
var buf = await resp.arrayBuffer(); var buf = await resp.arrayBuffer();
@@ -309,10 +303,7 @@ export class PMTiles {
return buf; return buf;
}; };
getLeafdir = async ( getLeafdir = async (version: number, entry: Entry): Promise<ArrayBuffer> => {
version: number,
entry: Entry
): Promise<ArrayBuffer> => {
let leaf = this.leaves.get(entry.offset); let leaf = this.leaves.get(entry.offset);
if (leaf) return await leaf.buffer; if (leaf) return await leaf.buffer;
@@ -350,10 +341,7 @@ export class PMTiles {
); );
if (leafdir_entry) { if (leafdir_entry) {
let leafdir = await this.getLeafdir( let leafdir = await this.getLeafdir(root.header.version, leafdir_entry);
root.header.version,
leafdir_entry
);
return queryTile(new DataView(leafdir), z, x, y); return queryTile(new DataView(leafdir), z, x, y);
} }
return null; return null;
@@ -441,11 +429,7 @@ export const addProtocol = (maplibregl: any) => {
instance.getZxy(+z, +x, +y).then((val) => { instance.getZxy(+z, +x, +y).then((val) => {
if (val) { if (val) {
let headers = { let headers = {
Range: Range: "bytes=" + val.offset + "-" + (val.offset + val.length - 1),
"bytes=" +
val.offset +
"-" +
(val.offset + val.length - 1),
}; };
const controller = new AbortController(); const controller = new AbortController();
const signal = controller.signal; const signal = controller.signal;