maplibre-tilepackage-protocol 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/bundle.js +39 -10
- package/dist/bundle.js.map +1 -1
- package/dist/index.esm.js +39 -10
- package/dist/index.esm.js.map +1 -1
- package/eslint.config.mjs +28 -0
- package/package.json +2 -2
- package/src/default-decompress.js +11 -4
- package/src/index.js +17 -4
- package/src/source.js +11 -2
package/README.md
CHANGED
|
@@ -132,7 +132,10 @@ Flat and indexed VTPK archives are supported. Indexed packages rely on the overz
|
|
|
132
132
|
## Sample Data
|
|
133
133
|
|
|
134
134
|
Austria indexed VTPK sample:
|
|
135
|
-
https://
|
|
135
|
+
https://cdn.basemap.at/offline/bmapv_vtpk_3857.vtpk
|
|
136
|
+
|
|
137
|
+
There is also a small example file in the example folder, and there is an online version of the example available here:
|
|
138
|
+
https://spatialillusions.com/maplibre-tilepackage-protocol/
|
|
136
139
|
|
|
137
140
|
## Acknowledgement
|
|
138
141
|
|
package/dist/bundle.js
CHANGED
|
@@ -1390,9 +1390,18 @@ var TilePackageProtocol = (function (exports) {
|
|
|
1390
1390
|
this.url = url;
|
|
1391
1391
|
this.customHeaders = customHeaders;
|
|
1392
1392
|
this.mustReload = false;
|
|
1393
|
+
// Safe global detection for legacy environments without globalThis
|
|
1394
|
+
const g =
|
|
1395
|
+
typeof globalThis !== "undefined"
|
|
1396
|
+
? globalThis
|
|
1397
|
+
: typeof window !== "undefined"
|
|
1398
|
+
? window
|
|
1399
|
+
: typeof self !== "undefined"
|
|
1400
|
+
? self
|
|
1401
|
+
: {};
|
|
1393
1402
|
let userAgent = "";
|
|
1394
|
-
if (
|
|
1395
|
-
userAgent =
|
|
1403
|
+
if (g && typeof g.navigator !== "undefined") {
|
|
1404
|
+
userAgent = g.navigator.userAgent || "";
|
|
1396
1405
|
}
|
|
1397
1406
|
const isWindows = userAgent.indexOf("Windows") > -1;
|
|
1398
1407
|
const isChromiumBased = /Chrome|Chromium|Edg|OPR|Brave/.test(userAgent);
|
|
@@ -4776,16 +4785,23 @@ var TilePackageProtocol = (function (exports) {
|
|
|
4776
4785
|
return buf;
|
|
4777
4786
|
}
|
|
4778
4787
|
if (compression === "gzip") {
|
|
4779
|
-
|
|
4788
|
+
// Safe global detection for DecompressionStream feature test
|
|
4789
|
+
const g =
|
|
4790
|
+
typeof globalThis !== "undefined"
|
|
4791
|
+
? globalThis
|
|
4792
|
+
: typeof window !== "undefined"
|
|
4793
|
+
? window
|
|
4794
|
+
: typeof self !== "undefined"
|
|
4795
|
+
? self
|
|
4796
|
+
: {};
|
|
4797
|
+
if (typeof g.DecompressionStream === "undefined") {
|
|
4780
4798
|
return decompressSync(new Uint8Array(buf));
|
|
4781
4799
|
}
|
|
4782
4800
|
const stream = new Response(buf).body;
|
|
4783
4801
|
if (!stream) {
|
|
4784
4802
|
throw new Error("Failed to read response stream");
|
|
4785
4803
|
}
|
|
4786
|
-
const result = stream.pipeThrough(
|
|
4787
|
-
new globalThis.DecompressionStream("gzip"),
|
|
4788
|
-
);
|
|
4804
|
+
const result = stream.pipeThrough(new g.DecompressionStream("gzip"));
|
|
4789
4805
|
return new Response(result).arrayBuffer();
|
|
4790
4806
|
}
|
|
4791
4807
|
throw new Error("Compression method not supported");
|
|
@@ -5306,13 +5322,23 @@ var TilePackageProtocol = (function (exports) {
|
|
|
5306
5322
|
}
|
|
5307
5323
|
}
|
|
5308
5324
|
|
|
5325
|
+
/**
|
|
5326
|
+
* Escape literal newlines in JSON text.
|
|
5327
|
+
* Replaces actual newline characters with the JSON escape sequence.
|
|
5328
|
+
*/
|
|
5329
|
+
function escapeJsonNewlines(text) {
|
|
5330
|
+
// Replace literal newlines with JSON escape sequences
|
|
5331
|
+
// This handles \r\n, \n, and \r
|
|
5332
|
+
return text.replace(/\r\n/g, "\\n").replace(/[\r\n]/g, "\\n");
|
|
5333
|
+
}
|
|
5334
|
+
|
|
5309
5335
|
function calculateFilename(z, x, y, header) {
|
|
5310
5336
|
const zoom = z.toString().padStart(2, "0");
|
|
5311
5337
|
const baseRow = Math.floor(y / 128) * 128;
|
|
5312
5338
|
const baseCol = Math.floor(x / 128) * 128;
|
|
5313
5339
|
const rowHex = baseRow.toString(16).padStart(4, "0");
|
|
5314
5340
|
const colHex = baseCol.toString(16).padStart(4, "0");
|
|
5315
|
-
|
|
5341
|
+
const basePath = header.type === "tpkx" ? "tile" : "p12/tile";
|
|
5316
5342
|
return `${basePath}/L${zoom}/R${rowHex}C${colHex}.bundle`;
|
|
5317
5343
|
}
|
|
5318
5344
|
|
|
@@ -5472,13 +5498,16 @@ var TilePackageProtocol = (function (exports) {
|
|
|
5472
5498
|
let metadata = {};
|
|
5473
5499
|
if (header.packageType === "vtpk") {
|
|
5474
5500
|
const resp = await this.source.getBytes(
|
|
5475
|
-
header.
|
|
5476
|
-
header.
|
|
5501
|
+
header.metadataOffset,
|
|
5502
|
+
header.metadataLength,
|
|
5477
5503
|
undefined,
|
|
5478
5504
|
header.etag,
|
|
5479
5505
|
);
|
|
5480
5506
|
const decoder = new TextDecoder("utf-8");
|
|
5481
|
-
|
|
5507
|
+
const jsonText = decoder.decode(resp.data);
|
|
5508
|
+
console.log("test", jsonText);
|
|
5509
|
+
console.log("escaped text", escapeJsonNewlines(jsonText));
|
|
5510
|
+
metadata = JSON.parse(escapeJsonNewlines(jsonText));
|
|
5482
5511
|
}
|
|
5483
5512
|
metadata.name = header.name;
|
|
5484
5513
|
return metadata;
|