js decoder 1.1.0

adds fflate dependency; maplibre decoder can read gzipped tiles [#41]
This commit is contained in:
Brandon Liu
2022-07-07 12:36:16 +08:00
parent abf1dd9372
commit 3811ff9b1b
5 changed files with 31 additions and 9 deletions

View File

@@ -1,5 +1,7 @@
declare const L: any;
import { decompressSync } from "fflate";
export const shift = (n: number, shift: number) => {
return n * Math.pow(2, shift);
};
@@ -536,7 +538,11 @@ export class ProtocolCache {
instance!.source
.getBytes(val.offset, val.length)
.then((arr) => {
callback(null, new Uint8Array(arr.buffer), null, null);
let data = new Uint8Array(arr.buffer);
if (data[0] == 0x1f && data[1] == 0x8b) {
data = decompressSync(data);
}
callback(null, data, null, null);
})
.catch((e) => {
callback(new Error("Canceled"), null, null, null);