@loaders.gl/pmtiles 4.0.0-beta.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/LICENSE +41 -0
- package/README.md +7 -0
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/dist.min.js +4436 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +13 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/parse-pmtiles.js +126 -0
- package/dist/es5/lib/parse-pmtiles.js.map +1 -0
- package/dist/es5/lib/sources.js +2 -0
- package/dist/es5/lib/sources.js.map +1 -0
- package/dist/es5/pmtiles-source.js +289 -0
- package/dist/es5/pmtiles-source.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/parse-pmtiles.js +69 -0
- package/dist/esm/lib/parse-pmtiles.js.map +1 -0
- package/dist/esm/lib/sources.js +2 -0
- package/dist/esm/lib/sources.js.map +1 -0
- package/dist/esm/pmtiles-source.js +106 -0
- package/dist/esm/pmtiles-source.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/parse-pmtiles.d.ts +42 -0
- package/dist/lib/parse-pmtiles.d.ts.map +1 -0
- package/dist/lib/sources.d.ts +1 -0
- package/dist/lib/sources.d.ts.map +1 -0
- package/dist/pmtiles-source.d.ts +52 -0
- package/dist/pmtiles-source.d.ts.map +1 -0
- package/package.json +42 -0
- package/src/bundle.ts +4 -0
- package/src/index.ts +5 -0
- package/src/lib/parse-pmtiles.ts +147 -0
- package/src/lib/sources.ts +150 -0
- package/src/pmtiles-source.ts +155 -0
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,4436 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
12
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
13
|
+
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
|
+
};
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
__markAsModule(target);
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, module, desc) => {
|
|
21
|
+
if (module && typeof module === "object" || typeof module === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(module))
|
|
23
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
24
|
+
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
};
|
|
28
|
+
var __toModule = (module) => {
|
|
29
|
+
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// ../loader-utils/src/lib/env-utils/assert.ts
|
|
33
|
+
function assert(condition, message) {
|
|
34
|
+
if (!condition) {
|
|
35
|
+
throw new Error(message || "loader assertion failed.");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var init_assert = __esm({
|
|
39
|
+
"../loader-utils/src/lib/env-utils/assert.ts"() {
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// ../loader-utils/src/lib/env-utils/globals.ts
|
|
44
|
+
var globals, self_, window_, global_, document_, isBrowser, matches, nodeVersion;
|
|
45
|
+
var init_globals = __esm({
|
|
46
|
+
"../loader-utils/src/lib/env-utils/globals.ts"() {
|
|
47
|
+
globals = {
|
|
48
|
+
self: typeof self !== "undefined" && self,
|
|
49
|
+
window: typeof window !== "undefined" && window,
|
|
50
|
+
global: typeof global !== "undefined" && global,
|
|
51
|
+
document: typeof document !== "undefined" && document
|
|
52
|
+
};
|
|
53
|
+
self_ = globals.self || globals.window || globals.global || {};
|
|
54
|
+
window_ = globals.window || globals.self || globals.global || {};
|
|
55
|
+
global_ = globals.global || globals.self || globals.window || {};
|
|
56
|
+
document_ = globals.document || {};
|
|
57
|
+
isBrowser = Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser);
|
|
58
|
+
matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
59
|
+
nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
64
|
+
var init_typeof = __esm({
|
|
65
|
+
"../../node_modules/@babel/runtime/helpers/esm/typeof.js"() {
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
|
|
70
|
+
var init_toPrimitive = __esm({
|
|
71
|
+
"../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js"() {
|
|
72
|
+
init_typeof();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
|
|
77
|
+
var init_toPropertyKey = __esm({
|
|
78
|
+
"../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js"() {
|
|
79
|
+
init_typeof();
|
|
80
|
+
init_toPrimitive();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
|
|
85
|
+
var init_defineProperty = __esm({
|
|
86
|
+
"../../node_modules/@babel/runtime/helpers/esm/defineProperty.js"() {
|
|
87
|
+
init_toPropertyKey();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// ../loader-utils/src/lib/path-utils/file-aliases.ts
|
|
92
|
+
function resolvePath(filename) {
|
|
93
|
+
for (const alias in fileAliases) {
|
|
94
|
+
if (filename.startsWith(alias)) {
|
|
95
|
+
const replacement = fileAliases[alias];
|
|
96
|
+
filename = filename.replace(alias, replacement);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!filename.startsWith("http://") && !filename.startsWith("https://")) {
|
|
100
|
+
filename = `${pathPrefix}${filename}`;
|
|
101
|
+
}
|
|
102
|
+
return filename;
|
|
103
|
+
}
|
|
104
|
+
var pathPrefix, fileAliases;
|
|
105
|
+
var init_file_aliases = __esm({
|
|
106
|
+
"../loader-utils/src/lib/path-utils/file-aliases.ts"() {
|
|
107
|
+
pathPrefix = "";
|
|
108
|
+
fileAliases = {};
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// ../loader-utils/src/lib/sources/data-source.ts
|
|
113
|
+
function getFetchFunction(options) {
|
|
114
|
+
const fetchFunction = options?.fetch;
|
|
115
|
+
if (fetchFunction && typeof fetchFunction === "function") {
|
|
116
|
+
return (url, fetchOptions2) => fetchFunction(url, fetchOptions2);
|
|
117
|
+
}
|
|
118
|
+
const fetchOptions = options?.fetch;
|
|
119
|
+
if (fetchOptions && typeof fetchOptions !== "function") {
|
|
120
|
+
return (url) => fetch(url, fetchOptions);
|
|
121
|
+
}
|
|
122
|
+
return (url) => fetch(url);
|
|
123
|
+
}
|
|
124
|
+
var DataSource;
|
|
125
|
+
var init_data_source = __esm({
|
|
126
|
+
"../loader-utils/src/lib/sources/data-source.ts"() {
|
|
127
|
+
DataSource = class {
|
|
128
|
+
constructor(props) {
|
|
129
|
+
this._needsRefresh = true;
|
|
130
|
+
this.props = { ...props };
|
|
131
|
+
this.loadOptions = { ...props.loadOptions };
|
|
132
|
+
this.fetch = getFetchFunction(this.loadOptions);
|
|
133
|
+
}
|
|
134
|
+
setProps(props) {
|
|
135
|
+
this.props = Object.assign(this.props, props);
|
|
136
|
+
this.setNeedsRefresh();
|
|
137
|
+
}
|
|
138
|
+
setNeedsRefresh() {
|
|
139
|
+
this._needsRefresh = true;
|
|
140
|
+
}
|
|
141
|
+
getNeedsRefresh(clear = true) {
|
|
142
|
+
const needsRefresh = this._needsRefresh;
|
|
143
|
+
if (clear) {
|
|
144
|
+
this._needsRefresh = false;
|
|
145
|
+
}
|
|
146
|
+
return needsRefresh;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// ../loader-utils/src/index.ts
|
|
153
|
+
var init_src = __esm({
|
|
154
|
+
"../loader-utils/src/index.ts"() {
|
|
155
|
+
init_assert();
|
|
156
|
+
init_globals();
|
|
157
|
+
init_file_aliases();
|
|
158
|
+
init_data_source();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// ../images/src/lib/utils/version.ts
|
|
163
|
+
var VERSION;
|
|
164
|
+
var init_version = __esm({
|
|
165
|
+
"../images/src/lib/utils/version.ts"() {
|
|
166
|
+
VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// ../images/src/lib/category-api/image-type.ts
|
|
171
|
+
function isImageTypeSupported(type) {
|
|
172
|
+
switch (type) {
|
|
173
|
+
case "auto":
|
|
174
|
+
return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
|
|
175
|
+
case "imagebitmap":
|
|
176
|
+
return IMAGE_BITMAP_SUPPORTED;
|
|
177
|
+
case "image":
|
|
178
|
+
return IMAGE_SUPPORTED;
|
|
179
|
+
case "data":
|
|
180
|
+
return DATA_SUPPORTED;
|
|
181
|
+
default:
|
|
182
|
+
throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function getDefaultImageType() {
|
|
186
|
+
if (IMAGE_BITMAP_SUPPORTED) {
|
|
187
|
+
return "imagebitmap";
|
|
188
|
+
}
|
|
189
|
+
if (IMAGE_SUPPORTED) {
|
|
190
|
+
return "image";
|
|
191
|
+
}
|
|
192
|
+
if (DATA_SUPPORTED) {
|
|
193
|
+
return "data";
|
|
194
|
+
}
|
|
195
|
+
throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js");
|
|
196
|
+
}
|
|
197
|
+
var _parseImageNode, IMAGE_SUPPORTED, IMAGE_BITMAP_SUPPORTED, NODE_IMAGE_SUPPORTED, DATA_SUPPORTED;
|
|
198
|
+
var init_image_type = __esm({
|
|
199
|
+
"../images/src/lib/category-api/image-type.ts"() {
|
|
200
|
+
init_src();
|
|
201
|
+
({ _parseImageNode } = globalThis);
|
|
202
|
+
IMAGE_SUPPORTED = typeof Image !== "undefined";
|
|
203
|
+
IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== "undefined";
|
|
204
|
+
NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
|
|
205
|
+
DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// ../images/src/lib/category-api/parsed-image-api.ts
|
|
210
|
+
function getImageType(image) {
|
|
211
|
+
const format = getImageTypeOrNull(image);
|
|
212
|
+
if (!format) {
|
|
213
|
+
throw new Error("Not an image");
|
|
214
|
+
}
|
|
215
|
+
return format;
|
|
216
|
+
}
|
|
217
|
+
function getImageData(image) {
|
|
218
|
+
switch (getImageType(image)) {
|
|
219
|
+
case "data":
|
|
220
|
+
return image;
|
|
221
|
+
case "image":
|
|
222
|
+
case "imagebitmap":
|
|
223
|
+
const canvas = document.createElement("canvas");
|
|
224
|
+
const context = canvas.getContext("2d");
|
|
225
|
+
if (!context) {
|
|
226
|
+
throw new Error("getImageData");
|
|
227
|
+
}
|
|
228
|
+
canvas.width = image.width;
|
|
229
|
+
canvas.height = image.height;
|
|
230
|
+
context.drawImage(image, 0, 0);
|
|
231
|
+
return context.getImageData(0, 0, image.width, image.height);
|
|
232
|
+
default:
|
|
233
|
+
throw new Error("getImageData");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function getImageTypeOrNull(image) {
|
|
237
|
+
if (typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
|
|
238
|
+
return "imagebitmap";
|
|
239
|
+
}
|
|
240
|
+
if (typeof Image !== "undefined" && image instanceof Image) {
|
|
241
|
+
return "image";
|
|
242
|
+
}
|
|
243
|
+
if (image && typeof image === "object" && image.data && image.width && image.height) {
|
|
244
|
+
return "data";
|
|
245
|
+
}
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
var init_parsed_image_api = __esm({
|
|
249
|
+
"../images/src/lib/category-api/parsed-image-api.ts"() {
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// ../images/src/lib/parsers/svg-utils.ts
|
|
254
|
+
function isSVG(url) {
|
|
255
|
+
return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
|
|
256
|
+
}
|
|
257
|
+
function getBlobOrSVGDataUrl(arrayBuffer, url) {
|
|
258
|
+
if (isSVG(url)) {
|
|
259
|
+
const textDecoder = new TextDecoder();
|
|
260
|
+
let xmlText = textDecoder.decode(arrayBuffer);
|
|
261
|
+
try {
|
|
262
|
+
if (typeof unescape === "function" && typeof encodeURIComponent === "function") {
|
|
263
|
+
xmlText = unescape(encodeURIComponent(xmlText));
|
|
264
|
+
}
|
|
265
|
+
} catch (error) {
|
|
266
|
+
throw new Error(error.message);
|
|
267
|
+
}
|
|
268
|
+
const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;
|
|
269
|
+
return src;
|
|
270
|
+
}
|
|
271
|
+
return getBlob(arrayBuffer, url);
|
|
272
|
+
}
|
|
273
|
+
function getBlob(arrayBuffer, url) {
|
|
274
|
+
if (isSVG(url)) {
|
|
275
|
+
throw new Error("SVG cannot be parsed directly to imagebitmap");
|
|
276
|
+
}
|
|
277
|
+
return new Blob([new Uint8Array(arrayBuffer)]);
|
|
278
|
+
}
|
|
279
|
+
var SVG_DATA_URL_PATTERN, SVG_URL_PATTERN;
|
|
280
|
+
var init_svg_utils = __esm({
|
|
281
|
+
"../images/src/lib/parsers/svg-utils.ts"() {
|
|
282
|
+
SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
|
|
283
|
+
SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// ../images/src/lib/parsers/parse-to-image.ts
|
|
288
|
+
async function parseToImage(arrayBuffer, options, url) {
|
|
289
|
+
const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
|
|
290
|
+
const URL = self.URL || self.webkitURL;
|
|
291
|
+
const objectUrl = typeof blobOrDataUrl !== "string" && URL.createObjectURL(blobOrDataUrl);
|
|
292
|
+
try {
|
|
293
|
+
return await loadToImage(objectUrl || blobOrDataUrl, options);
|
|
294
|
+
} finally {
|
|
295
|
+
if (objectUrl) {
|
|
296
|
+
URL.revokeObjectURL(objectUrl);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async function loadToImage(url, options) {
|
|
301
|
+
const image = new Image();
|
|
302
|
+
image.src = url;
|
|
303
|
+
if (options.image && options.image.decode && image.decode) {
|
|
304
|
+
await image.decode();
|
|
305
|
+
return image;
|
|
306
|
+
}
|
|
307
|
+
return await new Promise((resolve, reject) => {
|
|
308
|
+
try {
|
|
309
|
+
image.onload = () => resolve(image);
|
|
310
|
+
image.onerror = (err2) => reject(new Error(`Could not load image ${url}: ${err2}`));
|
|
311
|
+
} catch (error) {
|
|
312
|
+
reject(error);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
var init_parse_to_image = __esm({
|
|
317
|
+
"../images/src/lib/parsers/parse-to-image.ts"() {
|
|
318
|
+
init_svg_utils();
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// ../images/src/lib/parsers/parse-to-image-bitmap.ts
|
|
323
|
+
async function parseToImageBitmap(arrayBuffer, options, url) {
|
|
324
|
+
let blob;
|
|
325
|
+
if (isSVG(url)) {
|
|
326
|
+
const image = await parseToImage(arrayBuffer, options, url);
|
|
327
|
+
blob = image;
|
|
328
|
+
} else {
|
|
329
|
+
blob = getBlob(arrayBuffer, url);
|
|
330
|
+
}
|
|
331
|
+
const imagebitmapOptions = options && options.imagebitmap;
|
|
332
|
+
return await safeCreateImageBitmap(blob, imagebitmapOptions);
|
|
333
|
+
}
|
|
334
|
+
async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
|
|
335
|
+
if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
|
|
336
|
+
imagebitmapOptions = null;
|
|
337
|
+
}
|
|
338
|
+
if (imagebitmapOptions) {
|
|
339
|
+
try {
|
|
340
|
+
return await createImageBitmap(blob, imagebitmapOptions);
|
|
341
|
+
} catch (error) {
|
|
342
|
+
console.warn(error);
|
|
343
|
+
imagebitmapOptionsSupported = false;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return await createImageBitmap(blob);
|
|
347
|
+
}
|
|
348
|
+
function isEmptyObject(object) {
|
|
349
|
+
for (const key in object || EMPTY_OBJECT) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
var EMPTY_OBJECT, imagebitmapOptionsSupported;
|
|
355
|
+
var init_parse_to_image_bitmap = __esm({
|
|
356
|
+
"../images/src/lib/parsers/parse-to-image-bitmap.ts"() {
|
|
357
|
+
init_svg_utils();
|
|
358
|
+
init_parse_to_image();
|
|
359
|
+
EMPTY_OBJECT = {};
|
|
360
|
+
imagebitmapOptionsSupported = true;
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// ../images/src/lib/category-api/parse-isobmff-binary.ts
|
|
365
|
+
function getISOBMFFMediaType(buffer) {
|
|
366
|
+
if (!checkString(buffer, "ftyp", 4)) {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
if ((buffer[8] & 96) === 0) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
return decodeMajorBrand(buffer);
|
|
373
|
+
}
|
|
374
|
+
function decodeMajorBrand(buffer) {
|
|
375
|
+
const brandMajor = getUTF8String(buffer, 8, 12).replace("\0", " ").trim();
|
|
376
|
+
switch (brandMajor) {
|
|
377
|
+
case "avif":
|
|
378
|
+
case "avis":
|
|
379
|
+
return { extension: "avif", mimeType: "image/avif" };
|
|
380
|
+
default:
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function getUTF8String(array, start, end) {
|
|
385
|
+
return String.fromCharCode(...array.slice(start, end));
|
|
386
|
+
}
|
|
387
|
+
function stringToBytes(string) {
|
|
388
|
+
return [...string].map((character) => character.charCodeAt(0));
|
|
389
|
+
}
|
|
390
|
+
function checkString(buffer, header, offset = 0) {
|
|
391
|
+
const headerBytes = stringToBytes(header);
|
|
392
|
+
for (let i3 = 0; i3 < headerBytes.length; ++i3) {
|
|
393
|
+
if (headerBytes[i3] !== buffer[i3 + offset]) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
var init_parse_isobmff_binary = __esm({
|
|
400
|
+
"../images/src/lib/category-api/parse-isobmff-binary.ts"() {
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// ../images/src/lib/category-api/binary-image-api.ts
|
|
405
|
+
function getBinaryImageMetadata(binaryData) {
|
|
406
|
+
const dataView = toDataView(binaryData);
|
|
407
|
+
return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView) || getISOBMFFMetadata(dataView);
|
|
408
|
+
}
|
|
409
|
+
function getISOBMFFMetadata(binaryData) {
|
|
410
|
+
const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
|
|
411
|
+
const mediaType = getISOBMFFMediaType(buffer);
|
|
412
|
+
if (!mediaType) {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
mimeType: mediaType.mimeType,
|
|
417
|
+
width: 0,
|
|
418
|
+
height: 0
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
function getPngMetadata(binaryData) {
|
|
422
|
+
const dataView = toDataView(binaryData);
|
|
423
|
+
const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 2303741511;
|
|
424
|
+
if (!isPng) {
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
mimeType: "image/png",
|
|
429
|
+
width: dataView.getUint32(16, BIG_ENDIAN),
|
|
430
|
+
height: dataView.getUint32(20, BIG_ENDIAN)
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function getGifMetadata(binaryData) {
|
|
434
|
+
const dataView = toDataView(binaryData);
|
|
435
|
+
const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 1195984440;
|
|
436
|
+
if (!isGif) {
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
return {
|
|
440
|
+
mimeType: "image/gif",
|
|
441
|
+
width: dataView.getUint16(6, LITTLE_ENDIAN),
|
|
442
|
+
height: dataView.getUint16(8, LITTLE_ENDIAN)
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function getBmpMetadata(binaryData) {
|
|
446
|
+
const dataView = toDataView(binaryData);
|
|
447
|
+
const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 16973 && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
|
|
448
|
+
if (!isBmp) {
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
mimeType: "image/bmp",
|
|
453
|
+
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
454
|
+
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function getJpegMetadata(binaryData) {
|
|
458
|
+
const dataView = toDataView(binaryData);
|
|
459
|
+
const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 65496 && dataView.getUint8(2) === 255;
|
|
460
|
+
if (!isJpeg) {
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
const { tableMarkers, sofMarkers } = getJpegMarkers();
|
|
464
|
+
let i3 = 2;
|
|
465
|
+
while (i3 + 9 < dataView.byteLength) {
|
|
466
|
+
const marker = dataView.getUint16(i3, BIG_ENDIAN);
|
|
467
|
+
if (sofMarkers.has(marker)) {
|
|
468
|
+
return {
|
|
469
|
+
mimeType: "image/jpeg",
|
|
470
|
+
height: dataView.getUint16(i3 + 5, BIG_ENDIAN),
|
|
471
|
+
width: dataView.getUint16(i3 + 7, BIG_ENDIAN)
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
if (!tableMarkers.has(marker)) {
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
i3 += 2;
|
|
478
|
+
i3 += dataView.getUint16(i3, BIG_ENDIAN);
|
|
479
|
+
}
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
function getJpegMarkers() {
|
|
483
|
+
const tableMarkers = new Set([65499, 65476, 65484, 65501, 65534]);
|
|
484
|
+
for (let i3 = 65504; i3 < 65520; ++i3) {
|
|
485
|
+
tableMarkers.add(i3);
|
|
486
|
+
}
|
|
487
|
+
const sofMarkers = new Set([
|
|
488
|
+
65472,
|
|
489
|
+
65473,
|
|
490
|
+
65474,
|
|
491
|
+
65475,
|
|
492
|
+
65477,
|
|
493
|
+
65478,
|
|
494
|
+
65479,
|
|
495
|
+
65481,
|
|
496
|
+
65482,
|
|
497
|
+
65483,
|
|
498
|
+
65485,
|
|
499
|
+
65486,
|
|
500
|
+
65487,
|
|
501
|
+
65502
|
|
502
|
+
]);
|
|
503
|
+
return { tableMarkers, sofMarkers };
|
|
504
|
+
}
|
|
505
|
+
function toDataView(data) {
|
|
506
|
+
if (data instanceof DataView) {
|
|
507
|
+
return data;
|
|
508
|
+
}
|
|
509
|
+
if (ArrayBuffer.isView(data)) {
|
|
510
|
+
return new DataView(data.buffer);
|
|
511
|
+
}
|
|
512
|
+
if (data instanceof ArrayBuffer) {
|
|
513
|
+
return new DataView(data);
|
|
514
|
+
}
|
|
515
|
+
throw new Error("toDataView");
|
|
516
|
+
}
|
|
517
|
+
var BIG_ENDIAN, LITTLE_ENDIAN;
|
|
518
|
+
var init_binary_image_api = __esm({
|
|
519
|
+
"../images/src/lib/category-api/binary-image-api.ts"() {
|
|
520
|
+
init_parse_isobmff_binary();
|
|
521
|
+
BIG_ENDIAN = false;
|
|
522
|
+
LITTLE_ENDIAN = true;
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
// ../images/src/lib/parsers/parse-to-node-image.ts
|
|
527
|
+
async function parseToNodeImage(arrayBuffer, options) {
|
|
528
|
+
const { mimeType } = getBinaryImageMetadata(arrayBuffer) || {};
|
|
529
|
+
const _parseImageNode2 = globalThis._parseImageNode;
|
|
530
|
+
assert(_parseImageNode2);
|
|
531
|
+
return await _parseImageNode2(arrayBuffer, mimeType);
|
|
532
|
+
}
|
|
533
|
+
var init_parse_to_node_image = __esm({
|
|
534
|
+
"../images/src/lib/parsers/parse-to-node-image.ts"() {
|
|
535
|
+
init_src();
|
|
536
|
+
init_binary_image_api();
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
// ../images/src/lib/parsers/parse-image.ts
|
|
541
|
+
async function parseImage(arrayBuffer, options, context) {
|
|
542
|
+
options = options || {};
|
|
543
|
+
const imageOptions = options.image || {};
|
|
544
|
+
const imageType = imageOptions.type || "auto";
|
|
545
|
+
const { url } = context || {};
|
|
546
|
+
const loadType = getLoadableImageType(imageType);
|
|
547
|
+
let image;
|
|
548
|
+
switch (loadType) {
|
|
549
|
+
case "imagebitmap":
|
|
550
|
+
image = await parseToImageBitmap(arrayBuffer, options, url);
|
|
551
|
+
break;
|
|
552
|
+
case "image":
|
|
553
|
+
image = await parseToImage(arrayBuffer, options, url);
|
|
554
|
+
break;
|
|
555
|
+
case "data":
|
|
556
|
+
image = await parseToNodeImage(arrayBuffer, options);
|
|
557
|
+
break;
|
|
558
|
+
default:
|
|
559
|
+
assert(false);
|
|
560
|
+
}
|
|
561
|
+
if (imageType === "data") {
|
|
562
|
+
image = getImageData(image);
|
|
563
|
+
}
|
|
564
|
+
return image;
|
|
565
|
+
}
|
|
566
|
+
function getLoadableImageType(type) {
|
|
567
|
+
switch (type) {
|
|
568
|
+
case "auto":
|
|
569
|
+
case "data":
|
|
570
|
+
return getDefaultImageType();
|
|
571
|
+
default:
|
|
572
|
+
isImageTypeSupported(type);
|
|
573
|
+
return type;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
var init_parse_image = __esm({
|
|
577
|
+
"../images/src/lib/parsers/parse-image.ts"() {
|
|
578
|
+
init_src();
|
|
579
|
+
init_image_type();
|
|
580
|
+
init_parsed_image_api();
|
|
581
|
+
init_parse_to_image();
|
|
582
|
+
init_parse_to_image_bitmap();
|
|
583
|
+
init_parse_to_node_image();
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
// ../images/src/image-loader.ts
|
|
588
|
+
var EXTENSIONS, MIME_TYPES, DEFAULT_IMAGE_LOADER_OPTIONS, ImageLoader;
|
|
589
|
+
var init_image_loader = __esm({
|
|
590
|
+
"../images/src/image-loader.ts"() {
|
|
591
|
+
init_version();
|
|
592
|
+
init_parse_image();
|
|
593
|
+
init_binary_image_api();
|
|
594
|
+
EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "svg", "avif"];
|
|
595
|
+
MIME_TYPES = [
|
|
596
|
+
"image/png",
|
|
597
|
+
"image/jpeg",
|
|
598
|
+
"image/gif",
|
|
599
|
+
"image/webp",
|
|
600
|
+
"image/avif",
|
|
601
|
+
"image/bmp",
|
|
602
|
+
"image/vnd.microsoft.icon",
|
|
603
|
+
"image/svg+xml"
|
|
604
|
+
];
|
|
605
|
+
DEFAULT_IMAGE_LOADER_OPTIONS = {
|
|
606
|
+
image: {
|
|
607
|
+
type: "auto",
|
|
608
|
+
decode: true
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
ImageLoader = {
|
|
612
|
+
id: "image",
|
|
613
|
+
module: "images",
|
|
614
|
+
name: "Images",
|
|
615
|
+
version: VERSION,
|
|
616
|
+
mimeTypes: MIME_TYPES,
|
|
617
|
+
extensions: EXTENSIONS,
|
|
618
|
+
parse: parseImage,
|
|
619
|
+
tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
|
|
620
|
+
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
// ../images/src/index.ts
|
|
626
|
+
var init_src2 = __esm({
|
|
627
|
+
"../images/src/index.ts"() {
|
|
628
|
+
init_image_loader();
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
|
|
633
|
+
function getPolygonSignedArea(points, options = {}) {
|
|
634
|
+
const {
|
|
635
|
+
start = 0,
|
|
636
|
+
end = points.length
|
|
637
|
+
} = options;
|
|
638
|
+
const dim = options.size || 2;
|
|
639
|
+
let area2 = 0;
|
|
640
|
+
for (let i3 = start, j = end - dim; i3 < end; i3 += dim) {
|
|
641
|
+
area2 += (points[i3] - points[j]) * (points[i3 + 1] + points[j + 1]);
|
|
642
|
+
j = i3;
|
|
643
|
+
}
|
|
644
|
+
return area2 / 2;
|
|
645
|
+
}
|
|
646
|
+
var init_polygon_utils = __esm({
|
|
647
|
+
"../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
|
|
652
|
+
var init_polygon = __esm({
|
|
653
|
+
"../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
|
|
654
|
+
init_defineProperty();
|
|
655
|
+
init_polygon_utils();
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
|
|
660
|
+
function earcut(positions, holeIndices, dim = 2, areas) {
|
|
661
|
+
const hasHoles = holeIndices && holeIndices.length;
|
|
662
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
|
|
663
|
+
let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0]);
|
|
664
|
+
const triangles = [];
|
|
665
|
+
if (!outerNode || outerNode.next === outerNode.prev)
|
|
666
|
+
return triangles;
|
|
667
|
+
let invSize;
|
|
668
|
+
let maxX;
|
|
669
|
+
let maxY;
|
|
670
|
+
let minX;
|
|
671
|
+
let minY;
|
|
672
|
+
let x3;
|
|
673
|
+
let y2;
|
|
674
|
+
if (hasHoles)
|
|
675
|
+
outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
|
|
676
|
+
if (positions.length > 80 * dim) {
|
|
677
|
+
minX = maxX = positions[0];
|
|
678
|
+
minY = maxY = positions[1];
|
|
679
|
+
for (let i3 = dim; i3 < outerLen; i3 += dim) {
|
|
680
|
+
x3 = positions[i3];
|
|
681
|
+
y2 = positions[i3 + 1];
|
|
682
|
+
if (x3 < minX)
|
|
683
|
+
minX = x3;
|
|
684
|
+
if (y2 < minY)
|
|
685
|
+
minY = y2;
|
|
686
|
+
if (x3 > maxX)
|
|
687
|
+
maxX = x3;
|
|
688
|
+
if (y2 > maxY)
|
|
689
|
+
maxY = y2;
|
|
690
|
+
}
|
|
691
|
+
invSize = Math.max(maxX - minX, maxY - minY);
|
|
692
|
+
invSize = invSize !== 0 ? 1 / invSize : 0;
|
|
693
|
+
}
|
|
694
|
+
earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
|
|
695
|
+
return triangles;
|
|
696
|
+
}
|
|
697
|
+
function linkedList(data, start, end, dim, clockwise, area2) {
|
|
698
|
+
let i3;
|
|
699
|
+
let last;
|
|
700
|
+
if (area2 === void 0) {
|
|
701
|
+
area2 = getPolygonSignedArea(data, {
|
|
702
|
+
start,
|
|
703
|
+
end,
|
|
704
|
+
size: dim
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
if (clockwise === area2 < 0) {
|
|
708
|
+
for (i3 = start; i3 < end; i3 += dim)
|
|
709
|
+
last = insertNode(i3, data[i3], data[i3 + 1], last);
|
|
710
|
+
} else {
|
|
711
|
+
for (i3 = end - dim; i3 >= start; i3 -= dim)
|
|
712
|
+
last = insertNode(i3, data[i3], data[i3 + 1], last);
|
|
713
|
+
}
|
|
714
|
+
if (last && equals(last, last.next)) {
|
|
715
|
+
removeNode(last);
|
|
716
|
+
last = last.next;
|
|
717
|
+
}
|
|
718
|
+
return last;
|
|
719
|
+
}
|
|
720
|
+
function filterPoints(start, end) {
|
|
721
|
+
if (!start)
|
|
722
|
+
return start;
|
|
723
|
+
if (!end)
|
|
724
|
+
end = start;
|
|
725
|
+
let p = start;
|
|
726
|
+
let again;
|
|
727
|
+
do {
|
|
728
|
+
again = false;
|
|
729
|
+
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
730
|
+
removeNode(p);
|
|
731
|
+
p = end = p.prev;
|
|
732
|
+
if (p === p.next)
|
|
733
|
+
break;
|
|
734
|
+
again = true;
|
|
735
|
+
} else {
|
|
736
|
+
p = p.next;
|
|
737
|
+
}
|
|
738
|
+
} while (again || p !== end);
|
|
739
|
+
return end;
|
|
740
|
+
}
|
|
741
|
+
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
742
|
+
if (!ear)
|
|
743
|
+
return;
|
|
744
|
+
if (!pass && invSize)
|
|
745
|
+
indexCurve(ear, minX, minY, invSize);
|
|
746
|
+
let stop = ear;
|
|
747
|
+
let prev;
|
|
748
|
+
let next;
|
|
749
|
+
while (ear.prev !== ear.next) {
|
|
750
|
+
prev = ear.prev;
|
|
751
|
+
next = ear.next;
|
|
752
|
+
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
753
|
+
triangles.push(prev.i / dim);
|
|
754
|
+
triangles.push(ear.i / dim);
|
|
755
|
+
triangles.push(next.i / dim);
|
|
756
|
+
removeNode(ear);
|
|
757
|
+
ear = next.next;
|
|
758
|
+
stop = next.next;
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
ear = next;
|
|
762
|
+
if (ear === stop) {
|
|
763
|
+
if (!pass) {
|
|
764
|
+
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
765
|
+
} else if (pass === 1) {
|
|
766
|
+
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
767
|
+
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
768
|
+
} else if (pass === 2) {
|
|
769
|
+
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
770
|
+
}
|
|
771
|
+
break;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
function isEar(ear) {
|
|
776
|
+
const a = ear.prev;
|
|
777
|
+
const b = ear;
|
|
778
|
+
const c = ear.next;
|
|
779
|
+
if (area(a, b, c) >= 0)
|
|
780
|
+
return false;
|
|
781
|
+
let p = ear.next.next;
|
|
782
|
+
while (p !== ear.prev) {
|
|
783
|
+
if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
784
|
+
return false;
|
|
785
|
+
p = p.next;
|
|
786
|
+
}
|
|
787
|
+
return true;
|
|
788
|
+
}
|
|
789
|
+
function isEarHashed(ear, minX, minY, invSize) {
|
|
790
|
+
const a = ear.prev;
|
|
791
|
+
const b = ear;
|
|
792
|
+
const c = ear.next;
|
|
793
|
+
if (area(a, b, c) >= 0)
|
|
794
|
+
return false;
|
|
795
|
+
const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
|
|
796
|
+
const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
|
|
797
|
+
const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
|
|
798
|
+
const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
|
|
799
|
+
const minZ = zOrder(minTX, minTY, minX, minY, invSize);
|
|
800
|
+
const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
|
|
801
|
+
let p = ear.prevZ;
|
|
802
|
+
let n = ear.nextZ;
|
|
803
|
+
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
804
|
+
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
805
|
+
return false;
|
|
806
|
+
p = p.prevZ;
|
|
807
|
+
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
808
|
+
return false;
|
|
809
|
+
n = n.nextZ;
|
|
810
|
+
}
|
|
811
|
+
while (p && p.z >= minZ) {
|
|
812
|
+
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
813
|
+
return false;
|
|
814
|
+
p = p.prevZ;
|
|
815
|
+
}
|
|
816
|
+
while (n && n.z <= maxZ) {
|
|
817
|
+
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
818
|
+
return false;
|
|
819
|
+
n = n.nextZ;
|
|
820
|
+
}
|
|
821
|
+
return true;
|
|
822
|
+
}
|
|
823
|
+
function cureLocalIntersections(start, triangles, dim) {
|
|
824
|
+
let p = start;
|
|
825
|
+
do {
|
|
826
|
+
const a = p.prev;
|
|
827
|
+
const b = p.next.next;
|
|
828
|
+
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
829
|
+
triangles.push(a.i / dim);
|
|
830
|
+
triangles.push(p.i / dim);
|
|
831
|
+
triangles.push(b.i / dim);
|
|
832
|
+
removeNode(p);
|
|
833
|
+
removeNode(p.next);
|
|
834
|
+
p = start = b;
|
|
835
|
+
}
|
|
836
|
+
p = p.next;
|
|
837
|
+
} while (p !== start);
|
|
838
|
+
return filterPoints(p);
|
|
839
|
+
}
|
|
840
|
+
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
841
|
+
let a = start;
|
|
842
|
+
do {
|
|
843
|
+
let b = a.next.next;
|
|
844
|
+
while (b !== a.prev) {
|
|
845
|
+
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
846
|
+
let c = splitPolygon(a, b);
|
|
847
|
+
a = filterPoints(a, a.next);
|
|
848
|
+
c = filterPoints(c, c.next);
|
|
849
|
+
earcutLinked(a, triangles, dim, minX, minY, invSize);
|
|
850
|
+
earcutLinked(c, triangles, dim, minX, minY, invSize);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
b = b.next;
|
|
854
|
+
}
|
|
855
|
+
a = a.next;
|
|
856
|
+
} while (a !== start);
|
|
857
|
+
}
|
|
858
|
+
function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
|
|
859
|
+
const queue = [];
|
|
860
|
+
let i3;
|
|
861
|
+
let len;
|
|
862
|
+
let start;
|
|
863
|
+
let end;
|
|
864
|
+
let list;
|
|
865
|
+
for (i3 = 0, len = holeIndices.length; i3 < len; i3++) {
|
|
866
|
+
start = holeIndices[i3] * dim;
|
|
867
|
+
end = i3 < len - 1 ? holeIndices[i3 + 1] * dim : data.length;
|
|
868
|
+
list = linkedList(data, start, end, dim, false, areas && areas[i3 + 1]);
|
|
869
|
+
if (list === list.next)
|
|
870
|
+
list.steiner = true;
|
|
871
|
+
queue.push(getLeftmost(list));
|
|
872
|
+
}
|
|
873
|
+
queue.sort(compareX);
|
|
874
|
+
for (i3 = 0; i3 < queue.length; i3++) {
|
|
875
|
+
eliminateHole(queue[i3], outerNode);
|
|
876
|
+
outerNode = filterPoints(outerNode, outerNode.next);
|
|
877
|
+
}
|
|
878
|
+
return outerNode;
|
|
879
|
+
}
|
|
880
|
+
function compareX(a, b) {
|
|
881
|
+
return a.x - b.x;
|
|
882
|
+
}
|
|
883
|
+
function eliminateHole(hole, outerNode) {
|
|
884
|
+
outerNode = findHoleBridge(hole, outerNode);
|
|
885
|
+
if (outerNode) {
|
|
886
|
+
const b = splitPolygon(outerNode, hole);
|
|
887
|
+
filterPoints(outerNode, outerNode.next);
|
|
888
|
+
filterPoints(b, b.next);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
function findHoleBridge(hole, outerNode) {
|
|
892
|
+
let p = outerNode;
|
|
893
|
+
const hx = hole.x;
|
|
894
|
+
const hy = hole.y;
|
|
895
|
+
let qx = -Infinity;
|
|
896
|
+
let m;
|
|
897
|
+
do {
|
|
898
|
+
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
|
899
|
+
const x3 = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
|
900
|
+
if (x3 <= hx && x3 > qx) {
|
|
901
|
+
qx = x3;
|
|
902
|
+
if (x3 === hx) {
|
|
903
|
+
if (hy === p.y)
|
|
904
|
+
return p;
|
|
905
|
+
if (hy === p.next.y)
|
|
906
|
+
return p.next;
|
|
907
|
+
}
|
|
908
|
+
m = p.x < p.next.x ? p : p.next;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
p = p.next;
|
|
912
|
+
} while (p !== outerNode);
|
|
913
|
+
if (!m)
|
|
914
|
+
return null;
|
|
915
|
+
if (hx === qx)
|
|
916
|
+
return m;
|
|
917
|
+
const stop = m;
|
|
918
|
+
const mx = m.x;
|
|
919
|
+
const my = m.y;
|
|
920
|
+
let tanMin = Infinity;
|
|
921
|
+
let tan;
|
|
922
|
+
p = m;
|
|
923
|
+
do {
|
|
924
|
+
if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
|
925
|
+
tan = Math.abs(hy - p.y) / (hx - p.x);
|
|
926
|
+
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
|
|
927
|
+
m = p;
|
|
928
|
+
tanMin = tan;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
p = p.next;
|
|
932
|
+
} while (p !== stop);
|
|
933
|
+
return m;
|
|
934
|
+
}
|
|
935
|
+
function sectorContainsSector(m, p) {
|
|
936
|
+
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
|
937
|
+
}
|
|
938
|
+
function indexCurve(start, minX, minY, invSize) {
|
|
939
|
+
let p = start;
|
|
940
|
+
do {
|
|
941
|
+
if (p.z === null)
|
|
942
|
+
p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
|
943
|
+
p.prevZ = p.prev;
|
|
944
|
+
p.nextZ = p.next;
|
|
945
|
+
p = p.next;
|
|
946
|
+
} while (p !== start);
|
|
947
|
+
p.prevZ.nextZ = null;
|
|
948
|
+
p.prevZ = null;
|
|
949
|
+
sortLinked(p);
|
|
950
|
+
}
|
|
951
|
+
function sortLinked(list) {
|
|
952
|
+
let e;
|
|
953
|
+
let i3;
|
|
954
|
+
let inSize = 1;
|
|
955
|
+
let numMerges;
|
|
956
|
+
let p;
|
|
957
|
+
let pSize;
|
|
958
|
+
let q;
|
|
959
|
+
let qSize;
|
|
960
|
+
let tail;
|
|
961
|
+
do {
|
|
962
|
+
p = list;
|
|
963
|
+
list = null;
|
|
964
|
+
tail = null;
|
|
965
|
+
numMerges = 0;
|
|
966
|
+
while (p) {
|
|
967
|
+
numMerges++;
|
|
968
|
+
q = p;
|
|
969
|
+
pSize = 0;
|
|
970
|
+
for (i3 = 0; i3 < inSize; i3++) {
|
|
971
|
+
pSize++;
|
|
972
|
+
q = q.nextZ;
|
|
973
|
+
if (!q)
|
|
974
|
+
break;
|
|
975
|
+
}
|
|
976
|
+
qSize = inSize;
|
|
977
|
+
while (pSize > 0 || qSize > 0 && q) {
|
|
978
|
+
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
|
979
|
+
e = p;
|
|
980
|
+
p = p.nextZ;
|
|
981
|
+
pSize--;
|
|
982
|
+
} else {
|
|
983
|
+
e = q;
|
|
984
|
+
q = q.nextZ;
|
|
985
|
+
qSize--;
|
|
986
|
+
}
|
|
987
|
+
if (tail)
|
|
988
|
+
tail.nextZ = e;
|
|
989
|
+
else
|
|
990
|
+
list = e;
|
|
991
|
+
e.prevZ = tail;
|
|
992
|
+
tail = e;
|
|
993
|
+
}
|
|
994
|
+
p = q;
|
|
995
|
+
}
|
|
996
|
+
tail.nextZ = null;
|
|
997
|
+
inSize *= 2;
|
|
998
|
+
} while (numMerges > 1);
|
|
999
|
+
return list;
|
|
1000
|
+
}
|
|
1001
|
+
function zOrder(x3, y2, minX, minY, invSize) {
|
|
1002
|
+
x3 = 32767 * (x3 - minX) * invSize;
|
|
1003
|
+
y2 = 32767 * (y2 - minY) * invSize;
|
|
1004
|
+
x3 = (x3 | x3 << 8) & 16711935;
|
|
1005
|
+
x3 = (x3 | x3 << 4) & 252645135;
|
|
1006
|
+
x3 = (x3 | x3 << 2) & 858993459;
|
|
1007
|
+
x3 = (x3 | x3 << 1) & 1431655765;
|
|
1008
|
+
y2 = (y2 | y2 << 8) & 16711935;
|
|
1009
|
+
y2 = (y2 | y2 << 4) & 252645135;
|
|
1010
|
+
y2 = (y2 | y2 << 2) & 858993459;
|
|
1011
|
+
y2 = (y2 | y2 << 1) & 1431655765;
|
|
1012
|
+
return x3 | y2 << 1;
|
|
1013
|
+
}
|
|
1014
|
+
function getLeftmost(start) {
|
|
1015
|
+
let p = start;
|
|
1016
|
+
let leftmost = start;
|
|
1017
|
+
do {
|
|
1018
|
+
if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
|
|
1019
|
+
leftmost = p;
|
|
1020
|
+
p = p.next;
|
|
1021
|
+
} while (p !== start);
|
|
1022
|
+
return leftmost;
|
|
1023
|
+
}
|
|
1024
|
+
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
|
1025
|
+
return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
|
|
1026
|
+
}
|
|
1027
|
+
function isValidDiagonal(a, b) {
|
|
1028
|
+
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
|
|
1029
|
+
}
|
|
1030
|
+
function area(p, q, r) {
|
|
1031
|
+
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
1032
|
+
}
|
|
1033
|
+
function equals(p1, p2) {
|
|
1034
|
+
return p1.x === p2.x && p1.y === p2.y;
|
|
1035
|
+
}
|
|
1036
|
+
function intersects(p1, q1, p2, q2) {
|
|
1037
|
+
const o1 = sign(area(p1, q1, p2));
|
|
1038
|
+
const o2 = sign(area(p1, q1, q2));
|
|
1039
|
+
const o3 = sign(area(p2, q2, p1));
|
|
1040
|
+
const o4 = sign(area(p2, q2, q1));
|
|
1041
|
+
if (o1 !== o2 && o3 !== o4)
|
|
1042
|
+
return true;
|
|
1043
|
+
if (o1 === 0 && onSegment(p1, p2, q1))
|
|
1044
|
+
return true;
|
|
1045
|
+
if (o2 === 0 && onSegment(p1, q2, q1))
|
|
1046
|
+
return true;
|
|
1047
|
+
if (o3 === 0 && onSegment(p2, p1, q2))
|
|
1048
|
+
return true;
|
|
1049
|
+
if (o4 === 0 && onSegment(p2, q1, q2))
|
|
1050
|
+
return true;
|
|
1051
|
+
return false;
|
|
1052
|
+
}
|
|
1053
|
+
function onSegment(p, q, r) {
|
|
1054
|
+
return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
|
|
1055
|
+
}
|
|
1056
|
+
function sign(num) {
|
|
1057
|
+
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
|
1058
|
+
}
|
|
1059
|
+
function intersectsPolygon(a, b) {
|
|
1060
|
+
let p = a;
|
|
1061
|
+
do {
|
|
1062
|
+
if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
|
|
1063
|
+
return true;
|
|
1064
|
+
p = p.next;
|
|
1065
|
+
} while (p !== a);
|
|
1066
|
+
return false;
|
|
1067
|
+
}
|
|
1068
|
+
function locallyInside(a, b) {
|
|
1069
|
+
return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
|
|
1070
|
+
}
|
|
1071
|
+
function middleInside(a, b) {
|
|
1072
|
+
let p = a;
|
|
1073
|
+
let inside = false;
|
|
1074
|
+
const px = (a.x + b.x) / 2;
|
|
1075
|
+
const py = (a.y + b.y) / 2;
|
|
1076
|
+
do {
|
|
1077
|
+
if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
|
|
1078
|
+
inside = !inside;
|
|
1079
|
+
p = p.next;
|
|
1080
|
+
} while (p !== a);
|
|
1081
|
+
return inside;
|
|
1082
|
+
}
|
|
1083
|
+
function splitPolygon(a, b) {
|
|
1084
|
+
const a2 = new Node(a.i, a.x, a.y);
|
|
1085
|
+
const b2 = new Node(b.i, b.x, b.y);
|
|
1086
|
+
const an = a.next;
|
|
1087
|
+
const bp = b.prev;
|
|
1088
|
+
a.next = b;
|
|
1089
|
+
b.prev = a;
|
|
1090
|
+
a2.next = an;
|
|
1091
|
+
an.prev = a2;
|
|
1092
|
+
b2.next = a2;
|
|
1093
|
+
a2.prev = b2;
|
|
1094
|
+
bp.next = b2;
|
|
1095
|
+
b2.prev = bp;
|
|
1096
|
+
return b2;
|
|
1097
|
+
}
|
|
1098
|
+
function insertNode(i3, x3, y2, last) {
|
|
1099
|
+
const p = new Node(i3, x3, y2);
|
|
1100
|
+
if (!last) {
|
|
1101
|
+
p.prev = p;
|
|
1102
|
+
p.next = p;
|
|
1103
|
+
} else {
|
|
1104
|
+
p.next = last.next;
|
|
1105
|
+
p.prev = last;
|
|
1106
|
+
last.next.prev = p;
|
|
1107
|
+
last.next = p;
|
|
1108
|
+
}
|
|
1109
|
+
return p;
|
|
1110
|
+
}
|
|
1111
|
+
function removeNode(p) {
|
|
1112
|
+
p.next.prev = p.prev;
|
|
1113
|
+
p.prev.next = p.next;
|
|
1114
|
+
if (p.prevZ)
|
|
1115
|
+
p.prevZ.nextZ = p.nextZ;
|
|
1116
|
+
if (p.nextZ)
|
|
1117
|
+
p.nextZ.prevZ = p.prevZ;
|
|
1118
|
+
}
|
|
1119
|
+
function Node(i3, x3, y2) {
|
|
1120
|
+
this.i = i3;
|
|
1121
|
+
this.x = x3;
|
|
1122
|
+
this.y = y2;
|
|
1123
|
+
this.prev = null;
|
|
1124
|
+
this.next = null;
|
|
1125
|
+
this.z = null;
|
|
1126
|
+
this.prevZ = null;
|
|
1127
|
+
this.nextZ = null;
|
|
1128
|
+
this.steiner = false;
|
|
1129
|
+
}
|
|
1130
|
+
var init_earcut = __esm({
|
|
1131
|
+
"../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
|
|
1132
|
+
init_polygon_utils();
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/utils.js
|
|
1137
|
+
var init_utils = __esm({
|
|
1138
|
+
"../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
|
|
1143
|
+
var init_lineclip = __esm({
|
|
1144
|
+
"../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
|
|
1145
|
+
init_utils();
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
1148
|
+
|
|
1149
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
|
|
1150
|
+
var init_cut_by_grid = __esm({
|
|
1151
|
+
"../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
|
|
1152
|
+
init_lineclip();
|
|
1153
|
+
init_utils();
|
|
1154
|
+
}
|
|
1155
|
+
});
|
|
1156
|
+
|
|
1157
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
|
|
1158
|
+
var init_cut_by_mercator_bounds = __esm({
|
|
1159
|
+
"../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
|
|
1160
|
+
init_cut_by_grid();
|
|
1161
|
+
init_utils();
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/index.js
|
|
1166
|
+
var init_esm = __esm({
|
|
1167
|
+
"../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
|
|
1168
|
+
init_polygon();
|
|
1169
|
+
init_polygon_utils();
|
|
1170
|
+
init_earcut();
|
|
1171
|
+
init_lineclip();
|
|
1172
|
+
init_cut_by_grid();
|
|
1173
|
+
init_cut_by_mercator_bounds();
|
|
1174
|
+
init_polygon();
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
|
|
1178
|
+
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1179
|
+
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1180
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
1181
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1182
|
+
return fillArrays(features, {
|
|
1183
|
+
propArrayTypes,
|
|
1184
|
+
...geometryInfo
|
|
1185
|
+
}, {
|
|
1186
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1187
|
+
PositionDataType: options ? options.PositionDataType : Float32Array,
|
|
1188
|
+
triangulate: options ? options.triangulate : true
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
function extractNumericPropTypes(features) {
|
|
1192
|
+
const propArrayTypes = {};
|
|
1193
|
+
for (const feature of features) {
|
|
1194
|
+
if (feature.properties) {
|
|
1195
|
+
for (const key in feature.properties) {
|
|
1196
|
+
const val = feature.properties[key];
|
|
1197
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
return propArrayTypes;
|
|
1202
|
+
}
|
|
1203
|
+
function fillArrays(features, geometryInfo, options) {
|
|
1204
|
+
const {
|
|
1205
|
+
pointPositionsCount,
|
|
1206
|
+
pointFeaturesCount,
|
|
1207
|
+
linePositionsCount,
|
|
1208
|
+
linePathsCount,
|
|
1209
|
+
lineFeaturesCount,
|
|
1210
|
+
polygonPositionsCount,
|
|
1211
|
+
polygonObjectsCount,
|
|
1212
|
+
polygonRingsCount,
|
|
1213
|
+
polygonFeaturesCount,
|
|
1214
|
+
propArrayTypes,
|
|
1215
|
+
coordLength
|
|
1216
|
+
} = geometryInfo;
|
|
1217
|
+
const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
|
|
1218
|
+
const hasGlobalId = features[0] && "id" in features[0];
|
|
1219
|
+
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1220
|
+
const points = {
|
|
1221
|
+
type: "Point",
|
|
1222
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1223
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1224
|
+
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1225
|
+
numericProps: {},
|
|
1226
|
+
properties: [],
|
|
1227
|
+
fields: []
|
|
1228
|
+
};
|
|
1229
|
+
const lines = {
|
|
1230
|
+
type: "LineString",
|
|
1231
|
+
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
1232
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
1233
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
1234
|
+
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
1235
|
+
numericProps: {},
|
|
1236
|
+
properties: [],
|
|
1237
|
+
fields: []
|
|
1238
|
+
};
|
|
1239
|
+
const polygons = {
|
|
1240
|
+
type: "Polygon",
|
|
1241
|
+
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1242
|
+
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1243
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
1244
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1245
|
+
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1246
|
+
numericProps: {},
|
|
1247
|
+
properties: [],
|
|
1248
|
+
fields: []
|
|
1249
|
+
};
|
|
1250
|
+
if (triangulate) {
|
|
1251
|
+
polygons.triangles = [];
|
|
1252
|
+
}
|
|
1253
|
+
for (const object of [points, lines, polygons]) {
|
|
1254
|
+
for (const propName of numericPropKeys) {
|
|
1255
|
+
const T = propArrayTypes[propName];
|
|
1256
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
1260
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
1261
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
1262
|
+
const indexMap = {
|
|
1263
|
+
pointPosition: 0,
|
|
1264
|
+
pointFeature: 0,
|
|
1265
|
+
linePosition: 0,
|
|
1266
|
+
linePath: 0,
|
|
1267
|
+
lineFeature: 0,
|
|
1268
|
+
polygonPosition: 0,
|
|
1269
|
+
polygonObject: 0,
|
|
1270
|
+
polygonRing: 0,
|
|
1271
|
+
polygonFeature: 0,
|
|
1272
|
+
feature: 0
|
|
1273
|
+
};
|
|
1274
|
+
for (const feature of features) {
|
|
1275
|
+
const geometry = feature.geometry;
|
|
1276
|
+
const properties = feature.properties || {};
|
|
1277
|
+
switch (geometry.type) {
|
|
1278
|
+
case "Point":
|
|
1279
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1280
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1281
|
+
if (hasGlobalId) {
|
|
1282
|
+
points.fields.push({ id: feature.id });
|
|
1283
|
+
}
|
|
1284
|
+
indexMap.pointFeature++;
|
|
1285
|
+
break;
|
|
1286
|
+
case "LineString":
|
|
1287
|
+
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1288
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1289
|
+
if (hasGlobalId) {
|
|
1290
|
+
lines.fields.push({ id: feature.id });
|
|
1291
|
+
}
|
|
1292
|
+
indexMap.lineFeature++;
|
|
1293
|
+
break;
|
|
1294
|
+
case "Polygon":
|
|
1295
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1296
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1297
|
+
if (hasGlobalId) {
|
|
1298
|
+
polygons.fields.push({ id: feature.id });
|
|
1299
|
+
}
|
|
1300
|
+
indexMap.polygonFeature++;
|
|
1301
|
+
break;
|
|
1302
|
+
default:
|
|
1303
|
+
throw new Error("Invalid geometry type");
|
|
1304
|
+
}
|
|
1305
|
+
indexMap.feature++;
|
|
1306
|
+
}
|
|
1307
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
1308
|
+
}
|
|
1309
|
+
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
1310
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
1311
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1312
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
1313
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1314
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1315
|
+
indexMap.pointPosition += nPositions;
|
|
1316
|
+
}
|
|
1317
|
+
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1318
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1319
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1320
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1321
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1322
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1323
|
+
for (let i3 = 0, il = geometry.indices.length; i3 < il; ++i3) {
|
|
1324
|
+
const start = geometry.indices[i3];
|
|
1325
|
+
const end = i3 === il - 1 ? geometry.data.length : geometry.indices[i3 + 1];
|
|
1326
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1327
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
1331
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
1332
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1333
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
1334
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1335
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1336
|
+
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
1337
|
+
const startPosition = indexMap.polygonPosition;
|
|
1338
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
1339
|
+
const areas = geometry.areas[l];
|
|
1340
|
+
const indices = geometry.indices[l];
|
|
1341
|
+
const nextIndices = geometry.indices[l + 1];
|
|
1342
|
+
for (let i3 = 0, il = indices.length; i3 < il; ++i3) {
|
|
1343
|
+
const start = indices[i3];
|
|
1344
|
+
const end = i3 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i3 + 1];
|
|
1345
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
1346
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
1347
|
+
}
|
|
1348
|
+
const endPosition = indexMap.polygonPosition;
|
|
1349
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
function triangulatePolygon(polygons, areas, indices, {
|
|
1353
|
+
startPosition,
|
|
1354
|
+
endPosition,
|
|
1355
|
+
coordLength
|
|
1356
|
+
}) {
|
|
1357
|
+
if (!polygons.triangles) {
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
const start = startPosition * coordLength;
|
|
1361
|
+
const end = endPosition * coordLength;
|
|
1362
|
+
const polygonPositions = polygons.positions.subarray(start, end);
|
|
1363
|
+
const offset = indices[0];
|
|
1364
|
+
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
1365
|
+
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
1366
|
+
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
1367
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
function wrapProps(obj, size) {
|
|
1371
|
+
const returnObj = {};
|
|
1372
|
+
for (const key in obj) {
|
|
1373
|
+
returnObj[key] = { value: obj[key], size };
|
|
1374
|
+
}
|
|
1375
|
+
return returnObj;
|
|
1376
|
+
}
|
|
1377
|
+
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1378
|
+
const binaryFeatures = {
|
|
1379
|
+
points: {
|
|
1380
|
+
...points,
|
|
1381
|
+
positions: { value: points.positions, size: coordLength },
|
|
1382
|
+
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
1383
|
+
featureIds: { value: points.featureIds, size: 1 },
|
|
1384
|
+
numericProps: wrapProps(points.numericProps, 1)
|
|
1385
|
+
},
|
|
1386
|
+
lines: {
|
|
1387
|
+
...lines,
|
|
1388
|
+
positions: { value: lines.positions, size: coordLength },
|
|
1389
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1390
|
+
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
1391
|
+
featureIds: { value: lines.featureIds, size: 1 },
|
|
1392
|
+
numericProps: wrapProps(lines.numericProps, 1)
|
|
1393
|
+
},
|
|
1394
|
+
polygons: {
|
|
1395
|
+
...polygons,
|
|
1396
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
1397
|
+
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
1398
|
+
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
1399
|
+
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
1400
|
+
featureIds: { value: polygons.featureIds, size: 1 },
|
|
1401
|
+
numericProps: wrapProps(polygons.numericProps, 1)
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
if (binaryFeatures.polygons && polygons.triangles) {
|
|
1405
|
+
binaryFeatures.polygons.triangles = { value: new Uint32Array(polygons.triangles), size: 1 };
|
|
1406
|
+
}
|
|
1407
|
+
return binaryFeatures;
|
|
1408
|
+
}
|
|
1409
|
+
function fillNumericProperties(object, properties, index, length2) {
|
|
1410
|
+
for (const numericPropName in object.numericProps) {
|
|
1411
|
+
if (numericPropName in properties) {
|
|
1412
|
+
const value = properties[numericPropName];
|
|
1413
|
+
object.numericProps[numericPropName].fill(value, index, index + length2);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
function keepStringProperties(properties, numericKeys) {
|
|
1418
|
+
const props = {};
|
|
1419
|
+
for (const key in properties) {
|
|
1420
|
+
if (!numericKeys.includes(key)) {
|
|
1421
|
+
props[key] = properties[key];
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
return props;
|
|
1425
|
+
}
|
|
1426
|
+
function deduceArrayType(x3, constructor) {
|
|
1427
|
+
if (constructor === Array || !Number.isFinite(x3)) {
|
|
1428
|
+
return Array;
|
|
1429
|
+
}
|
|
1430
|
+
return constructor === Float64Array || Math.fround(x3) !== x3 ? Float64Array : Float32Array;
|
|
1431
|
+
}
|
|
1432
|
+
var init_flat_geojson_to_binary = __esm({
|
|
1433
|
+
"../gis/src/lib/flat-geojson-to-binary.ts"() {
|
|
1434
|
+
init_esm();
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
|
|
1438
|
+
// ../gis/src/index.ts
|
|
1439
|
+
var init_src3 = __esm({
|
|
1440
|
+
"../gis/src/index.ts"() {
|
|
1441
|
+
init_flat_geojson_to_binary();
|
|
1442
|
+
}
|
|
1443
|
+
});
|
|
1444
|
+
|
|
1445
|
+
// ../../node_modules/ieee754/index.js
|
|
1446
|
+
var require_ieee754 = __commonJS({
|
|
1447
|
+
"../../node_modules/ieee754/index.js"(exports) {
|
|
1448
|
+
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
1449
|
+
var e, m;
|
|
1450
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
1451
|
+
var eMax = (1 << eLen) - 1;
|
|
1452
|
+
var eBias = eMax >> 1;
|
|
1453
|
+
var nBits = -7;
|
|
1454
|
+
var i3 = isLE ? nBytes - 1 : 0;
|
|
1455
|
+
var d = isLE ? -1 : 1;
|
|
1456
|
+
var s = buffer[offset + i3];
|
|
1457
|
+
i3 += d;
|
|
1458
|
+
e = s & (1 << -nBits) - 1;
|
|
1459
|
+
s >>= -nBits;
|
|
1460
|
+
nBits += eLen;
|
|
1461
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i3], i3 += d, nBits -= 8) {
|
|
1462
|
+
}
|
|
1463
|
+
m = e & (1 << -nBits) - 1;
|
|
1464
|
+
e >>= -nBits;
|
|
1465
|
+
nBits += mLen;
|
|
1466
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i3], i3 += d, nBits -= 8) {
|
|
1467
|
+
}
|
|
1468
|
+
if (e === 0) {
|
|
1469
|
+
e = 1 - eBias;
|
|
1470
|
+
} else if (e === eMax) {
|
|
1471
|
+
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
1472
|
+
} else {
|
|
1473
|
+
m = m + Math.pow(2, mLen);
|
|
1474
|
+
e = e - eBias;
|
|
1475
|
+
}
|
|
1476
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
1477
|
+
};
|
|
1478
|
+
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
1479
|
+
var e, m, c;
|
|
1480
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
1481
|
+
var eMax = (1 << eLen) - 1;
|
|
1482
|
+
var eBias = eMax >> 1;
|
|
1483
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
1484
|
+
var i3 = isLE ? 0 : nBytes - 1;
|
|
1485
|
+
var d = isLE ? 1 : -1;
|
|
1486
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
1487
|
+
value = Math.abs(value);
|
|
1488
|
+
if (isNaN(value) || value === Infinity) {
|
|
1489
|
+
m = isNaN(value) ? 1 : 0;
|
|
1490
|
+
e = eMax;
|
|
1491
|
+
} else {
|
|
1492
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
1493
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
1494
|
+
e--;
|
|
1495
|
+
c *= 2;
|
|
1496
|
+
}
|
|
1497
|
+
if (e + eBias >= 1) {
|
|
1498
|
+
value += rt / c;
|
|
1499
|
+
} else {
|
|
1500
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
1501
|
+
}
|
|
1502
|
+
if (value * c >= 2) {
|
|
1503
|
+
e++;
|
|
1504
|
+
c /= 2;
|
|
1505
|
+
}
|
|
1506
|
+
if (e + eBias >= eMax) {
|
|
1507
|
+
m = 0;
|
|
1508
|
+
e = eMax;
|
|
1509
|
+
} else if (e + eBias >= 1) {
|
|
1510
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
1511
|
+
e = e + eBias;
|
|
1512
|
+
} else {
|
|
1513
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
1514
|
+
e = 0;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
for (; mLen >= 8; buffer[offset + i3] = m & 255, i3 += d, m /= 256, mLen -= 8) {
|
|
1518
|
+
}
|
|
1519
|
+
e = e << mLen | m;
|
|
1520
|
+
eLen += mLen;
|
|
1521
|
+
for (; eLen > 0; buffer[offset + i3] = e & 255, i3 += d, e /= 256, eLen -= 8) {
|
|
1522
|
+
}
|
|
1523
|
+
buffer[offset + i3 - d] |= s * 128;
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
|
|
1528
|
+
// ../../node_modules/pbf/index.js
|
|
1529
|
+
var require_pbf = __commonJS({
|
|
1530
|
+
"../../node_modules/pbf/index.js"(exports, module) {
|
|
1531
|
+
"use strict";
|
|
1532
|
+
module.exports = Pbf;
|
|
1533
|
+
var ieee754 = require_ieee754();
|
|
1534
|
+
function Pbf(buf) {
|
|
1535
|
+
this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
|
|
1536
|
+
this.pos = 0;
|
|
1537
|
+
this.type = 0;
|
|
1538
|
+
this.length = this.buf.length;
|
|
1539
|
+
}
|
|
1540
|
+
Pbf.Varint = 0;
|
|
1541
|
+
Pbf.Fixed64 = 1;
|
|
1542
|
+
Pbf.Bytes = 2;
|
|
1543
|
+
Pbf.Fixed32 = 5;
|
|
1544
|
+
var SHIFT_LEFT_32 = (1 << 16) * (1 << 16);
|
|
1545
|
+
var SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;
|
|
1546
|
+
var TEXT_DECODER_MIN_LENGTH = 12;
|
|
1547
|
+
var utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf8");
|
|
1548
|
+
Pbf.prototype = {
|
|
1549
|
+
destroy: function() {
|
|
1550
|
+
this.buf = null;
|
|
1551
|
+
},
|
|
1552
|
+
readFields: function(readField, result, end) {
|
|
1553
|
+
end = end || this.length;
|
|
1554
|
+
while (this.pos < end) {
|
|
1555
|
+
var val = this.readVarint(), tag = val >> 3, startPos = this.pos;
|
|
1556
|
+
this.type = val & 7;
|
|
1557
|
+
readField(tag, result, this);
|
|
1558
|
+
if (this.pos === startPos)
|
|
1559
|
+
this.skip(val);
|
|
1560
|
+
}
|
|
1561
|
+
return result;
|
|
1562
|
+
},
|
|
1563
|
+
readMessage: function(readField, result) {
|
|
1564
|
+
return this.readFields(readField, result, this.readVarint() + this.pos);
|
|
1565
|
+
},
|
|
1566
|
+
readFixed32: function() {
|
|
1567
|
+
var val = readUInt32(this.buf, this.pos);
|
|
1568
|
+
this.pos += 4;
|
|
1569
|
+
return val;
|
|
1570
|
+
},
|
|
1571
|
+
readSFixed32: function() {
|
|
1572
|
+
var val = readInt32(this.buf, this.pos);
|
|
1573
|
+
this.pos += 4;
|
|
1574
|
+
return val;
|
|
1575
|
+
},
|
|
1576
|
+
readFixed64: function() {
|
|
1577
|
+
var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
|
|
1578
|
+
this.pos += 8;
|
|
1579
|
+
return val;
|
|
1580
|
+
},
|
|
1581
|
+
readSFixed64: function() {
|
|
1582
|
+
var val = readUInt32(this.buf, this.pos) + readInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
|
|
1583
|
+
this.pos += 8;
|
|
1584
|
+
return val;
|
|
1585
|
+
},
|
|
1586
|
+
readFloat: function() {
|
|
1587
|
+
var val = ieee754.read(this.buf, this.pos, true, 23, 4);
|
|
1588
|
+
this.pos += 4;
|
|
1589
|
+
return val;
|
|
1590
|
+
},
|
|
1591
|
+
readDouble: function() {
|
|
1592
|
+
var val = ieee754.read(this.buf, this.pos, true, 52, 8);
|
|
1593
|
+
this.pos += 8;
|
|
1594
|
+
return val;
|
|
1595
|
+
},
|
|
1596
|
+
readVarint: function(isSigned) {
|
|
1597
|
+
var buf = this.buf, val, b;
|
|
1598
|
+
b = buf[this.pos++];
|
|
1599
|
+
val = b & 127;
|
|
1600
|
+
if (b < 128)
|
|
1601
|
+
return val;
|
|
1602
|
+
b = buf[this.pos++];
|
|
1603
|
+
val |= (b & 127) << 7;
|
|
1604
|
+
if (b < 128)
|
|
1605
|
+
return val;
|
|
1606
|
+
b = buf[this.pos++];
|
|
1607
|
+
val |= (b & 127) << 14;
|
|
1608
|
+
if (b < 128)
|
|
1609
|
+
return val;
|
|
1610
|
+
b = buf[this.pos++];
|
|
1611
|
+
val |= (b & 127) << 21;
|
|
1612
|
+
if (b < 128)
|
|
1613
|
+
return val;
|
|
1614
|
+
b = buf[this.pos];
|
|
1615
|
+
val |= (b & 15) << 28;
|
|
1616
|
+
return readVarintRemainder2(val, isSigned, this);
|
|
1617
|
+
},
|
|
1618
|
+
readVarint64: function() {
|
|
1619
|
+
return this.readVarint(true);
|
|
1620
|
+
},
|
|
1621
|
+
readSVarint: function() {
|
|
1622
|
+
var num = this.readVarint();
|
|
1623
|
+
return num % 2 === 1 ? (num + 1) / -2 : num / 2;
|
|
1624
|
+
},
|
|
1625
|
+
readBoolean: function() {
|
|
1626
|
+
return Boolean(this.readVarint());
|
|
1627
|
+
},
|
|
1628
|
+
readString: function() {
|
|
1629
|
+
var end = this.readVarint() + this.pos;
|
|
1630
|
+
var pos = this.pos;
|
|
1631
|
+
this.pos = end;
|
|
1632
|
+
if (end - pos >= TEXT_DECODER_MIN_LENGTH && utf8TextDecoder) {
|
|
1633
|
+
return readUtf8TextDecoder(this.buf, pos, end);
|
|
1634
|
+
}
|
|
1635
|
+
return readUtf8(this.buf, pos, end);
|
|
1636
|
+
},
|
|
1637
|
+
readBytes: function() {
|
|
1638
|
+
var end = this.readVarint() + this.pos, buffer = this.buf.subarray(this.pos, end);
|
|
1639
|
+
this.pos = end;
|
|
1640
|
+
return buffer;
|
|
1641
|
+
},
|
|
1642
|
+
readPackedVarint: function(arr, isSigned) {
|
|
1643
|
+
if (this.type !== Pbf.Bytes)
|
|
1644
|
+
return arr.push(this.readVarint(isSigned));
|
|
1645
|
+
var end = readPackedEnd(this);
|
|
1646
|
+
arr = arr || [];
|
|
1647
|
+
while (this.pos < end)
|
|
1648
|
+
arr.push(this.readVarint(isSigned));
|
|
1649
|
+
return arr;
|
|
1650
|
+
},
|
|
1651
|
+
readPackedSVarint: function(arr) {
|
|
1652
|
+
if (this.type !== Pbf.Bytes)
|
|
1653
|
+
return arr.push(this.readSVarint());
|
|
1654
|
+
var end = readPackedEnd(this);
|
|
1655
|
+
arr = arr || [];
|
|
1656
|
+
while (this.pos < end)
|
|
1657
|
+
arr.push(this.readSVarint());
|
|
1658
|
+
return arr;
|
|
1659
|
+
},
|
|
1660
|
+
readPackedBoolean: function(arr) {
|
|
1661
|
+
if (this.type !== Pbf.Bytes)
|
|
1662
|
+
return arr.push(this.readBoolean());
|
|
1663
|
+
var end = readPackedEnd(this);
|
|
1664
|
+
arr = arr || [];
|
|
1665
|
+
while (this.pos < end)
|
|
1666
|
+
arr.push(this.readBoolean());
|
|
1667
|
+
return arr;
|
|
1668
|
+
},
|
|
1669
|
+
readPackedFloat: function(arr) {
|
|
1670
|
+
if (this.type !== Pbf.Bytes)
|
|
1671
|
+
return arr.push(this.readFloat());
|
|
1672
|
+
var end = readPackedEnd(this);
|
|
1673
|
+
arr = arr || [];
|
|
1674
|
+
while (this.pos < end)
|
|
1675
|
+
arr.push(this.readFloat());
|
|
1676
|
+
return arr;
|
|
1677
|
+
},
|
|
1678
|
+
readPackedDouble: function(arr) {
|
|
1679
|
+
if (this.type !== Pbf.Bytes)
|
|
1680
|
+
return arr.push(this.readDouble());
|
|
1681
|
+
var end = readPackedEnd(this);
|
|
1682
|
+
arr = arr || [];
|
|
1683
|
+
while (this.pos < end)
|
|
1684
|
+
arr.push(this.readDouble());
|
|
1685
|
+
return arr;
|
|
1686
|
+
},
|
|
1687
|
+
readPackedFixed32: function(arr) {
|
|
1688
|
+
if (this.type !== Pbf.Bytes)
|
|
1689
|
+
return arr.push(this.readFixed32());
|
|
1690
|
+
var end = readPackedEnd(this);
|
|
1691
|
+
arr = arr || [];
|
|
1692
|
+
while (this.pos < end)
|
|
1693
|
+
arr.push(this.readFixed32());
|
|
1694
|
+
return arr;
|
|
1695
|
+
},
|
|
1696
|
+
readPackedSFixed32: function(arr) {
|
|
1697
|
+
if (this.type !== Pbf.Bytes)
|
|
1698
|
+
return arr.push(this.readSFixed32());
|
|
1699
|
+
var end = readPackedEnd(this);
|
|
1700
|
+
arr = arr || [];
|
|
1701
|
+
while (this.pos < end)
|
|
1702
|
+
arr.push(this.readSFixed32());
|
|
1703
|
+
return arr;
|
|
1704
|
+
},
|
|
1705
|
+
readPackedFixed64: function(arr) {
|
|
1706
|
+
if (this.type !== Pbf.Bytes)
|
|
1707
|
+
return arr.push(this.readFixed64());
|
|
1708
|
+
var end = readPackedEnd(this);
|
|
1709
|
+
arr = arr || [];
|
|
1710
|
+
while (this.pos < end)
|
|
1711
|
+
arr.push(this.readFixed64());
|
|
1712
|
+
return arr;
|
|
1713
|
+
},
|
|
1714
|
+
readPackedSFixed64: function(arr) {
|
|
1715
|
+
if (this.type !== Pbf.Bytes)
|
|
1716
|
+
return arr.push(this.readSFixed64());
|
|
1717
|
+
var end = readPackedEnd(this);
|
|
1718
|
+
arr = arr || [];
|
|
1719
|
+
while (this.pos < end)
|
|
1720
|
+
arr.push(this.readSFixed64());
|
|
1721
|
+
return arr;
|
|
1722
|
+
},
|
|
1723
|
+
skip: function(val) {
|
|
1724
|
+
var type = val & 7;
|
|
1725
|
+
if (type === Pbf.Varint)
|
|
1726
|
+
while (this.buf[this.pos++] > 127) {
|
|
1727
|
+
}
|
|
1728
|
+
else if (type === Pbf.Bytes)
|
|
1729
|
+
this.pos = this.readVarint() + this.pos;
|
|
1730
|
+
else if (type === Pbf.Fixed32)
|
|
1731
|
+
this.pos += 4;
|
|
1732
|
+
else if (type === Pbf.Fixed64)
|
|
1733
|
+
this.pos += 8;
|
|
1734
|
+
else
|
|
1735
|
+
throw new Error("Unimplemented type: " + type);
|
|
1736
|
+
},
|
|
1737
|
+
writeTag: function(tag, type) {
|
|
1738
|
+
this.writeVarint(tag << 3 | type);
|
|
1739
|
+
},
|
|
1740
|
+
realloc: function(min) {
|
|
1741
|
+
var length2 = this.length || 16;
|
|
1742
|
+
while (length2 < this.pos + min)
|
|
1743
|
+
length2 *= 2;
|
|
1744
|
+
if (length2 !== this.length) {
|
|
1745
|
+
var buf = new Uint8Array(length2);
|
|
1746
|
+
buf.set(this.buf);
|
|
1747
|
+
this.buf = buf;
|
|
1748
|
+
this.length = length2;
|
|
1749
|
+
}
|
|
1750
|
+
},
|
|
1751
|
+
finish: function() {
|
|
1752
|
+
this.length = this.pos;
|
|
1753
|
+
this.pos = 0;
|
|
1754
|
+
return this.buf.subarray(0, this.length);
|
|
1755
|
+
},
|
|
1756
|
+
writeFixed32: function(val) {
|
|
1757
|
+
this.realloc(4);
|
|
1758
|
+
writeInt32(this.buf, val, this.pos);
|
|
1759
|
+
this.pos += 4;
|
|
1760
|
+
},
|
|
1761
|
+
writeSFixed32: function(val) {
|
|
1762
|
+
this.realloc(4);
|
|
1763
|
+
writeInt32(this.buf, val, this.pos);
|
|
1764
|
+
this.pos += 4;
|
|
1765
|
+
},
|
|
1766
|
+
writeFixed64: function(val) {
|
|
1767
|
+
this.realloc(8);
|
|
1768
|
+
writeInt32(this.buf, val & -1, this.pos);
|
|
1769
|
+
writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
|
|
1770
|
+
this.pos += 8;
|
|
1771
|
+
},
|
|
1772
|
+
writeSFixed64: function(val) {
|
|
1773
|
+
this.realloc(8);
|
|
1774
|
+
writeInt32(this.buf, val & -1, this.pos);
|
|
1775
|
+
writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
|
|
1776
|
+
this.pos += 8;
|
|
1777
|
+
},
|
|
1778
|
+
writeVarint: function(val) {
|
|
1779
|
+
val = +val || 0;
|
|
1780
|
+
if (val > 268435455 || val < 0) {
|
|
1781
|
+
writeBigVarint(val, this);
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1784
|
+
this.realloc(4);
|
|
1785
|
+
this.buf[this.pos++] = val & 127 | (val > 127 ? 128 : 0);
|
|
1786
|
+
if (val <= 127)
|
|
1787
|
+
return;
|
|
1788
|
+
this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0);
|
|
1789
|
+
if (val <= 127)
|
|
1790
|
+
return;
|
|
1791
|
+
this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0);
|
|
1792
|
+
if (val <= 127)
|
|
1793
|
+
return;
|
|
1794
|
+
this.buf[this.pos++] = val >>> 7 & 127;
|
|
1795
|
+
},
|
|
1796
|
+
writeSVarint: function(val) {
|
|
1797
|
+
this.writeVarint(val < 0 ? -val * 2 - 1 : val * 2);
|
|
1798
|
+
},
|
|
1799
|
+
writeBoolean: function(val) {
|
|
1800
|
+
this.writeVarint(Boolean(val));
|
|
1801
|
+
},
|
|
1802
|
+
writeString: function(str) {
|
|
1803
|
+
str = String(str);
|
|
1804
|
+
this.realloc(str.length * 4);
|
|
1805
|
+
this.pos++;
|
|
1806
|
+
var startPos = this.pos;
|
|
1807
|
+
this.pos = writeUtf8(this.buf, str, this.pos);
|
|
1808
|
+
var len = this.pos - startPos;
|
|
1809
|
+
if (len >= 128)
|
|
1810
|
+
makeRoomForExtraLength(startPos, len, this);
|
|
1811
|
+
this.pos = startPos - 1;
|
|
1812
|
+
this.writeVarint(len);
|
|
1813
|
+
this.pos += len;
|
|
1814
|
+
},
|
|
1815
|
+
writeFloat: function(val) {
|
|
1816
|
+
this.realloc(4);
|
|
1817
|
+
ieee754.write(this.buf, val, this.pos, true, 23, 4);
|
|
1818
|
+
this.pos += 4;
|
|
1819
|
+
},
|
|
1820
|
+
writeDouble: function(val) {
|
|
1821
|
+
this.realloc(8);
|
|
1822
|
+
ieee754.write(this.buf, val, this.pos, true, 52, 8);
|
|
1823
|
+
this.pos += 8;
|
|
1824
|
+
},
|
|
1825
|
+
writeBytes: function(buffer) {
|
|
1826
|
+
var len = buffer.length;
|
|
1827
|
+
this.writeVarint(len);
|
|
1828
|
+
this.realloc(len);
|
|
1829
|
+
for (var i3 = 0; i3 < len; i3++)
|
|
1830
|
+
this.buf[this.pos++] = buffer[i3];
|
|
1831
|
+
},
|
|
1832
|
+
writeRawMessage: function(fn, obj) {
|
|
1833
|
+
this.pos++;
|
|
1834
|
+
var startPos = this.pos;
|
|
1835
|
+
fn(obj, this);
|
|
1836
|
+
var len = this.pos - startPos;
|
|
1837
|
+
if (len >= 128)
|
|
1838
|
+
makeRoomForExtraLength(startPos, len, this);
|
|
1839
|
+
this.pos = startPos - 1;
|
|
1840
|
+
this.writeVarint(len);
|
|
1841
|
+
this.pos += len;
|
|
1842
|
+
},
|
|
1843
|
+
writeMessage: function(tag, fn, obj) {
|
|
1844
|
+
this.writeTag(tag, Pbf.Bytes);
|
|
1845
|
+
this.writeRawMessage(fn, obj);
|
|
1846
|
+
},
|
|
1847
|
+
writePackedVarint: function(tag, arr) {
|
|
1848
|
+
if (arr.length)
|
|
1849
|
+
this.writeMessage(tag, writePackedVarint, arr);
|
|
1850
|
+
},
|
|
1851
|
+
writePackedSVarint: function(tag, arr) {
|
|
1852
|
+
if (arr.length)
|
|
1853
|
+
this.writeMessage(tag, writePackedSVarint, arr);
|
|
1854
|
+
},
|
|
1855
|
+
writePackedBoolean: function(tag, arr) {
|
|
1856
|
+
if (arr.length)
|
|
1857
|
+
this.writeMessage(tag, writePackedBoolean, arr);
|
|
1858
|
+
},
|
|
1859
|
+
writePackedFloat: function(tag, arr) {
|
|
1860
|
+
if (arr.length)
|
|
1861
|
+
this.writeMessage(tag, writePackedFloat, arr);
|
|
1862
|
+
},
|
|
1863
|
+
writePackedDouble: function(tag, arr) {
|
|
1864
|
+
if (arr.length)
|
|
1865
|
+
this.writeMessage(tag, writePackedDouble, arr);
|
|
1866
|
+
},
|
|
1867
|
+
writePackedFixed32: function(tag, arr) {
|
|
1868
|
+
if (arr.length)
|
|
1869
|
+
this.writeMessage(tag, writePackedFixed32, arr);
|
|
1870
|
+
},
|
|
1871
|
+
writePackedSFixed32: function(tag, arr) {
|
|
1872
|
+
if (arr.length)
|
|
1873
|
+
this.writeMessage(tag, writePackedSFixed32, arr);
|
|
1874
|
+
},
|
|
1875
|
+
writePackedFixed64: function(tag, arr) {
|
|
1876
|
+
if (arr.length)
|
|
1877
|
+
this.writeMessage(tag, writePackedFixed64, arr);
|
|
1878
|
+
},
|
|
1879
|
+
writePackedSFixed64: function(tag, arr) {
|
|
1880
|
+
if (arr.length)
|
|
1881
|
+
this.writeMessage(tag, writePackedSFixed64, arr);
|
|
1882
|
+
},
|
|
1883
|
+
writeBytesField: function(tag, buffer) {
|
|
1884
|
+
this.writeTag(tag, Pbf.Bytes);
|
|
1885
|
+
this.writeBytes(buffer);
|
|
1886
|
+
},
|
|
1887
|
+
writeFixed32Field: function(tag, val) {
|
|
1888
|
+
this.writeTag(tag, Pbf.Fixed32);
|
|
1889
|
+
this.writeFixed32(val);
|
|
1890
|
+
},
|
|
1891
|
+
writeSFixed32Field: function(tag, val) {
|
|
1892
|
+
this.writeTag(tag, Pbf.Fixed32);
|
|
1893
|
+
this.writeSFixed32(val);
|
|
1894
|
+
},
|
|
1895
|
+
writeFixed64Field: function(tag, val) {
|
|
1896
|
+
this.writeTag(tag, Pbf.Fixed64);
|
|
1897
|
+
this.writeFixed64(val);
|
|
1898
|
+
},
|
|
1899
|
+
writeSFixed64Field: function(tag, val) {
|
|
1900
|
+
this.writeTag(tag, Pbf.Fixed64);
|
|
1901
|
+
this.writeSFixed64(val);
|
|
1902
|
+
},
|
|
1903
|
+
writeVarintField: function(tag, val) {
|
|
1904
|
+
this.writeTag(tag, Pbf.Varint);
|
|
1905
|
+
this.writeVarint(val);
|
|
1906
|
+
},
|
|
1907
|
+
writeSVarintField: function(tag, val) {
|
|
1908
|
+
this.writeTag(tag, Pbf.Varint);
|
|
1909
|
+
this.writeSVarint(val);
|
|
1910
|
+
},
|
|
1911
|
+
writeStringField: function(tag, str) {
|
|
1912
|
+
this.writeTag(tag, Pbf.Bytes);
|
|
1913
|
+
this.writeString(str);
|
|
1914
|
+
},
|
|
1915
|
+
writeFloatField: function(tag, val) {
|
|
1916
|
+
this.writeTag(tag, Pbf.Fixed32);
|
|
1917
|
+
this.writeFloat(val);
|
|
1918
|
+
},
|
|
1919
|
+
writeDoubleField: function(tag, val) {
|
|
1920
|
+
this.writeTag(tag, Pbf.Fixed64);
|
|
1921
|
+
this.writeDouble(val);
|
|
1922
|
+
},
|
|
1923
|
+
writeBooleanField: function(tag, val) {
|
|
1924
|
+
this.writeVarintField(tag, Boolean(val));
|
|
1925
|
+
}
|
|
1926
|
+
};
|
|
1927
|
+
function readVarintRemainder2(l, s, p) {
|
|
1928
|
+
var buf = p.buf, h, b;
|
|
1929
|
+
b = buf[p.pos++];
|
|
1930
|
+
h = (b & 112) >> 4;
|
|
1931
|
+
if (b < 128)
|
|
1932
|
+
return toNum2(l, h, s);
|
|
1933
|
+
b = buf[p.pos++];
|
|
1934
|
+
h |= (b & 127) << 3;
|
|
1935
|
+
if (b < 128)
|
|
1936
|
+
return toNum2(l, h, s);
|
|
1937
|
+
b = buf[p.pos++];
|
|
1938
|
+
h |= (b & 127) << 10;
|
|
1939
|
+
if (b < 128)
|
|
1940
|
+
return toNum2(l, h, s);
|
|
1941
|
+
b = buf[p.pos++];
|
|
1942
|
+
h |= (b & 127) << 17;
|
|
1943
|
+
if (b < 128)
|
|
1944
|
+
return toNum2(l, h, s);
|
|
1945
|
+
b = buf[p.pos++];
|
|
1946
|
+
h |= (b & 127) << 24;
|
|
1947
|
+
if (b < 128)
|
|
1948
|
+
return toNum2(l, h, s);
|
|
1949
|
+
b = buf[p.pos++];
|
|
1950
|
+
h |= (b & 1) << 31;
|
|
1951
|
+
if (b < 128)
|
|
1952
|
+
return toNum2(l, h, s);
|
|
1953
|
+
throw new Error("Expected varint not more than 10 bytes");
|
|
1954
|
+
}
|
|
1955
|
+
function readPackedEnd(pbf) {
|
|
1956
|
+
return pbf.type === Pbf.Bytes ? pbf.readVarint() + pbf.pos : pbf.pos + 1;
|
|
1957
|
+
}
|
|
1958
|
+
function toNum2(low, high, isSigned) {
|
|
1959
|
+
if (isSigned) {
|
|
1960
|
+
return high * 4294967296 + (low >>> 0);
|
|
1961
|
+
}
|
|
1962
|
+
return (high >>> 0) * 4294967296 + (low >>> 0);
|
|
1963
|
+
}
|
|
1964
|
+
function writeBigVarint(val, pbf) {
|
|
1965
|
+
var low, high;
|
|
1966
|
+
if (val >= 0) {
|
|
1967
|
+
low = val % 4294967296 | 0;
|
|
1968
|
+
high = val / 4294967296 | 0;
|
|
1969
|
+
} else {
|
|
1970
|
+
low = ~(-val % 4294967296);
|
|
1971
|
+
high = ~(-val / 4294967296);
|
|
1972
|
+
if (low ^ 4294967295) {
|
|
1973
|
+
low = low + 1 | 0;
|
|
1974
|
+
} else {
|
|
1975
|
+
low = 0;
|
|
1976
|
+
high = high + 1 | 0;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
if (val >= 18446744073709552e3 || val < -18446744073709552e3) {
|
|
1980
|
+
throw new Error("Given varint doesn't fit into 10 bytes");
|
|
1981
|
+
}
|
|
1982
|
+
pbf.realloc(10);
|
|
1983
|
+
writeBigVarintLow(low, high, pbf);
|
|
1984
|
+
writeBigVarintHigh(high, pbf);
|
|
1985
|
+
}
|
|
1986
|
+
function writeBigVarintLow(low, high, pbf) {
|
|
1987
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1988
|
+
low >>>= 7;
|
|
1989
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1990
|
+
low >>>= 7;
|
|
1991
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1992
|
+
low >>>= 7;
|
|
1993
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1994
|
+
low >>>= 7;
|
|
1995
|
+
pbf.buf[pbf.pos] = low & 127;
|
|
1996
|
+
}
|
|
1997
|
+
function writeBigVarintHigh(high, pbf) {
|
|
1998
|
+
var lsb = (high & 7) << 4;
|
|
1999
|
+
pbf.buf[pbf.pos++] |= lsb | ((high >>>= 3) ? 128 : 0);
|
|
2000
|
+
if (!high)
|
|
2001
|
+
return;
|
|
2002
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
2003
|
+
if (!high)
|
|
2004
|
+
return;
|
|
2005
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
2006
|
+
if (!high)
|
|
2007
|
+
return;
|
|
2008
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
2009
|
+
if (!high)
|
|
2010
|
+
return;
|
|
2011
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
2012
|
+
if (!high)
|
|
2013
|
+
return;
|
|
2014
|
+
pbf.buf[pbf.pos++] = high & 127;
|
|
2015
|
+
}
|
|
2016
|
+
function makeRoomForExtraLength(startPos, len, pbf) {
|
|
2017
|
+
var extraLen = len <= 16383 ? 1 : len <= 2097151 ? 2 : len <= 268435455 ? 3 : Math.floor(Math.log(len) / (Math.LN2 * 7));
|
|
2018
|
+
pbf.realloc(extraLen);
|
|
2019
|
+
for (var i3 = pbf.pos - 1; i3 >= startPos; i3--)
|
|
2020
|
+
pbf.buf[i3 + extraLen] = pbf.buf[i3];
|
|
2021
|
+
}
|
|
2022
|
+
function writePackedVarint(arr, pbf) {
|
|
2023
|
+
for (var i3 = 0; i3 < arr.length; i3++)
|
|
2024
|
+
pbf.writeVarint(arr[i3]);
|
|
2025
|
+
}
|
|
2026
|
+
function writePackedSVarint(arr, pbf) {
|
|
2027
|
+
for (var i3 = 0; i3 < arr.length; i3++)
|
|
2028
|
+
pbf.writeSVarint(arr[i3]);
|
|
2029
|
+
}
|
|
2030
|
+
function writePackedFloat(arr, pbf) {
|
|
2031
|
+
for (var i3 = 0; i3 < arr.length; i3++)
|
|
2032
|
+
pbf.writeFloat(arr[i3]);
|
|
2033
|
+
}
|
|
2034
|
+
function writePackedDouble(arr, pbf) {
|
|
2035
|
+
for (var i3 = 0; i3 < arr.length; i3++)
|
|
2036
|
+
pbf.writeDouble(arr[i3]);
|
|
2037
|
+
}
|
|
2038
|
+
function writePackedBoolean(arr, pbf) {
|
|
2039
|
+
for (var i3 = 0; i3 < arr.length; i3++)
|
|
2040
|
+
pbf.writeBoolean(arr[i3]);
|
|
2041
|
+
}
|
|
2042
|
+
function writePackedFixed32(arr, pbf) {
|
|
2043
|
+
for (var i3 = 0; i3 < arr.length; i3++)
|
|
2044
|
+
pbf.writeFixed32(arr[i3]);
|
|
2045
|
+
}
|
|
2046
|
+
function writePackedSFixed32(arr, pbf) {
|
|
2047
|
+
for (var i3 = 0; i3 < arr.length; i3++)
|
|
2048
|
+
pbf.writeSFixed32(arr[i3]);
|
|
2049
|
+
}
|
|
2050
|
+
function writePackedFixed64(arr, pbf) {
|
|
2051
|
+
for (var i3 = 0; i3 < arr.length; i3++)
|
|
2052
|
+
pbf.writeFixed64(arr[i3]);
|
|
2053
|
+
}
|
|
2054
|
+
function writePackedSFixed64(arr, pbf) {
|
|
2055
|
+
for (var i3 = 0; i3 < arr.length; i3++)
|
|
2056
|
+
pbf.writeSFixed64(arr[i3]);
|
|
2057
|
+
}
|
|
2058
|
+
function readUInt32(buf, pos) {
|
|
2059
|
+
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216;
|
|
2060
|
+
}
|
|
2061
|
+
function writeInt32(buf, val, pos) {
|
|
2062
|
+
buf[pos] = val;
|
|
2063
|
+
buf[pos + 1] = val >>> 8;
|
|
2064
|
+
buf[pos + 2] = val >>> 16;
|
|
2065
|
+
buf[pos + 3] = val >>> 24;
|
|
2066
|
+
}
|
|
2067
|
+
function readInt32(buf, pos) {
|
|
2068
|
+
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + (buf[pos + 3] << 24);
|
|
2069
|
+
}
|
|
2070
|
+
function readUtf8(buf, pos, end) {
|
|
2071
|
+
var str = "";
|
|
2072
|
+
var i3 = pos;
|
|
2073
|
+
while (i3 < end) {
|
|
2074
|
+
var b0 = buf[i3];
|
|
2075
|
+
var c = null;
|
|
2076
|
+
var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
|
|
2077
|
+
if (i3 + bytesPerSequence > end)
|
|
2078
|
+
break;
|
|
2079
|
+
var b1, b2, b3;
|
|
2080
|
+
if (bytesPerSequence === 1) {
|
|
2081
|
+
if (b0 < 128) {
|
|
2082
|
+
c = b0;
|
|
2083
|
+
}
|
|
2084
|
+
} else if (bytesPerSequence === 2) {
|
|
2085
|
+
b1 = buf[i3 + 1];
|
|
2086
|
+
if ((b1 & 192) === 128) {
|
|
2087
|
+
c = (b0 & 31) << 6 | b1 & 63;
|
|
2088
|
+
if (c <= 127) {
|
|
2089
|
+
c = null;
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
} else if (bytesPerSequence === 3) {
|
|
2093
|
+
b1 = buf[i3 + 1];
|
|
2094
|
+
b2 = buf[i3 + 2];
|
|
2095
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128) {
|
|
2096
|
+
c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
|
|
2097
|
+
if (c <= 2047 || c >= 55296 && c <= 57343) {
|
|
2098
|
+
c = null;
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
} else if (bytesPerSequence === 4) {
|
|
2102
|
+
b1 = buf[i3 + 1];
|
|
2103
|
+
b2 = buf[i3 + 2];
|
|
2104
|
+
b3 = buf[i3 + 3];
|
|
2105
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
|
|
2106
|
+
c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
|
|
2107
|
+
if (c <= 65535 || c >= 1114112) {
|
|
2108
|
+
c = null;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
if (c === null) {
|
|
2113
|
+
c = 65533;
|
|
2114
|
+
bytesPerSequence = 1;
|
|
2115
|
+
} else if (c > 65535) {
|
|
2116
|
+
c -= 65536;
|
|
2117
|
+
str += String.fromCharCode(c >>> 10 & 1023 | 55296);
|
|
2118
|
+
c = 56320 | c & 1023;
|
|
2119
|
+
}
|
|
2120
|
+
str += String.fromCharCode(c);
|
|
2121
|
+
i3 += bytesPerSequence;
|
|
2122
|
+
}
|
|
2123
|
+
return str;
|
|
2124
|
+
}
|
|
2125
|
+
function readUtf8TextDecoder(buf, pos, end) {
|
|
2126
|
+
return utf8TextDecoder.decode(buf.subarray(pos, end));
|
|
2127
|
+
}
|
|
2128
|
+
function writeUtf8(buf, str, pos) {
|
|
2129
|
+
for (var i3 = 0, c, lead; i3 < str.length; i3++) {
|
|
2130
|
+
c = str.charCodeAt(i3);
|
|
2131
|
+
if (c > 55295 && c < 57344) {
|
|
2132
|
+
if (lead) {
|
|
2133
|
+
if (c < 56320) {
|
|
2134
|
+
buf[pos++] = 239;
|
|
2135
|
+
buf[pos++] = 191;
|
|
2136
|
+
buf[pos++] = 189;
|
|
2137
|
+
lead = c;
|
|
2138
|
+
continue;
|
|
2139
|
+
} else {
|
|
2140
|
+
c = lead - 55296 << 10 | c - 56320 | 65536;
|
|
2141
|
+
lead = null;
|
|
2142
|
+
}
|
|
2143
|
+
} else {
|
|
2144
|
+
if (c > 56319 || i3 + 1 === str.length) {
|
|
2145
|
+
buf[pos++] = 239;
|
|
2146
|
+
buf[pos++] = 191;
|
|
2147
|
+
buf[pos++] = 189;
|
|
2148
|
+
} else {
|
|
2149
|
+
lead = c;
|
|
2150
|
+
}
|
|
2151
|
+
continue;
|
|
2152
|
+
}
|
|
2153
|
+
} else if (lead) {
|
|
2154
|
+
buf[pos++] = 239;
|
|
2155
|
+
buf[pos++] = 191;
|
|
2156
|
+
buf[pos++] = 189;
|
|
2157
|
+
lead = null;
|
|
2158
|
+
}
|
|
2159
|
+
if (c < 128) {
|
|
2160
|
+
buf[pos++] = c;
|
|
2161
|
+
} else {
|
|
2162
|
+
if (c < 2048) {
|
|
2163
|
+
buf[pos++] = c >> 6 | 192;
|
|
2164
|
+
} else {
|
|
2165
|
+
if (c < 65536) {
|
|
2166
|
+
buf[pos++] = c >> 12 | 224;
|
|
2167
|
+
} else {
|
|
2168
|
+
buf[pos++] = c >> 18 | 240;
|
|
2169
|
+
buf[pos++] = c >> 12 & 63 | 128;
|
|
2170
|
+
}
|
|
2171
|
+
buf[pos++] = c >> 6 & 63 | 128;
|
|
2172
|
+
}
|
|
2173
|
+
buf[pos++] = c & 63 | 128;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
return pos;
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
});
|
|
2180
|
+
|
|
2181
|
+
// ../mvt/src/helpers/mapbox-util-functions.ts
|
|
2182
|
+
function classifyRings(rings) {
|
|
2183
|
+
const len = rings.length;
|
|
2184
|
+
if (len <= 1)
|
|
2185
|
+
return [rings];
|
|
2186
|
+
const polygons = [];
|
|
2187
|
+
let polygon;
|
|
2188
|
+
let ccw;
|
|
2189
|
+
for (let i3 = 0; i3 < len; i3++) {
|
|
2190
|
+
const area2 = signedArea(rings[i3]);
|
|
2191
|
+
if (area2 === 0)
|
|
2192
|
+
continue;
|
|
2193
|
+
if (ccw === void 0)
|
|
2194
|
+
ccw = area2 < 0;
|
|
2195
|
+
if (ccw === area2 < 0) {
|
|
2196
|
+
if (polygon)
|
|
2197
|
+
polygons.push(polygon);
|
|
2198
|
+
polygon = [rings[i3]];
|
|
2199
|
+
} else if (polygon)
|
|
2200
|
+
polygon.push(rings[i3]);
|
|
2201
|
+
}
|
|
2202
|
+
if (polygon)
|
|
2203
|
+
polygons.push(polygon);
|
|
2204
|
+
return polygons;
|
|
2205
|
+
}
|
|
2206
|
+
function signedArea(ring) {
|
|
2207
|
+
let sum = 0;
|
|
2208
|
+
for (let i3 = 0, j = ring.length - 1, p1, p2; i3 < ring.length; j = i3++) {
|
|
2209
|
+
p1 = ring[i3];
|
|
2210
|
+
p2 = ring[j];
|
|
2211
|
+
sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
|
|
2212
|
+
}
|
|
2213
|
+
return sum;
|
|
2214
|
+
}
|
|
2215
|
+
function readFeature(tag, feature, pbf) {
|
|
2216
|
+
if (feature && pbf) {
|
|
2217
|
+
if (tag === 1)
|
|
2218
|
+
feature.id = pbf.readVarint();
|
|
2219
|
+
else if (tag === 2)
|
|
2220
|
+
readTag(pbf, feature);
|
|
2221
|
+
else if (tag === 3)
|
|
2222
|
+
feature.type = pbf.readVarint();
|
|
2223
|
+
else if (tag === 4)
|
|
2224
|
+
feature._geometry = pbf.pos;
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
function readTag(pbf, feature) {
|
|
2228
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
2229
|
+
while (pbf.pos < end) {
|
|
2230
|
+
const key = feature._keys[pbf.readVarint()];
|
|
2231
|
+
const value = feature._values[pbf.readVarint()];
|
|
2232
|
+
feature.properties[key] = value;
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
var init_mapbox_util_functions = __esm({
|
|
2236
|
+
"../mvt/src/helpers/mapbox-util-functions.ts"() {
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2239
|
+
|
|
2240
|
+
// ../mvt/src/lib/mapbox-vector-tile/vector-tile-feature.ts
|
|
2241
|
+
var VectorTileFeature;
|
|
2242
|
+
var init_vector_tile_feature = __esm({
|
|
2243
|
+
"../mvt/src/lib/mapbox-vector-tile/vector-tile-feature.ts"() {
|
|
2244
|
+
init_mapbox_util_functions();
|
|
2245
|
+
VectorTileFeature = class {
|
|
2246
|
+
static get types() {
|
|
2247
|
+
return ["Unknown", "Point", "LineString", "Polygon"];
|
|
2248
|
+
}
|
|
2249
|
+
constructor(pbf, end, extent, keys, values) {
|
|
2250
|
+
this.properties = {};
|
|
2251
|
+
this.extent = extent;
|
|
2252
|
+
this.type = 0;
|
|
2253
|
+
this.id = null;
|
|
2254
|
+
this._pbf = pbf;
|
|
2255
|
+
this._geometry = -1;
|
|
2256
|
+
this._keys = keys;
|
|
2257
|
+
this._values = values;
|
|
2258
|
+
pbf.readFields(readFeature, this, end);
|
|
2259
|
+
}
|
|
2260
|
+
loadGeometry() {
|
|
2261
|
+
const pbf = this._pbf;
|
|
2262
|
+
pbf.pos = this._geometry;
|
|
2263
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
2264
|
+
let cmd2 = 1;
|
|
2265
|
+
let length2 = 0;
|
|
2266
|
+
let x3 = 0;
|
|
2267
|
+
let y2 = 0;
|
|
2268
|
+
const lines = [];
|
|
2269
|
+
let line;
|
|
2270
|
+
while (pbf.pos < end) {
|
|
2271
|
+
if (length2 <= 0) {
|
|
2272
|
+
const cmdLen2 = pbf.readVarint();
|
|
2273
|
+
cmd2 = cmdLen2 & 7;
|
|
2274
|
+
length2 = cmdLen2 >> 3;
|
|
2275
|
+
}
|
|
2276
|
+
length2--;
|
|
2277
|
+
if (cmd2 === 1 || cmd2 === 2) {
|
|
2278
|
+
x3 += pbf.readSVarint();
|
|
2279
|
+
y2 += pbf.readSVarint();
|
|
2280
|
+
if (cmd2 === 1) {
|
|
2281
|
+
if (line)
|
|
2282
|
+
lines.push(line);
|
|
2283
|
+
line = [];
|
|
2284
|
+
}
|
|
2285
|
+
if (line)
|
|
2286
|
+
line.push([x3, y2]);
|
|
2287
|
+
} else if (cmd2 === 7) {
|
|
2288
|
+
if (line) {
|
|
2289
|
+
line.push(line[0].slice());
|
|
2290
|
+
}
|
|
2291
|
+
} else {
|
|
2292
|
+
throw new Error(`unknown command ${cmd2}`);
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
if (line)
|
|
2296
|
+
lines.push(line);
|
|
2297
|
+
return lines;
|
|
2298
|
+
}
|
|
2299
|
+
bbox() {
|
|
2300
|
+
const pbf = this._pbf;
|
|
2301
|
+
pbf.pos = this._geometry;
|
|
2302
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
2303
|
+
let cmd2 = 1;
|
|
2304
|
+
let length2 = 0;
|
|
2305
|
+
let x3 = 0;
|
|
2306
|
+
let y2 = 0;
|
|
2307
|
+
let x1 = Infinity;
|
|
2308
|
+
let x22 = -Infinity;
|
|
2309
|
+
let y1 = Infinity;
|
|
2310
|
+
let y22 = -Infinity;
|
|
2311
|
+
while (pbf.pos < end) {
|
|
2312
|
+
if (length2 <= 0) {
|
|
2313
|
+
const cmdLen2 = pbf.readVarint();
|
|
2314
|
+
cmd2 = cmdLen2 & 7;
|
|
2315
|
+
length2 = cmdLen2 >> 3;
|
|
2316
|
+
}
|
|
2317
|
+
length2--;
|
|
2318
|
+
if (cmd2 === 1 || cmd2 === 2) {
|
|
2319
|
+
x3 += pbf.readSVarint();
|
|
2320
|
+
y2 += pbf.readSVarint();
|
|
2321
|
+
if (x3 < x1)
|
|
2322
|
+
x1 = x3;
|
|
2323
|
+
if (x3 > x22)
|
|
2324
|
+
x22 = x3;
|
|
2325
|
+
if (y2 < y1)
|
|
2326
|
+
y1 = y2;
|
|
2327
|
+
if (y2 > y22)
|
|
2328
|
+
y22 = y2;
|
|
2329
|
+
} else if (cmd2 !== 7) {
|
|
2330
|
+
throw new Error(`unknown command ${cmd2}`);
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
return [x1, y1, x22, y22];
|
|
2334
|
+
}
|
|
2335
|
+
_toGeoJSON(transform) {
|
|
2336
|
+
let coords = this.loadGeometry();
|
|
2337
|
+
let type = VectorTileFeature.types[this.type];
|
|
2338
|
+
let i3;
|
|
2339
|
+
let j;
|
|
2340
|
+
switch (this.type) {
|
|
2341
|
+
case 1:
|
|
2342
|
+
const points = [];
|
|
2343
|
+
for (i3 = 0; i3 < coords.length; i3++) {
|
|
2344
|
+
points[i3] = coords[i3][0];
|
|
2345
|
+
}
|
|
2346
|
+
coords = points;
|
|
2347
|
+
transform(coords, this);
|
|
2348
|
+
break;
|
|
2349
|
+
case 2:
|
|
2350
|
+
for (i3 = 0; i3 < coords.length; i3++) {
|
|
2351
|
+
transform(coords[i3], this);
|
|
2352
|
+
}
|
|
2353
|
+
break;
|
|
2354
|
+
case 3:
|
|
2355
|
+
coords = classifyRings(coords);
|
|
2356
|
+
for (i3 = 0; i3 < coords.length; i3++) {
|
|
2357
|
+
for (j = 0; j < coords[i3].length; j++) {
|
|
2358
|
+
transform(coords[i3][j], this);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
break;
|
|
2362
|
+
}
|
|
2363
|
+
if (coords.length === 1) {
|
|
2364
|
+
coords = coords[0];
|
|
2365
|
+
} else {
|
|
2366
|
+
type = `Multi${type}`;
|
|
2367
|
+
}
|
|
2368
|
+
const result = {
|
|
2369
|
+
type: "Feature",
|
|
2370
|
+
geometry: {
|
|
2371
|
+
type,
|
|
2372
|
+
coordinates: coords
|
|
2373
|
+
},
|
|
2374
|
+
properties: this.properties
|
|
2375
|
+
};
|
|
2376
|
+
if (this.id !== null) {
|
|
2377
|
+
result.id = this.id;
|
|
2378
|
+
}
|
|
2379
|
+
return result;
|
|
2380
|
+
}
|
|
2381
|
+
toGeoJSON(options) {
|
|
2382
|
+
if (typeof options === "function") {
|
|
2383
|
+
return this._toGeoJSON(options);
|
|
2384
|
+
}
|
|
2385
|
+
const { x: x3, y: y2, z } = options;
|
|
2386
|
+
const size = this.extent * Math.pow(2, z);
|
|
2387
|
+
const x0 = this.extent * x3;
|
|
2388
|
+
const y0 = this.extent * y2;
|
|
2389
|
+
function project2(line) {
|
|
2390
|
+
for (let j = 0; j < line.length; j++) {
|
|
2391
|
+
const p = line[j];
|
|
2392
|
+
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
2393
|
+
const y22 = 180 - (p[1] + y0) * 360 / size;
|
|
2394
|
+
p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
return this._toGeoJSON(project2);
|
|
2398
|
+
}
|
|
2399
|
+
};
|
|
2400
|
+
}
|
|
2401
|
+
});
|
|
2402
|
+
|
|
2403
|
+
// ../mvt/src/lib/mapbox-vector-tile/vector-tile-layer.ts
|
|
2404
|
+
function readLayer(tag, layer, pbf) {
|
|
2405
|
+
if (layer && pbf) {
|
|
2406
|
+
if (tag === 15)
|
|
2407
|
+
layer.version = pbf.readVarint();
|
|
2408
|
+
else if (tag === 1)
|
|
2409
|
+
layer.name = pbf.readString();
|
|
2410
|
+
else if (tag === 5)
|
|
2411
|
+
layer.extent = pbf.readVarint();
|
|
2412
|
+
else if (tag === 2)
|
|
2413
|
+
layer._features.push(pbf.pos);
|
|
2414
|
+
else if (tag === 3)
|
|
2415
|
+
layer._keys.push(pbf.readString());
|
|
2416
|
+
else if (tag === 4)
|
|
2417
|
+
layer._values.push(readValueMessage(pbf));
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
function readValueMessage(pbf) {
|
|
2421
|
+
let value = null;
|
|
2422
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
2423
|
+
while (pbf.pos < end) {
|
|
2424
|
+
const tag = pbf.readVarint() >> 3;
|
|
2425
|
+
value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
|
|
2426
|
+
}
|
|
2427
|
+
return value;
|
|
2428
|
+
}
|
|
2429
|
+
var VectorTileLayer;
|
|
2430
|
+
var init_vector_tile_layer = __esm({
|
|
2431
|
+
"../mvt/src/lib/mapbox-vector-tile/vector-tile-layer.ts"() {
|
|
2432
|
+
init_vector_tile_feature();
|
|
2433
|
+
VectorTileLayer = class {
|
|
2434
|
+
constructor(pbf, end) {
|
|
2435
|
+
this.version = 1;
|
|
2436
|
+
this.name = "";
|
|
2437
|
+
this.extent = 4096;
|
|
2438
|
+
this.length = 0;
|
|
2439
|
+
this._pbf = pbf;
|
|
2440
|
+
this._keys = [];
|
|
2441
|
+
this._values = [];
|
|
2442
|
+
this._features = [];
|
|
2443
|
+
pbf.readFields(readLayer, this, end);
|
|
2444
|
+
this.length = this._features.length;
|
|
2445
|
+
}
|
|
2446
|
+
feature(i3) {
|
|
2447
|
+
if (i3 < 0 || i3 >= this._features.length) {
|
|
2448
|
+
throw new Error("feature index out of bounds");
|
|
2449
|
+
}
|
|
2450
|
+
this._pbf.pos = this._features[i3];
|
|
2451
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
2452
|
+
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
|
|
2453
|
+
}
|
|
2454
|
+
};
|
|
2455
|
+
}
|
|
2456
|
+
});
|
|
2457
|
+
|
|
2458
|
+
// ../mvt/src/lib/mapbox-vector-tile/vector-tile.ts
|
|
2459
|
+
function readTile(tag, layers, pbf) {
|
|
2460
|
+
if (tag === 3) {
|
|
2461
|
+
if (pbf) {
|
|
2462
|
+
const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
|
|
2463
|
+
if (layer.length && layers) {
|
|
2464
|
+
layers[layer.name] = layer;
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
var VectorTile;
|
|
2470
|
+
var init_vector_tile = __esm({
|
|
2471
|
+
"../mvt/src/lib/mapbox-vector-tile/vector-tile.ts"() {
|
|
2472
|
+
init_vector_tile_layer();
|
|
2473
|
+
VectorTile = class {
|
|
2474
|
+
constructor(pbf, end) {
|
|
2475
|
+
this.layers = pbf.readFields(readTile, {}, end);
|
|
2476
|
+
}
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
});
|
|
2480
|
+
|
|
2481
|
+
// ../mvt/src/helpers/binary-util-functions.ts
|
|
2482
|
+
function classifyRings2(geom) {
|
|
2483
|
+
const len = geom.indices.length;
|
|
2484
|
+
const type = "Polygon";
|
|
2485
|
+
if (len <= 1) {
|
|
2486
|
+
return {
|
|
2487
|
+
type,
|
|
2488
|
+
data: geom.data,
|
|
2489
|
+
areas: [[getPolygonSignedArea(geom.data)]],
|
|
2490
|
+
indices: [geom.indices]
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2493
|
+
const areas = [];
|
|
2494
|
+
const polygons = [];
|
|
2495
|
+
let ringAreas = [];
|
|
2496
|
+
let polygon = [];
|
|
2497
|
+
let ccw;
|
|
2498
|
+
let offset = 0;
|
|
2499
|
+
for (let endIndex, i3 = 0, startIndex; i3 < len; i3++) {
|
|
2500
|
+
startIndex = geom.indices[i3] - offset;
|
|
2501
|
+
endIndex = geom.indices[i3 + 1] - offset || geom.data.length;
|
|
2502
|
+
const shape = geom.data.slice(startIndex, endIndex);
|
|
2503
|
+
const area2 = getPolygonSignedArea(shape);
|
|
2504
|
+
if (area2 === 0) {
|
|
2505
|
+
const before = geom.data.slice(0, startIndex);
|
|
2506
|
+
const after = geom.data.slice(endIndex);
|
|
2507
|
+
geom.data = before.concat(after);
|
|
2508
|
+
offset += endIndex - startIndex;
|
|
2509
|
+
continue;
|
|
2510
|
+
}
|
|
2511
|
+
if (ccw === void 0)
|
|
2512
|
+
ccw = area2 < 0;
|
|
2513
|
+
if (ccw === area2 < 0) {
|
|
2514
|
+
if (polygon.length) {
|
|
2515
|
+
areas.push(ringAreas);
|
|
2516
|
+
polygons.push(polygon);
|
|
2517
|
+
}
|
|
2518
|
+
polygon = [startIndex];
|
|
2519
|
+
ringAreas = [area2];
|
|
2520
|
+
} else {
|
|
2521
|
+
ringAreas.push(area2);
|
|
2522
|
+
polygon.push(startIndex);
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
if (ringAreas)
|
|
2526
|
+
areas.push(ringAreas);
|
|
2527
|
+
if (polygon.length)
|
|
2528
|
+
polygons.push(polygon);
|
|
2529
|
+
return { type, areas, indices: polygons, data: geom.data };
|
|
2530
|
+
}
|
|
2531
|
+
function project(data, x0, y0, size) {
|
|
2532
|
+
for (let j = 0, jl = data.length; j < jl; j += 2) {
|
|
2533
|
+
data[j] = (data[j] + x0) * 360 / size - 180;
|
|
2534
|
+
const y2 = 180 - (data[j + 1] + y0) * 360 / size;
|
|
2535
|
+
data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
function readFeature2(tag, feature, pbf) {
|
|
2539
|
+
if (feature && pbf) {
|
|
2540
|
+
if (tag === 1)
|
|
2541
|
+
feature.id = pbf.readVarint();
|
|
2542
|
+
else if (tag === 2)
|
|
2543
|
+
readTag2(pbf, feature);
|
|
2544
|
+
else if (tag === 3)
|
|
2545
|
+
feature.type = pbf.readVarint();
|
|
2546
|
+
else if (tag === 4)
|
|
2547
|
+
feature._geometry = pbf.pos;
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
function readTag2(pbf, feature) {
|
|
2551
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
2552
|
+
while (pbf.pos < end) {
|
|
2553
|
+
const key = feature._keys[pbf.readVarint()];
|
|
2554
|
+
const value = feature._values[pbf.readVarint()];
|
|
2555
|
+
feature.properties[key] = value;
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
var init_binary_util_functions = __esm({
|
|
2559
|
+
"../mvt/src/helpers/binary-util-functions.ts"() {
|
|
2560
|
+
init_esm();
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
|
|
2564
|
+
// ../mvt/src/lib/binary-vector-tile/vector-tile-feature.ts
|
|
2565
|
+
var endPos, cmd, cmdLen, length, x, y, i, VectorTileFeature2;
|
|
2566
|
+
var init_vector_tile_feature2 = __esm({
|
|
2567
|
+
"../mvt/src/lib/binary-vector-tile/vector-tile-feature.ts"() {
|
|
2568
|
+
init_binary_util_functions();
|
|
2569
|
+
VectorTileFeature2 = class {
|
|
2570
|
+
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
2571
|
+
this.properties = {};
|
|
2572
|
+
this.extent = extent;
|
|
2573
|
+
this.type = 0;
|
|
2574
|
+
this.id = null;
|
|
2575
|
+
this._pbf = pbf;
|
|
2576
|
+
this._geometry = -1;
|
|
2577
|
+
this._keys = keys;
|
|
2578
|
+
this._values = values;
|
|
2579
|
+
this._geometryInfo = geometryInfo;
|
|
2580
|
+
pbf.readFields(readFeature2, this, end);
|
|
2581
|
+
}
|
|
2582
|
+
loadGeometry() {
|
|
2583
|
+
const pbf = this._pbf;
|
|
2584
|
+
pbf.pos = this._geometry;
|
|
2585
|
+
endPos = pbf.readVarint() + pbf.pos;
|
|
2586
|
+
cmd = 1;
|
|
2587
|
+
length = 0;
|
|
2588
|
+
x = 0;
|
|
2589
|
+
y = 0;
|
|
2590
|
+
i = 0;
|
|
2591
|
+
const indices = [];
|
|
2592
|
+
const data = [];
|
|
2593
|
+
while (pbf.pos < endPos) {
|
|
2594
|
+
if (length <= 0) {
|
|
2595
|
+
cmdLen = pbf.readVarint();
|
|
2596
|
+
cmd = cmdLen & 7;
|
|
2597
|
+
length = cmdLen >> 3;
|
|
2598
|
+
}
|
|
2599
|
+
length--;
|
|
2600
|
+
if (cmd === 1 || cmd === 2) {
|
|
2601
|
+
x += pbf.readSVarint();
|
|
2602
|
+
y += pbf.readSVarint();
|
|
2603
|
+
if (cmd === 1) {
|
|
2604
|
+
indices.push(i);
|
|
2605
|
+
}
|
|
2606
|
+
data.push(x, y);
|
|
2607
|
+
i += 2;
|
|
2608
|
+
} else if (cmd === 7) {
|
|
2609
|
+
if (i > 0) {
|
|
2610
|
+
const start = indices[indices.length - 1];
|
|
2611
|
+
data.push(data[start], data[start + 1]);
|
|
2612
|
+
i += 2;
|
|
2613
|
+
}
|
|
2614
|
+
} else {
|
|
2615
|
+
throw new Error(`unknown command ${cmd}`);
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
return { data, indices };
|
|
2619
|
+
}
|
|
2620
|
+
_toBinaryCoordinates(transform) {
|
|
2621
|
+
const geom = this.loadGeometry();
|
|
2622
|
+
let geometry;
|
|
2623
|
+
transform(geom.data, this);
|
|
2624
|
+
const coordLength = 2;
|
|
2625
|
+
switch (this.type) {
|
|
2626
|
+
case 1:
|
|
2627
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
2628
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
2629
|
+
geometry = { type: "Point", ...geom };
|
|
2630
|
+
break;
|
|
2631
|
+
case 2:
|
|
2632
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
2633
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
2634
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
2635
|
+
geometry = { type: "LineString", ...geom };
|
|
2636
|
+
break;
|
|
2637
|
+
case 3:
|
|
2638
|
+
geometry = classifyRings2(geom);
|
|
2639
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
2640
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
2641
|
+
for (const indices of geometry.indices) {
|
|
2642
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
2643
|
+
}
|
|
2644
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
2645
|
+
break;
|
|
2646
|
+
default:
|
|
2647
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
2648
|
+
}
|
|
2649
|
+
const result = { type: "Feature", geometry, properties: this.properties };
|
|
2650
|
+
if (this.id !== null) {
|
|
2651
|
+
result.id = this.id;
|
|
2652
|
+
}
|
|
2653
|
+
return result;
|
|
2654
|
+
}
|
|
2655
|
+
toBinaryCoordinates(options) {
|
|
2656
|
+
if (typeof options === "function") {
|
|
2657
|
+
return this._toBinaryCoordinates(options);
|
|
2658
|
+
}
|
|
2659
|
+
const { x: x3, y: y2, z } = options;
|
|
2660
|
+
const size = this.extent * Math.pow(2, z);
|
|
2661
|
+
const x0 = this.extent * x3;
|
|
2662
|
+
const y0 = this.extent * y2;
|
|
2663
|
+
return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
|
|
2664
|
+
}
|
|
2665
|
+
};
|
|
2666
|
+
}
|
|
2667
|
+
});
|
|
2668
|
+
|
|
2669
|
+
// ../mvt/src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
2670
|
+
function readLayer2(tag, layer, pbf) {
|
|
2671
|
+
if (layer && pbf) {
|
|
2672
|
+
if (tag === 15)
|
|
2673
|
+
layer.version = pbf.readVarint();
|
|
2674
|
+
else if (tag === 1)
|
|
2675
|
+
layer.name = pbf.readString();
|
|
2676
|
+
else if (tag === 5)
|
|
2677
|
+
layer.extent = pbf.readVarint();
|
|
2678
|
+
else if (tag === 2)
|
|
2679
|
+
layer._features.push(pbf.pos);
|
|
2680
|
+
else if (tag === 3)
|
|
2681
|
+
layer._keys.push(pbf.readString());
|
|
2682
|
+
else if (tag === 4)
|
|
2683
|
+
layer._values.push(readValueMessage2(pbf));
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
function readValueMessage2(pbf) {
|
|
2687
|
+
let value = null;
|
|
2688
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
2689
|
+
while (pbf.pos < end) {
|
|
2690
|
+
const tag = pbf.readVarint() >> 3;
|
|
2691
|
+
value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
|
|
2692
|
+
}
|
|
2693
|
+
return value;
|
|
2694
|
+
}
|
|
2695
|
+
var VectorTileLayer2;
|
|
2696
|
+
var init_vector_tile_layer2 = __esm({
|
|
2697
|
+
"../mvt/src/lib/binary-vector-tile/vector-tile-layer.ts"() {
|
|
2698
|
+
init_vector_tile_feature2();
|
|
2699
|
+
VectorTileLayer2 = class {
|
|
2700
|
+
constructor(pbf, end) {
|
|
2701
|
+
this.version = 1;
|
|
2702
|
+
this.name = "";
|
|
2703
|
+
this.extent = 4096;
|
|
2704
|
+
this.length = 0;
|
|
2705
|
+
this._pbf = pbf;
|
|
2706
|
+
this._keys = [];
|
|
2707
|
+
this._values = [];
|
|
2708
|
+
this._features = [];
|
|
2709
|
+
pbf.readFields(readLayer2, this, end);
|
|
2710
|
+
this.length = this._features.length;
|
|
2711
|
+
}
|
|
2712
|
+
feature(i3, geometryInfo) {
|
|
2713
|
+
if (i3 < 0 || i3 >= this._features.length) {
|
|
2714
|
+
throw new Error("feature index out of bounds");
|
|
2715
|
+
}
|
|
2716
|
+
this._pbf.pos = this._features[i3];
|
|
2717
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
2718
|
+
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
2719
|
+
}
|
|
2720
|
+
};
|
|
2721
|
+
}
|
|
2722
|
+
});
|
|
2723
|
+
|
|
2724
|
+
// ../mvt/src/lib/binary-vector-tile/vector-tile.ts
|
|
2725
|
+
function readTile2(tag, layers, pbf) {
|
|
2726
|
+
if (tag === 3) {
|
|
2727
|
+
if (pbf) {
|
|
2728
|
+
const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
|
|
2729
|
+
if (layer.length && layers) {
|
|
2730
|
+
layers[layer.name] = layer;
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
var VectorTile2;
|
|
2736
|
+
var init_vector_tile2 = __esm({
|
|
2737
|
+
"../mvt/src/lib/binary-vector-tile/vector-tile.ts"() {
|
|
2738
|
+
init_vector_tile_layer2();
|
|
2739
|
+
VectorTile2 = class {
|
|
2740
|
+
constructor(pbf, end) {
|
|
2741
|
+
this.layers = pbf.readFields(readTile2, {}, end);
|
|
2742
|
+
}
|
|
2743
|
+
};
|
|
2744
|
+
}
|
|
2745
|
+
});
|
|
2746
|
+
|
|
2747
|
+
// ../mvt/src/lib/parse-mvt.ts
|
|
2748
|
+
function parseMVT(arrayBuffer, options) {
|
|
2749
|
+
const mvtOptions = normalizeOptions(options);
|
|
2750
|
+
const shape = options?.gis?.format || options?.mvt?.shape || options?.shape;
|
|
2751
|
+
switch (shape) {
|
|
2752
|
+
case "columnar-table":
|
|
2753
|
+
return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
|
|
2754
|
+
case "geojson-table": {
|
|
2755
|
+
const table = {
|
|
2756
|
+
shape: "geojson-table",
|
|
2757
|
+
type: "FeatureCollection",
|
|
2758
|
+
features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)
|
|
2759
|
+
};
|
|
2760
|
+
return table;
|
|
2761
|
+
}
|
|
2762
|
+
case "geojson":
|
|
2763
|
+
return parseToGeojsonFeatures(arrayBuffer, mvtOptions);
|
|
2764
|
+
case "binary-geometry":
|
|
2765
|
+
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2766
|
+
case "binary":
|
|
2767
|
+
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2768
|
+
default:
|
|
2769
|
+
throw new Error(shape || "undefined shape");
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
function parseToBinary(arrayBuffer, options) {
|
|
2773
|
+
const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);
|
|
2774
|
+
const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, geometryInfo);
|
|
2775
|
+
binaryData.byteLength = arrayBuffer.byteLength;
|
|
2776
|
+
return binaryData;
|
|
2777
|
+
}
|
|
2778
|
+
function parseToFlatGeoJson(arrayBuffer, options) {
|
|
2779
|
+
const features = [];
|
|
2780
|
+
const geometryInfo = {
|
|
2781
|
+
coordLength: 2,
|
|
2782
|
+
pointPositionsCount: 0,
|
|
2783
|
+
pointFeaturesCount: 0,
|
|
2784
|
+
linePositionsCount: 0,
|
|
2785
|
+
linePathsCount: 0,
|
|
2786
|
+
lineFeaturesCount: 0,
|
|
2787
|
+
polygonPositionsCount: 0,
|
|
2788
|
+
polygonObjectsCount: 0,
|
|
2789
|
+
polygonRingsCount: 0,
|
|
2790
|
+
polygonFeaturesCount: 0
|
|
2791
|
+
};
|
|
2792
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
2793
|
+
return [features, geometryInfo];
|
|
2794
|
+
}
|
|
2795
|
+
const tile = new VectorTile2(new import_pbf.default(arrayBuffer));
|
|
2796
|
+
const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
2797
|
+
selectedLayers.forEach((layerName) => {
|
|
2798
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
2799
|
+
if (!vectorTileLayer) {
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2802
|
+
for (let i3 = 0; i3 < vectorTileLayer.length; i3++) {
|
|
2803
|
+
const vectorTileFeature = vectorTileLayer.feature(i3, geometryInfo);
|
|
2804
|
+
const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
|
|
2805
|
+
features.push(decodedFeature);
|
|
2806
|
+
}
|
|
2807
|
+
});
|
|
2808
|
+
return [features, geometryInfo];
|
|
2809
|
+
}
|
|
2810
|
+
function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
2811
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
2812
|
+
return [];
|
|
2813
|
+
}
|
|
2814
|
+
const features = [];
|
|
2815
|
+
const tile = new VectorTile(new import_pbf.default(arrayBuffer));
|
|
2816
|
+
const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
2817
|
+
selectedLayers.forEach((layerName) => {
|
|
2818
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
2819
|
+
if (!vectorTileLayer) {
|
|
2820
|
+
return;
|
|
2821
|
+
}
|
|
2822
|
+
for (let i3 = 0; i3 < vectorTileLayer.length; i3++) {
|
|
2823
|
+
const vectorTileFeature = vectorTileLayer.feature(i3);
|
|
2824
|
+
const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
|
|
2825
|
+
features.push(decodedFeature);
|
|
2826
|
+
}
|
|
2827
|
+
});
|
|
2828
|
+
return features;
|
|
2829
|
+
}
|
|
2830
|
+
function normalizeOptions(options) {
|
|
2831
|
+
if (!options?.mvt) {
|
|
2832
|
+
throw new Error("mvt options required");
|
|
2833
|
+
}
|
|
2834
|
+
const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
|
|
2835
|
+
const { tileIndex } = options.mvt;
|
|
2836
|
+
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2837
|
+
if (wgs84Coordinates && !hasTileIndex) {
|
|
2838
|
+
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
|
|
2839
|
+
}
|
|
2840
|
+
return options.mvt;
|
|
2841
|
+
}
|
|
2842
|
+
function getDecodedFeature(feature, options, layerName) {
|
|
2843
|
+
const decodedFeature = feature.toGeoJSON(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates);
|
|
2844
|
+
if (options.layerProperty) {
|
|
2845
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2846
|
+
}
|
|
2847
|
+
return decodedFeature;
|
|
2848
|
+
}
|
|
2849
|
+
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
2850
|
+
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
2851
|
+
if (options.layerProperty && decodedFeature.properties) {
|
|
2852
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2853
|
+
}
|
|
2854
|
+
return decodedFeature;
|
|
2855
|
+
}
|
|
2856
|
+
function transformToLocalCoordinates(line, feature) {
|
|
2857
|
+
const { extent } = feature;
|
|
2858
|
+
for (let i3 = 0; i3 < line.length; i3++) {
|
|
2859
|
+
const p = line[i3];
|
|
2860
|
+
p[0] /= extent;
|
|
2861
|
+
p[1] /= extent;
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
function transformToLocalCoordinatesBinary(data, feature) {
|
|
2865
|
+
const { extent } = feature;
|
|
2866
|
+
for (let i3 = 0, il = data.length; i3 < il; ++i3) {
|
|
2867
|
+
data[i3] /= extent;
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
var import_pbf;
|
|
2871
|
+
var init_parse_mvt = __esm({
|
|
2872
|
+
"../mvt/src/lib/parse-mvt.ts"() {
|
|
2873
|
+
init_src3();
|
|
2874
|
+
import_pbf = __toModule(require_pbf());
|
|
2875
|
+
init_vector_tile();
|
|
2876
|
+
init_vector_tile2();
|
|
2877
|
+
}
|
|
2878
|
+
});
|
|
2879
|
+
|
|
2880
|
+
// ../mvt/src/mvt-loader.ts
|
|
2881
|
+
var VERSION2, MVTWorkerLoader, MVTLoader;
|
|
2882
|
+
var init_mvt_loader = __esm({
|
|
2883
|
+
"../mvt/src/mvt-loader.ts"() {
|
|
2884
|
+
init_parse_mvt();
|
|
2885
|
+
VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2886
|
+
MVTWorkerLoader = {
|
|
2887
|
+
name: "Mapbox Vector Tile",
|
|
2888
|
+
id: "mvt",
|
|
2889
|
+
module: "mvt",
|
|
2890
|
+
version: VERSION2,
|
|
2891
|
+
extensions: ["mvt", "pbf"],
|
|
2892
|
+
mimeTypes: [
|
|
2893
|
+
"application/vnd.mapbox-vector-tile",
|
|
2894
|
+
"application/x-protobuf"
|
|
2895
|
+
],
|
|
2896
|
+
worker: true,
|
|
2897
|
+
category: "geometry",
|
|
2898
|
+
options: {
|
|
2899
|
+
mvt: {
|
|
2900
|
+
shape: "geojson",
|
|
2901
|
+
coordinates: "local",
|
|
2902
|
+
layerProperty: "layerName",
|
|
2903
|
+
layers: void 0,
|
|
2904
|
+
tileIndex: null
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
};
|
|
2908
|
+
MVTLoader = {
|
|
2909
|
+
...MVTWorkerLoader,
|
|
2910
|
+
parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),
|
|
2911
|
+
parseSync: parseMVT,
|
|
2912
|
+
binary: true
|
|
2913
|
+
};
|
|
2914
|
+
}
|
|
2915
|
+
});
|
|
2916
|
+
|
|
2917
|
+
// ../mvt/src/lib/parse-tilejson.ts
|
|
2918
|
+
function parseTileJSON(jsonMetadata) {
|
|
2919
|
+
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
2920
|
+
return null;
|
|
2921
|
+
}
|
|
2922
|
+
const boundingBox = parseBounds(jsonMetadata.bounds);
|
|
2923
|
+
const center = parseCenter(jsonMetadata.center);
|
|
2924
|
+
const maxZoom = safeParseFloat(jsonMetadata.maxzoom);
|
|
2925
|
+
const minZoom = safeParseFloat(jsonMetadata.minzoom);
|
|
2926
|
+
let tileJSON = {
|
|
2927
|
+
name: jsonMetadata.name || "",
|
|
2928
|
+
description: jsonMetadata.description || "",
|
|
2929
|
+
boundingBox,
|
|
2930
|
+
center,
|
|
2931
|
+
maxZoom,
|
|
2932
|
+
minZoom,
|
|
2933
|
+
layers: []
|
|
2934
|
+
};
|
|
2935
|
+
if (typeof jsonMetadata?.json === "string") {
|
|
2936
|
+
try {
|
|
2937
|
+
tileJSON.metaJson = JSON.parse(jsonMetadata.json);
|
|
2938
|
+
} catch (err2) {
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
let layers = parseTilestatsLayers(tileJSON.metaJson?.tilestats);
|
|
2942
|
+
if (layers.length === 0) {
|
|
2943
|
+
layers = parseTileJSONLayers(jsonMetadata.vector_layers);
|
|
2944
|
+
}
|
|
2945
|
+
tileJSON = {
|
|
2946
|
+
...tileJSON,
|
|
2947
|
+
layers
|
|
2948
|
+
};
|
|
2949
|
+
return tileJSON;
|
|
2950
|
+
}
|
|
2951
|
+
function parseTileJSONLayers(layers) {
|
|
2952
|
+
if (!Array.isArray(layers)) {
|
|
2953
|
+
return [];
|
|
2954
|
+
}
|
|
2955
|
+
return layers.map((layer) => ({
|
|
2956
|
+
name: layer.id || "",
|
|
2957
|
+
fields: Object.entries(layer.fields || []).map(([key, datatype]) => ({
|
|
2958
|
+
name: key,
|
|
2959
|
+
...attributeTypeToFieldType(String(datatype))
|
|
2960
|
+
}))
|
|
2961
|
+
}));
|
|
2962
|
+
}
|
|
2963
|
+
function parseTilestatsLayers(tilestats) {
|
|
2964
|
+
if (isObject(tilestats) && Array.isArray(tilestats.layers)) {
|
|
2965
|
+
return tilestats.layers.map((layer) => parseTilestatsForLayer(layer));
|
|
2966
|
+
}
|
|
2967
|
+
return [];
|
|
2968
|
+
}
|
|
2969
|
+
function parseTilestatsForLayer(layer) {
|
|
2970
|
+
const fields = [];
|
|
2971
|
+
const indexedAttributes = {};
|
|
2972
|
+
const attributes = layer.attributes || [];
|
|
2973
|
+
for (const attr of attributes) {
|
|
2974
|
+
const name = attr.attribute;
|
|
2975
|
+
if (typeof name === "string") {
|
|
2976
|
+
if (name.split("|").length > 1) {
|
|
2977
|
+
const fname = name.split("|")[0];
|
|
2978
|
+
indexedAttributes[fname] = indexedAttributes[fname] || [];
|
|
2979
|
+
indexedAttributes[fname].push(attr);
|
|
2980
|
+
} else if (!fields[name]) {
|
|
2981
|
+
fields[name] = attributeToField(attr);
|
|
2982
|
+
} else {
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
return {
|
|
2987
|
+
name: layer.layer || "",
|
|
2988
|
+
dominantGeometry: layer.geometry,
|
|
2989
|
+
fields
|
|
2990
|
+
};
|
|
2991
|
+
}
|
|
2992
|
+
function parseBounds(bounds) {
|
|
2993
|
+
const result = fromArrayOrString(bounds);
|
|
2994
|
+
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
2995
|
+
return [
|
|
2996
|
+
[result[0], result[1]],
|
|
2997
|
+
[result[2], result[3]]
|
|
2998
|
+
];
|
|
2999
|
+
}
|
|
3000
|
+
return void 0;
|
|
3001
|
+
}
|
|
3002
|
+
function parseCenter(center) {
|
|
3003
|
+
const result = fromArrayOrString(center);
|
|
3004
|
+
if (Array.isArray(result) && result.length === 3 && isLng(result[0]) && isLat(result[1]) && isZoom(result[2])) {
|
|
3005
|
+
return result;
|
|
3006
|
+
}
|
|
3007
|
+
return null;
|
|
3008
|
+
}
|
|
3009
|
+
function safeParseFloat(input) {
|
|
3010
|
+
const result = typeof input === "string" ? parseFloat(input) : typeof input === "number" ? input : null;
|
|
3011
|
+
return result === null || isNaN(result) ? null : result;
|
|
3012
|
+
}
|
|
3013
|
+
function isLat(num) {
|
|
3014
|
+
return Number.isFinite(num) && num <= 90 && num >= -90;
|
|
3015
|
+
}
|
|
3016
|
+
function isLng(num) {
|
|
3017
|
+
return Number.isFinite(num) && num <= 180 && num >= -180;
|
|
3018
|
+
}
|
|
3019
|
+
function isZoom(num) {
|
|
3020
|
+
return Number.isFinite(num) && num >= 0 && num <= 22;
|
|
3021
|
+
}
|
|
3022
|
+
function fromArrayOrString(data) {
|
|
3023
|
+
if (typeof data === "string") {
|
|
3024
|
+
return data.split(",").map(parseFloat);
|
|
3025
|
+
} else if (Array.isArray(data)) {
|
|
3026
|
+
return data;
|
|
3027
|
+
}
|
|
3028
|
+
return null;
|
|
3029
|
+
}
|
|
3030
|
+
function attributeToField(attribute = {}) {
|
|
3031
|
+
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
3032
|
+
return {
|
|
3033
|
+
name: attribute.attribute,
|
|
3034
|
+
...fieldTypes
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
function attributeTypeToFieldType(aType) {
|
|
3038
|
+
const type = aType.toLowerCase();
|
|
3039
|
+
if (!type || !attrTypeMap[type]) {
|
|
3040
|
+
}
|
|
3041
|
+
return attrTypeMap[type] || { type: "string" };
|
|
3042
|
+
}
|
|
3043
|
+
var isObject, attrTypeMap;
|
|
3044
|
+
var init_parse_tilejson = __esm({
|
|
3045
|
+
"../mvt/src/lib/parse-tilejson.ts"() {
|
|
3046
|
+
isObject = (x3) => x3 !== null && typeof x3 === "object";
|
|
3047
|
+
attrTypeMap = {
|
|
3048
|
+
number: {
|
|
3049
|
+
type: "float32"
|
|
3050
|
+
},
|
|
3051
|
+
numeric: {
|
|
3052
|
+
type: "float32"
|
|
3053
|
+
},
|
|
3054
|
+
string: {
|
|
3055
|
+
type: "utf8"
|
|
3056
|
+
},
|
|
3057
|
+
vachar: {
|
|
3058
|
+
type: "utf8"
|
|
3059
|
+
},
|
|
3060
|
+
float: {
|
|
3061
|
+
type: "float32"
|
|
3062
|
+
},
|
|
3063
|
+
int: {
|
|
3064
|
+
type: "int32"
|
|
3065
|
+
},
|
|
3066
|
+
int4: {
|
|
3067
|
+
type: "int32"
|
|
3068
|
+
},
|
|
3069
|
+
boolean: {
|
|
3070
|
+
type: "boolean"
|
|
3071
|
+
},
|
|
3072
|
+
bool: {
|
|
3073
|
+
type: "boolean"
|
|
3074
|
+
}
|
|
3075
|
+
};
|
|
3076
|
+
}
|
|
3077
|
+
});
|
|
3078
|
+
|
|
3079
|
+
// ../mvt/src/tilejson-loader.ts
|
|
3080
|
+
var VERSION3, TileJSONLoader;
|
|
3081
|
+
var init_tilejson_loader = __esm({
|
|
3082
|
+
"../mvt/src/tilejson-loader.ts"() {
|
|
3083
|
+
init_parse_tilejson();
|
|
3084
|
+
VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3085
|
+
TileJSONLoader = {
|
|
3086
|
+
name: "TileJSON",
|
|
3087
|
+
id: "tilejson",
|
|
3088
|
+
module: "pmtiles",
|
|
3089
|
+
version: VERSION3,
|
|
3090
|
+
worker: true,
|
|
3091
|
+
extensions: ["json"],
|
|
3092
|
+
mimeTypes: ["application/json"],
|
|
3093
|
+
text: true,
|
|
3094
|
+
options: {
|
|
3095
|
+
tilejson: {}
|
|
3096
|
+
},
|
|
3097
|
+
parse: async (arrayBuffer, options) => {
|
|
3098
|
+
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
3099
|
+
const json = JSON.parse(jsonString);
|
|
3100
|
+
return parseTileJSON(json);
|
|
3101
|
+
},
|
|
3102
|
+
parseTextSync: (text, options) => {
|
|
3103
|
+
const json = JSON.parse(text);
|
|
3104
|
+
return parseTileJSON(json);
|
|
3105
|
+
}
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
});
|
|
3109
|
+
|
|
3110
|
+
// ../mvt/src/index.ts
|
|
3111
|
+
var init_src4 = __esm({
|
|
3112
|
+
"../mvt/src/index.ts"() {
|
|
3113
|
+
init_mvt_loader();
|
|
3114
|
+
init_tilejson_loader();
|
|
3115
|
+
}
|
|
3116
|
+
});
|
|
3117
|
+
|
|
3118
|
+
// ../../node_modules/pmtiles/dist/index.mjs
|
|
3119
|
+
function inflateSync(data, opts) {
|
|
3120
|
+
return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary);
|
|
3121
|
+
}
|
|
3122
|
+
function gunzipSync(data, opts) {
|
|
3123
|
+
var st = gzs(data);
|
|
3124
|
+
if (st + 8 > data.length)
|
|
3125
|
+
err(6, "invalid gzip data");
|
|
3126
|
+
return inflt(data.subarray(st, -8), { i: 2 }, opts && opts.out || new u8(gzl(data)), opts && opts.dictionary);
|
|
3127
|
+
}
|
|
3128
|
+
function unzlibSync(data, opts) {
|
|
3129
|
+
return inflt(data.subarray(zls(data, opts && opts.dictionary), -4), { i: 2 }, opts && opts.out, opts && opts.dictionary);
|
|
3130
|
+
}
|
|
3131
|
+
function decompressSync(data, opts) {
|
|
3132
|
+
return data[0] == 31 && data[1] == 139 && data[2] == 8 ? gunzipSync(data, opts) : (data[0] & 15) != 8 || data[0] >> 4 > 7 || (data[0] << 8 | data[1]) % 31 ? inflateSync(data, opts) : unzlibSync(data, opts);
|
|
3133
|
+
}
|
|
3134
|
+
function getHeader(source) {
|
|
3135
|
+
return __async(this, null, function* () {
|
|
3136
|
+
const resp = yield source.getBytes(0, 512e3);
|
|
3137
|
+
const dataview = new DataView(resp.data);
|
|
3138
|
+
const json_size = dataview.getUint32(4, true);
|
|
3139
|
+
const root_entries = dataview.getUint16(8, true);
|
|
3140
|
+
const dec = new TextDecoder("utf-8");
|
|
3141
|
+
const json_metadata = JSON.parse(dec.decode(new DataView(resp.data, 10, json_size)));
|
|
3142
|
+
let tile_compression = 0;
|
|
3143
|
+
if (json_metadata.compression === "gzip") {
|
|
3144
|
+
tile_compression = 2;
|
|
3145
|
+
}
|
|
3146
|
+
let minzoom = 0;
|
|
3147
|
+
if ("minzoom" in json_metadata) {
|
|
3148
|
+
minzoom = +json_metadata.minzoom;
|
|
3149
|
+
}
|
|
3150
|
+
let maxzoom = 0;
|
|
3151
|
+
if ("maxzoom" in json_metadata) {
|
|
3152
|
+
maxzoom = +json_metadata.maxzoom;
|
|
3153
|
+
}
|
|
3154
|
+
let center_lon = 0;
|
|
3155
|
+
let center_lat = 0;
|
|
3156
|
+
let center_zoom = 0;
|
|
3157
|
+
let min_lon = -180;
|
|
3158
|
+
let min_lat = -85;
|
|
3159
|
+
let max_lon = 180;
|
|
3160
|
+
let max_lat = 85;
|
|
3161
|
+
if (json_metadata.bounds) {
|
|
3162
|
+
const split = json_metadata.bounds.split(",");
|
|
3163
|
+
min_lon = +split[0];
|
|
3164
|
+
min_lat = +split[1];
|
|
3165
|
+
max_lon = +split[2];
|
|
3166
|
+
max_lat = +split[3];
|
|
3167
|
+
}
|
|
3168
|
+
if (json_metadata.center) {
|
|
3169
|
+
const split = json_metadata.center.split(",");
|
|
3170
|
+
center_lon = +split[0];
|
|
3171
|
+
center_lat = +split[1];
|
|
3172
|
+
center_zoom = +split[2];
|
|
3173
|
+
}
|
|
3174
|
+
const header = {
|
|
3175
|
+
specVersion: dataview.getUint16(2, true),
|
|
3176
|
+
rootDirectoryOffset: 10 + json_size,
|
|
3177
|
+
rootDirectoryLength: root_entries * 17,
|
|
3178
|
+
jsonMetadataOffset: 10,
|
|
3179
|
+
jsonMetadataLength: json_size,
|
|
3180
|
+
leafDirectoryOffset: 0,
|
|
3181
|
+
leafDirectoryLength: void 0,
|
|
3182
|
+
tileDataOffset: 0,
|
|
3183
|
+
tileDataLength: void 0,
|
|
3184
|
+
numAddressedTiles: 0,
|
|
3185
|
+
numTileEntries: 0,
|
|
3186
|
+
numTileContents: 0,
|
|
3187
|
+
clustered: false,
|
|
3188
|
+
internalCompression: 1,
|
|
3189
|
+
tileCompression: tile_compression,
|
|
3190
|
+
tileType: 1,
|
|
3191
|
+
minZoom: minzoom,
|
|
3192
|
+
maxZoom: maxzoom,
|
|
3193
|
+
minLon: min_lon,
|
|
3194
|
+
minLat: min_lat,
|
|
3195
|
+
maxLon: max_lon,
|
|
3196
|
+
maxLat: max_lat,
|
|
3197
|
+
centerZoom: center_zoom,
|
|
3198
|
+
centerLon: center_lon,
|
|
3199
|
+
centerLat: center_lat,
|
|
3200
|
+
etag: resp.etag
|
|
3201
|
+
};
|
|
3202
|
+
return header;
|
|
3203
|
+
});
|
|
3204
|
+
}
|
|
3205
|
+
function getZxy(header, source, cache, z, x3, y2, signal) {
|
|
3206
|
+
return __async(this, null, function* () {
|
|
3207
|
+
let root_dir = yield cache.getArrayBuffer(source, header.rootDirectoryOffset, header.rootDirectoryLength, header);
|
|
3208
|
+
if (header.specVersion === 1) {
|
|
3209
|
+
root_dir = sortDir(root_dir);
|
|
3210
|
+
}
|
|
3211
|
+
const entry = queryTile(new DataView(root_dir), z, x3, y2);
|
|
3212
|
+
if (entry) {
|
|
3213
|
+
const resp = yield source.getBytes(entry.offset, entry.length, signal);
|
|
3214
|
+
let tile_data = resp.data;
|
|
3215
|
+
const view = new DataView(tile_data);
|
|
3216
|
+
if (view.getUint8(0) == 31 && view.getUint8(1) == 139) {
|
|
3217
|
+
tile_data = decompressSync(new Uint8Array(tile_data));
|
|
3218
|
+
}
|
|
3219
|
+
return {
|
|
3220
|
+
data: tile_data
|
|
3221
|
+
};
|
|
3222
|
+
}
|
|
3223
|
+
const leafcoords = deriveLeaf(new DataView(root_dir), { z, x: x3, y: y2 });
|
|
3224
|
+
if (leafcoords) {
|
|
3225
|
+
const leafdir_entry = queryLeafdir(new DataView(root_dir), leafcoords.z, leafcoords.x, leafcoords.y);
|
|
3226
|
+
if (leafdir_entry) {
|
|
3227
|
+
let leaf_dir = yield cache.getArrayBuffer(source, leafdir_entry.offset, leafdir_entry.length, header);
|
|
3228
|
+
if (header.specVersion === 1) {
|
|
3229
|
+
leaf_dir = sortDir(leaf_dir);
|
|
3230
|
+
}
|
|
3231
|
+
const tile_entry = queryTile(new DataView(leaf_dir), z, x3, y2);
|
|
3232
|
+
if (tile_entry) {
|
|
3233
|
+
const resp = yield source.getBytes(tile_entry.offset, tile_entry.length, signal);
|
|
3234
|
+
let tile_data = resp.data;
|
|
3235
|
+
const view = new DataView(tile_data);
|
|
3236
|
+
if (view.getUint8(0) == 31 && view.getUint8(1) == 139) {
|
|
3237
|
+
tile_data = decompressSync(new Uint8Array(tile_data));
|
|
3238
|
+
}
|
|
3239
|
+
return {
|
|
3240
|
+
data: tile_data
|
|
3241
|
+
};
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
return void 0;
|
|
3246
|
+
});
|
|
3247
|
+
}
|
|
3248
|
+
function toNum(low, high) {
|
|
3249
|
+
return (high >>> 0) * 4294967296 + (low >>> 0);
|
|
3250
|
+
}
|
|
3251
|
+
function readVarintRemainder(l, p) {
|
|
3252
|
+
const buf = p.buf;
|
|
3253
|
+
let h, b;
|
|
3254
|
+
b = buf[p.pos++];
|
|
3255
|
+
h = (b & 112) >> 4;
|
|
3256
|
+
if (b < 128)
|
|
3257
|
+
return toNum(l, h);
|
|
3258
|
+
b = buf[p.pos++];
|
|
3259
|
+
h |= (b & 127) << 3;
|
|
3260
|
+
if (b < 128)
|
|
3261
|
+
return toNum(l, h);
|
|
3262
|
+
b = buf[p.pos++];
|
|
3263
|
+
h |= (b & 127) << 10;
|
|
3264
|
+
if (b < 128)
|
|
3265
|
+
return toNum(l, h);
|
|
3266
|
+
b = buf[p.pos++];
|
|
3267
|
+
h |= (b & 127) << 17;
|
|
3268
|
+
if (b < 128)
|
|
3269
|
+
return toNum(l, h);
|
|
3270
|
+
b = buf[p.pos++];
|
|
3271
|
+
h |= (b & 127) << 24;
|
|
3272
|
+
if (b < 128)
|
|
3273
|
+
return toNum(l, h);
|
|
3274
|
+
b = buf[p.pos++];
|
|
3275
|
+
h |= (b & 1) << 31;
|
|
3276
|
+
if (b < 128)
|
|
3277
|
+
return toNum(l, h);
|
|
3278
|
+
throw new Error("Expected varint not more than 10 bytes");
|
|
3279
|
+
}
|
|
3280
|
+
function readVarint(p) {
|
|
3281
|
+
const buf = p.buf;
|
|
3282
|
+
let val, b;
|
|
3283
|
+
b = buf[p.pos++];
|
|
3284
|
+
val = b & 127;
|
|
3285
|
+
if (b < 128)
|
|
3286
|
+
return val;
|
|
3287
|
+
b = buf[p.pos++];
|
|
3288
|
+
val |= (b & 127) << 7;
|
|
3289
|
+
if (b < 128)
|
|
3290
|
+
return val;
|
|
3291
|
+
b = buf[p.pos++];
|
|
3292
|
+
val |= (b & 127) << 14;
|
|
3293
|
+
if (b < 128)
|
|
3294
|
+
return val;
|
|
3295
|
+
b = buf[p.pos++];
|
|
3296
|
+
val |= (b & 127) << 21;
|
|
3297
|
+
if (b < 128)
|
|
3298
|
+
return val;
|
|
3299
|
+
b = buf[p.pos];
|
|
3300
|
+
val |= (b & 15) << 28;
|
|
3301
|
+
return readVarintRemainder(val, p);
|
|
3302
|
+
}
|
|
3303
|
+
function rotate(n, xy, rx, ry) {
|
|
3304
|
+
if (ry == 0) {
|
|
3305
|
+
if (rx == 1) {
|
|
3306
|
+
xy[0] = n - 1 - xy[0];
|
|
3307
|
+
xy[1] = n - 1 - xy[1];
|
|
3308
|
+
}
|
|
3309
|
+
const t = xy[0];
|
|
3310
|
+
xy[0] = xy[1];
|
|
3311
|
+
xy[1] = t;
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
function zxyToTileId(z, x3, y2) {
|
|
3315
|
+
if (z > 26) {
|
|
3316
|
+
throw Error("Tile zoom level exceeds max safe number limit (26)");
|
|
3317
|
+
}
|
|
3318
|
+
if (x3 > Math.pow(2, z) - 1 || y2 > Math.pow(2, z) - 1) {
|
|
3319
|
+
throw Error("tile x/y outside zoom level bounds");
|
|
3320
|
+
}
|
|
3321
|
+
const acc = tzValues[z];
|
|
3322
|
+
const n = Math.pow(2, z);
|
|
3323
|
+
let rx = 0;
|
|
3324
|
+
let ry = 0;
|
|
3325
|
+
let d = 0;
|
|
3326
|
+
const xy = [x3, y2];
|
|
3327
|
+
let s = n / 2;
|
|
3328
|
+
while (s > 0) {
|
|
3329
|
+
rx = (xy[0] & s) > 0 ? 1 : 0;
|
|
3330
|
+
ry = (xy[1] & s) > 0 ? 1 : 0;
|
|
3331
|
+
d += s * s * (3 * rx ^ ry);
|
|
3332
|
+
rotate(s, xy, rx, ry);
|
|
3333
|
+
s = s / 2;
|
|
3334
|
+
}
|
|
3335
|
+
return acc + d;
|
|
3336
|
+
}
|
|
3337
|
+
function defaultDecompress(buf, compression) {
|
|
3338
|
+
return __async(this, null, function* () {
|
|
3339
|
+
if (compression === 1 || compression === 0) {
|
|
3340
|
+
return buf;
|
|
3341
|
+
} else if (compression === 2) {
|
|
3342
|
+
if (typeof globalThis.DecompressionStream == "undefined") {
|
|
3343
|
+
return decompressSync(new Uint8Array(buf));
|
|
3344
|
+
} else {
|
|
3345
|
+
let stream = new Response(buf).body;
|
|
3346
|
+
let result = stream.pipeThrough(new globalThis.DecompressionStream("gzip"));
|
|
3347
|
+
return new Response(result).arrayBuffer();
|
|
3348
|
+
}
|
|
3349
|
+
} else {
|
|
3350
|
+
throw Error("Compression method not supported");
|
|
3351
|
+
}
|
|
3352
|
+
});
|
|
3353
|
+
}
|
|
3354
|
+
function findTile(entries, tileId) {
|
|
3355
|
+
let m = 0;
|
|
3356
|
+
let n = entries.length - 1;
|
|
3357
|
+
while (m <= n) {
|
|
3358
|
+
const k = n + m >> 1;
|
|
3359
|
+
const cmp = tileId - entries[k].tileId;
|
|
3360
|
+
if (cmp > 0) {
|
|
3361
|
+
m = k + 1;
|
|
3362
|
+
} else if (cmp < 0) {
|
|
3363
|
+
n = k - 1;
|
|
3364
|
+
} else {
|
|
3365
|
+
return entries[k];
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
if (n >= 0) {
|
|
3369
|
+
if (entries[n].runLength === 0) {
|
|
3370
|
+
return entries[n];
|
|
3371
|
+
}
|
|
3372
|
+
if (tileId - entries[n].tileId < entries[n].runLength) {
|
|
3373
|
+
return entries[n];
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
return null;
|
|
3377
|
+
}
|
|
3378
|
+
function getUint64(v, offset) {
|
|
3379
|
+
const wh = v.getUint32(offset + 4, true);
|
|
3380
|
+
const wl = v.getUint32(offset + 0, true);
|
|
3381
|
+
return wh * Math.pow(2, 32) + wl;
|
|
3382
|
+
}
|
|
3383
|
+
function bytesToHeader(bytes, etag) {
|
|
3384
|
+
const v = new DataView(bytes);
|
|
3385
|
+
const spec_version = v.getUint8(7);
|
|
3386
|
+
if (spec_version > 3) {
|
|
3387
|
+
throw Error(`Archive is spec version ${spec_version} but this library supports up to spec version 3`);
|
|
3388
|
+
}
|
|
3389
|
+
return {
|
|
3390
|
+
specVersion: spec_version,
|
|
3391
|
+
rootDirectoryOffset: getUint64(v, 8),
|
|
3392
|
+
rootDirectoryLength: getUint64(v, 16),
|
|
3393
|
+
jsonMetadataOffset: getUint64(v, 24),
|
|
3394
|
+
jsonMetadataLength: getUint64(v, 32),
|
|
3395
|
+
leafDirectoryOffset: getUint64(v, 40),
|
|
3396
|
+
leafDirectoryLength: getUint64(v, 48),
|
|
3397
|
+
tileDataOffset: getUint64(v, 56),
|
|
3398
|
+
tileDataLength: getUint64(v, 64),
|
|
3399
|
+
numAddressedTiles: getUint64(v, 72),
|
|
3400
|
+
numTileEntries: getUint64(v, 80),
|
|
3401
|
+
numTileContents: getUint64(v, 88),
|
|
3402
|
+
clustered: v.getUint8(96) === 1,
|
|
3403
|
+
internalCompression: v.getUint8(97),
|
|
3404
|
+
tileCompression: v.getUint8(98),
|
|
3405
|
+
tileType: v.getUint8(99),
|
|
3406
|
+
minZoom: v.getUint8(100),
|
|
3407
|
+
maxZoom: v.getUint8(101),
|
|
3408
|
+
minLon: v.getInt32(102, true) / 1e7,
|
|
3409
|
+
minLat: v.getInt32(106, true) / 1e7,
|
|
3410
|
+
maxLon: v.getInt32(110, true) / 1e7,
|
|
3411
|
+
maxLat: v.getInt32(114, true) / 1e7,
|
|
3412
|
+
centerZoom: v.getUint8(118),
|
|
3413
|
+
centerLon: v.getInt32(119, true) / 1e7,
|
|
3414
|
+
centerLat: v.getInt32(123, true) / 1e7,
|
|
3415
|
+
etag
|
|
3416
|
+
};
|
|
3417
|
+
}
|
|
3418
|
+
function deserializeIndex(buffer) {
|
|
3419
|
+
const p = { buf: new Uint8Array(buffer), pos: 0 };
|
|
3420
|
+
const numEntries = readVarint(p);
|
|
3421
|
+
const entries = [];
|
|
3422
|
+
let lastId = 0;
|
|
3423
|
+
for (let i3 = 0; i3 < numEntries; i3++) {
|
|
3424
|
+
const v = readVarint(p);
|
|
3425
|
+
entries.push({ tileId: lastId + v, offset: 0, length: 0, runLength: 1 });
|
|
3426
|
+
lastId += v;
|
|
3427
|
+
}
|
|
3428
|
+
for (let i3 = 0; i3 < numEntries; i3++) {
|
|
3429
|
+
entries[i3].runLength = readVarint(p);
|
|
3430
|
+
}
|
|
3431
|
+
for (let i3 = 0; i3 < numEntries; i3++) {
|
|
3432
|
+
entries[i3].length = readVarint(p);
|
|
3433
|
+
}
|
|
3434
|
+
for (let i3 = 0; i3 < numEntries; i3++) {
|
|
3435
|
+
const v = readVarint(p);
|
|
3436
|
+
if (v === 0 && i3 > 0) {
|
|
3437
|
+
entries[i3].offset = entries[i3 - 1].offset + entries[i3 - 1].length;
|
|
3438
|
+
} else {
|
|
3439
|
+
entries[i3].offset = v - 1;
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
return entries;
|
|
3443
|
+
}
|
|
3444
|
+
function detectVersion(a) {
|
|
3445
|
+
const v = new DataView(a);
|
|
3446
|
+
if (v.getUint16(2, true) === 2) {
|
|
3447
|
+
console.warn("PMTiles spec version 2 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade");
|
|
3448
|
+
return 2;
|
|
3449
|
+
} else if (v.getUint16(2, true) === 1) {
|
|
3450
|
+
console.warn("PMTiles spec version 1 has been deprecated; please see github.com/protomaps/PMTiles for tools to upgrade");
|
|
3451
|
+
return 1;
|
|
3452
|
+
}
|
|
3453
|
+
return 3;
|
|
3454
|
+
}
|
|
3455
|
+
function getHeaderAndRoot(source, decompress, prefetch, current_etag) {
|
|
3456
|
+
return __async(this, null, function* () {
|
|
3457
|
+
const resp = yield source.getBytes(0, 16384);
|
|
3458
|
+
const v = new DataView(resp.data);
|
|
3459
|
+
if (v.getUint16(0, true) !== 19792) {
|
|
3460
|
+
throw new Error("Wrong magic number for PMTiles archive");
|
|
3461
|
+
}
|
|
3462
|
+
if (detectVersion(resp.data) < 3) {
|
|
3463
|
+
return [yield v2_default.getHeader(source)];
|
|
3464
|
+
}
|
|
3465
|
+
const headerData = resp.data.slice(0, HEADER_SIZE_BYTES);
|
|
3466
|
+
let resp_etag = resp.etag;
|
|
3467
|
+
if (current_etag && resp.etag != current_etag) {
|
|
3468
|
+
console.warn("ETag conflict detected; your HTTP server might not support content-based ETag headers. ETags disabled for " + source.getKey());
|
|
3469
|
+
resp_etag = void 0;
|
|
3470
|
+
}
|
|
3471
|
+
const header = bytesToHeader(headerData, resp_etag);
|
|
3472
|
+
if (prefetch) {
|
|
3473
|
+
const rootDirData = resp.data.slice(header.rootDirectoryOffset, header.rootDirectoryOffset + header.rootDirectoryLength);
|
|
3474
|
+
const dirKey = source.getKey() + "|" + (header.etag || "") + "|" + header.rootDirectoryOffset + "|" + header.rootDirectoryLength;
|
|
3475
|
+
const rootDir = deserializeIndex(yield decompress(rootDirData, header.internalCompression));
|
|
3476
|
+
return [header, [dirKey, rootDir.length, rootDir]];
|
|
3477
|
+
}
|
|
3478
|
+
return [header, void 0];
|
|
3479
|
+
});
|
|
3480
|
+
}
|
|
3481
|
+
function getDirectory(source, decompress, offset, length2, header) {
|
|
3482
|
+
return __async(this, null, function* () {
|
|
3483
|
+
const resp = yield source.getBytes(offset, length2);
|
|
3484
|
+
if (header.etag && header.etag !== resp.etag) {
|
|
3485
|
+
throw new EtagMismatch(resp.etag);
|
|
3486
|
+
}
|
|
3487
|
+
const data = yield decompress(resp.data, header.internalCompression);
|
|
3488
|
+
const directory = deserializeIndex(data);
|
|
3489
|
+
if (directory.length === 0) {
|
|
3490
|
+
throw new Error("Empty directory is invalid");
|
|
3491
|
+
}
|
|
3492
|
+
return directory;
|
|
3493
|
+
});
|
|
3494
|
+
}
|
|
3495
|
+
var __async, u8, u16, i32, fleb, fdeb, clim, freb, _a, fl, revfl, _b, fd, revfd, rev, x2, i2, hMap, flt, i2, i2, i2, i2, fdt, i2, flrm, fdrm, max, bits, bits16, shft, slc, ec, err, inflt, et, gzs, gzl, zls, td, tds, shift, unshift, getUint24, getUint48, compare, queryLeafdir, queryTile, queryView, entrySort, parseEntry, sortDir, createDirectory, deriveLeaf, v2_default, tzValues, TileType, HEADER_SIZE_BYTES, FetchSource, EtagMismatch, SharedPromiseCache, PMTiles;
|
|
3496
|
+
var init_dist = __esm({
|
|
3497
|
+
"../../node_modules/pmtiles/dist/index.mjs"() {
|
|
3498
|
+
__async = (__this, __arguments, generator) => {
|
|
3499
|
+
return new Promise((resolve, reject) => {
|
|
3500
|
+
var fulfilled = (value) => {
|
|
3501
|
+
try {
|
|
3502
|
+
step(generator.next(value));
|
|
3503
|
+
} catch (e) {
|
|
3504
|
+
reject(e);
|
|
3505
|
+
}
|
|
3506
|
+
};
|
|
3507
|
+
var rejected = (value) => {
|
|
3508
|
+
try {
|
|
3509
|
+
step(generator.throw(value));
|
|
3510
|
+
} catch (e) {
|
|
3511
|
+
reject(e);
|
|
3512
|
+
}
|
|
3513
|
+
};
|
|
3514
|
+
var step = (x3) => x3.done ? resolve(x3.value) : Promise.resolve(x3.value).then(fulfilled, rejected);
|
|
3515
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
3516
|
+
});
|
|
3517
|
+
};
|
|
3518
|
+
u8 = Uint8Array;
|
|
3519
|
+
u16 = Uint16Array;
|
|
3520
|
+
i32 = Int32Array;
|
|
3521
|
+
fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0]);
|
|
3522
|
+
fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0]);
|
|
3523
|
+
clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
|
3524
|
+
freb = function(eb, start) {
|
|
3525
|
+
var b = new u16(31);
|
|
3526
|
+
for (var i3 = 0; i3 < 31; ++i3) {
|
|
3527
|
+
b[i3] = start += 1 << eb[i3 - 1];
|
|
3528
|
+
}
|
|
3529
|
+
var r = new i32(b[30]);
|
|
3530
|
+
for (var i3 = 1; i3 < 30; ++i3) {
|
|
3531
|
+
for (var j = b[i3]; j < b[i3 + 1]; ++j) {
|
|
3532
|
+
r[j] = j - b[i3] << 5 | i3;
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
return { b, r };
|
|
3536
|
+
};
|
|
3537
|
+
_a = freb(fleb, 2);
|
|
3538
|
+
fl = _a.b;
|
|
3539
|
+
revfl = _a.r;
|
|
3540
|
+
fl[28] = 258, revfl[258] = 28;
|
|
3541
|
+
_b = freb(fdeb, 0);
|
|
3542
|
+
fd = _b.b;
|
|
3543
|
+
revfd = _b.r;
|
|
3544
|
+
rev = new u16(32768);
|
|
3545
|
+
for (i2 = 0; i2 < 32768; ++i2) {
|
|
3546
|
+
x2 = (i2 & 43690) >> 1 | (i2 & 21845) << 1;
|
|
3547
|
+
x2 = (x2 & 52428) >> 2 | (x2 & 13107) << 2;
|
|
3548
|
+
x2 = (x2 & 61680) >> 4 | (x2 & 3855) << 4;
|
|
3549
|
+
rev[i2] = ((x2 & 65280) >> 8 | (x2 & 255) << 8) >> 1;
|
|
3550
|
+
}
|
|
3551
|
+
hMap = function(cd, mb, r) {
|
|
3552
|
+
var s = cd.length;
|
|
3553
|
+
var i3 = 0;
|
|
3554
|
+
var l = new u16(mb);
|
|
3555
|
+
for (; i3 < s; ++i3) {
|
|
3556
|
+
if (cd[i3])
|
|
3557
|
+
++l[cd[i3] - 1];
|
|
3558
|
+
}
|
|
3559
|
+
var le = new u16(mb);
|
|
3560
|
+
for (i3 = 1; i3 < mb; ++i3) {
|
|
3561
|
+
le[i3] = le[i3 - 1] + l[i3 - 1] << 1;
|
|
3562
|
+
}
|
|
3563
|
+
var co;
|
|
3564
|
+
if (r) {
|
|
3565
|
+
co = new u16(1 << mb);
|
|
3566
|
+
var rvb = 15 - mb;
|
|
3567
|
+
for (i3 = 0; i3 < s; ++i3) {
|
|
3568
|
+
if (cd[i3]) {
|
|
3569
|
+
var sv = i3 << 4 | cd[i3];
|
|
3570
|
+
var r_1 = mb - cd[i3];
|
|
3571
|
+
var v = le[cd[i3] - 1]++ << r_1;
|
|
3572
|
+
for (var m = v | (1 << r_1) - 1; v <= m; ++v) {
|
|
3573
|
+
co[rev[v] >> rvb] = sv;
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
} else {
|
|
3578
|
+
co = new u16(s);
|
|
3579
|
+
for (i3 = 0; i3 < s; ++i3) {
|
|
3580
|
+
if (cd[i3]) {
|
|
3581
|
+
co[i3] = rev[le[cd[i3] - 1]++] >> 15 - cd[i3];
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
return co;
|
|
3586
|
+
};
|
|
3587
|
+
flt = new u8(288);
|
|
3588
|
+
for (i2 = 0; i2 < 144; ++i2)
|
|
3589
|
+
flt[i2] = 8;
|
|
3590
|
+
for (i2 = 144; i2 < 256; ++i2)
|
|
3591
|
+
flt[i2] = 9;
|
|
3592
|
+
for (i2 = 256; i2 < 280; ++i2)
|
|
3593
|
+
flt[i2] = 7;
|
|
3594
|
+
for (i2 = 280; i2 < 288; ++i2)
|
|
3595
|
+
flt[i2] = 8;
|
|
3596
|
+
fdt = new u8(32);
|
|
3597
|
+
for (i2 = 0; i2 < 32; ++i2)
|
|
3598
|
+
fdt[i2] = 5;
|
|
3599
|
+
flrm = /* @__PURE__ */ hMap(flt, 9, 1);
|
|
3600
|
+
fdrm = /* @__PURE__ */ hMap(fdt, 5, 1);
|
|
3601
|
+
max = function(a) {
|
|
3602
|
+
var m = a[0];
|
|
3603
|
+
for (var i3 = 1; i3 < a.length; ++i3) {
|
|
3604
|
+
if (a[i3] > m)
|
|
3605
|
+
m = a[i3];
|
|
3606
|
+
}
|
|
3607
|
+
return m;
|
|
3608
|
+
};
|
|
3609
|
+
bits = function(d, p, m) {
|
|
3610
|
+
var o = p / 8 | 0;
|
|
3611
|
+
return (d[o] | d[o + 1] << 8) >> (p & 7) & m;
|
|
3612
|
+
};
|
|
3613
|
+
bits16 = function(d, p) {
|
|
3614
|
+
var o = p / 8 | 0;
|
|
3615
|
+
return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7);
|
|
3616
|
+
};
|
|
3617
|
+
shft = function(p) {
|
|
3618
|
+
return (p + 7) / 8 | 0;
|
|
3619
|
+
};
|
|
3620
|
+
slc = function(v, s, e) {
|
|
3621
|
+
if (s == null || s < 0)
|
|
3622
|
+
s = 0;
|
|
3623
|
+
if (e == null || e > v.length)
|
|
3624
|
+
e = v.length;
|
|
3625
|
+
var n = new u8(e - s);
|
|
3626
|
+
n.set(v.subarray(s, e));
|
|
3627
|
+
return n;
|
|
3628
|
+
};
|
|
3629
|
+
ec = [
|
|
3630
|
+
"unexpected EOF",
|
|
3631
|
+
"invalid block type",
|
|
3632
|
+
"invalid length/literal",
|
|
3633
|
+
"invalid distance",
|
|
3634
|
+
"stream finished",
|
|
3635
|
+
"no stream handler",
|
|
3636
|
+
,
|
|
3637
|
+
"no callback",
|
|
3638
|
+
"invalid UTF-8 data",
|
|
3639
|
+
"extra field too long",
|
|
3640
|
+
"date not in range 1980-2099",
|
|
3641
|
+
"filename too long",
|
|
3642
|
+
"stream finishing",
|
|
3643
|
+
"invalid zip data"
|
|
3644
|
+
];
|
|
3645
|
+
err = function(ind, msg, nt) {
|
|
3646
|
+
var e = new Error(msg || ec[ind]);
|
|
3647
|
+
e.code = ind;
|
|
3648
|
+
if (Error.captureStackTrace)
|
|
3649
|
+
Error.captureStackTrace(e, err);
|
|
3650
|
+
if (!nt)
|
|
3651
|
+
throw e;
|
|
3652
|
+
return e;
|
|
3653
|
+
};
|
|
3654
|
+
inflt = function(dat, st, buf, dict) {
|
|
3655
|
+
var sl = dat.length, dl = dict ? dict.length : 0;
|
|
3656
|
+
if (!sl || st.f && !st.l)
|
|
3657
|
+
return buf || new u8(0);
|
|
3658
|
+
var noBuf = !buf || st.i != 2;
|
|
3659
|
+
var noSt = st.i;
|
|
3660
|
+
if (!buf)
|
|
3661
|
+
buf = new u8(sl * 3);
|
|
3662
|
+
var cbuf = function(l2) {
|
|
3663
|
+
var bl = buf.length;
|
|
3664
|
+
if (l2 > bl) {
|
|
3665
|
+
var nbuf = new u8(Math.max(bl * 2, l2));
|
|
3666
|
+
nbuf.set(buf);
|
|
3667
|
+
buf = nbuf;
|
|
3668
|
+
}
|
|
3669
|
+
};
|
|
3670
|
+
var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
|
|
3671
|
+
var tbts = sl * 8;
|
|
3672
|
+
do {
|
|
3673
|
+
if (!lm) {
|
|
3674
|
+
final = bits(dat, pos, 1);
|
|
3675
|
+
var type = bits(dat, pos + 1, 3);
|
|
3676
|
+
pos += 3;
|
|
3677
|
+
if (!type) {
|
|
3678
|
+
var s = shft(pos) + 4, l = dat[s - 4] | dat[s - 3] << 8, t = s + l;
|
|
3679
|
+
if (t > sl) {
|
|
3680
|
+
if (noSt)
|
|
3681
|
+
err(0);
|
|
3682
|
+
break;
|
|
3683
|
+
}
|
|
3684
|
+
if (noBuf)
|
|
3685
|
+
cbuf(bt + l);
|
|
3686
|
+
buf.set(dat.subarray(s, t), bt);
|
|
3687
|
+
st.b = bt += l, st.p = pos = t * 8, st.f = final;
|
|
3688
|
+
continue;
|
|
3689
|
+
} else if (type == 1)
|
|
3690
|
+
lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
|
|
3691
|
+
else if (type == 2) {
|
|
3692
|
+
var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
|
|
3693
|
+
var tl = hLit + bits(dat, pos + 5, 31) + 1;
|
|
3694
|
+
pos += 14;
|
|
3695
|
+
var ldt = new u8(tl);
|
|
3696
|
+
var clt = new u8(19);
|
|
3697
|
+
for (var i3 = 0; i3 < hcLen; ++i3) {
|
|
3698
|
+
clt[clim[i3]] = bits(dat, pos + i3 * 3, 7);
|
|
3699
|
+
}
|
|
3700
|
+
pos += hcLen * 3;
|
|
3701
|
+
var clb = max(clt), clbmsk = (1 << clb) - 1;
|
|
3702
|
+
var clm = hMap(clt, clb, 1);
|
|
3703
|
+
for (var i3 = 0; i3 < tl; ) {
|
|
3704
|
+
var r = clm[bits(dat, pos, clbmsk)];
|
|
3705
|
+
pos += r & 15;
|
|
3706
|
+
var s = r >> 4;
|
|
3707
|
+
if (s < 16) {
|
|
3708
|
+
ldt[i3++] = s;
|
|
3709
|
+
} else {
|
|
3710
|
+
var c = 0, n = 0;
|
|
3711
|
+
if (s == 16)
|
|
3712
|
+
n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i3 - 1];
|
|
3713
|
+
else if (s == 17)
|
|
3714
|
+
n = 3 + bits(dat, pos, 7), pos += 3;
|
|
3715
|
+
else if (s == 18)
|
|
3716
|
+
n = 11 + bits(dat, pos, 127), pos += 7;
|
|
3717
|
+
while (n--)
|
|
3718
|
+
ldt[i3++] = c;
|
|
3719
|
+
}
|
|
3720
|
+
}
|
|
3721
|
+
var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
|
|
3722
|
+
lbt = max(lt);
|
|
3723
|
+
dbt = max(dt);
|
|
3724
|
+
lm = hMap(lt, lbt, 1);
|
|
3725
|
+
dm = hMap(dt, dbt, 1);
|
|
3726
|
+
} else
|
|
3727
|
+
err(1);
|
|
3728
|
+
if (pos > tbts) {
|
|
3729
|
+
if (noSt)
|
|
3730
|
+
err(0);
|
|
3731
|
+
break;
|
|
3732
|
+
}
|
|
3733
|
+
}
|
|
3734
|
+
if (noBuf)
|
|
3735
|
+
cbuf(bt + 131072);
|
|
3736
|
+
var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
|
|
3737
|
+
var lpos = pos;
|
|
3738
|
+
for (; ; lpos = pos) {
|
|
3739
|
+
var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
|
|
3740
|
+
pos += c & 15;
|
|
3741
|
+
if (pos > tbts) {
|
|
3742
|
+
if (noSt)
|
|
3743
|
+
err(0);
|
|
3744
|
+
break;
|
|
3745
|
+
}
|
|
3746
|
+
if (!c)
|
|
3747
|
+
err(2);
|
|
3748
|
+
if (sym < 256)
|
|
3749
|
+
buf[bt++] = sym;
|
|
3750
|
+
else if (sym == 256) {
|
|
3751
|
+
lpos = pos, lm = null;
|
|
3752
|
+
break;
|
|
3753
|
+
} else {
|
|
3754
|
+
var add = sym - 254;
|
|
3755
|
+
if (sym > 264) {
|
|
3756
|
+
var i3 = sym - 257, b = fleb[i3];
|
|
3757
|
+
add = bits(dat, pos, (1 << b) - 1) + fl[i3];
|
|
3758
|
+
pos += b;
|
|
3759
|
+
}
|
|
3760
|
+
var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
|
|
3761
|
+
if (!d)
|
|
3762
|
+
err(3);
|
|
3763
|
+
pos += d & 15;
|
|
3764
|
+
var dt = fd[dsym];
|
|
3765
|
+
if (dsym > 3) {
|
|
3766
|
+
var b = fdeb[dsym];
|
|
3767
|
+
dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
|
|
3768
|
+
}
|
|
3769
|
+
if (pos > tbts) {
|
|
3770
|
+
if (noSt)
|
|
3771
|
+
err(0);
|
|
3772
|
+
break;
|
|
3773
|
+
}
|
|
3774
|
+
if (noBuf)
|
|
3775
|
+
cbuf(bt + 131072);
|
|
3776
|
+
var end = bt + add;
|
|
3777
|
+
if (bt < dt) {
|
|
3778
|
+
var shift2 = dl - dt, dend = Math.min(dt, end);
|
|
3779
|
+
if (shift2 + bt < 0)
|
|
3780
|
+
err(3);
|
|
3781
|
+
for (; bt < dend; ++bt)
|
|
3782
|
+
buf[bt] = dict[shift2 + bt];
|
|
3783
|
+
}
|
|
3784
|
+
for (; bt < end; bt += 4) {
|
|
3785
|
+
buf[bt] = buf[bt - dt];
|
|
3786
|
+
buf[bt + 1] = buf[bt + 1 - dt];
|
|
3787
|
+
buf[bt + 2] = buf[bt + 2 - dt];
|
|
3788
|
+
buf[bt + 3] = buf[bt + 3 - dt];
|
|
3789
|
+
}
|
|
3790
|
+
bt = end;
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
st.l = lm, st.p = lpos, st.b = bt, st.f = final;
|
|
3794
|
+
if (lm)
|
|
3795
|
+
final = 1, st.m = lbt, st.d = dm, st.n = dbt;
|
|
3796
|
+
} while (!final);
|
|
3797
|
+
return bt == buf.length ? buf : slc(buf, 0, bt);
|
|
3798
|
+
};
|
|
3799
|
+
et = /* @__PURE__ */ new u8(0);
|
|
3800
|
+
gzs = function(d) {
|
|
3801
|
+
if (d[0] != 31 || d[1] != 139 || d[2] != 8)
|
|
3802
|
+
err(6, "invalid gzip data");
|
|
3803
|
+
var flg = d[3];
|
|
3804
|
+
var st = 10;
|
|
3805
|
+
if (flg & 4)
|
|
3806
|
+
st += (d[10] | d[11] << 8) + 2;
|
|
3807
|
+
for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++])
|
|
3808
|
+
;
|
|
3809
|
+
return st + (flg & 2);
|
|
3810
|
+
};
|
|
3811
|
+
gzl = function(d) {
|
|
3812
|
+
var l = d.length;
|
|
3813
|
+
return (d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16 | d[l - 1] << 24) >>> 0;
|
|
3814
|
+
};
|
|
3815
|
+
zls = function(d, dict) {
|
|
3816
|
+
if ((d[0] & 15) != 8 || d[0] >> 4 > 7 || (d[0] << 8 | d[1]) % 31)
|
|
3817
|
+
err(6, "invalid zlib data");
|
|
3818
|
+
if ((d[1] >> 5 & 1) == +!dict)
|
|
3819
|
+
err(6, "invalid zlib data: " + (d[1] & 32 ? "need" : "unexpected") + " dictionary");
|
|
3820
|
+
return (d[1] >> 3 & 4) + 2;
|
|
3821
|
+
};
|
|
3822
|
+
td = typeof TextDecoder != "undefined" && /* @__PURE__ */ new TextDecoder();
|
|
3823
|
+
tds = 0;
|
|
3824
|
+
try {
|
|
3825
|
+
td.decode(et, { stream: true });
|
|
3826
|
+
tds = 1;
|
|
3827
|
+
} catch (e) {
|
|
3828
|
+
}
|
|
3829
|
+
shift = (n, shift2) => {
|
|
3830
|
+
return n * Math.pow(2, shift2);
|
|
3831
|
+
};
|
|
3832
|
+
unshift = (n, shift2) => {
|
|
3833
|
+
return Math.floor(n / Math.pow(2, shift2));
|
|
3834
|
+
};
|
|
3835
|
+
getUint24 = (view, pos) => {
|
|
3836
|
+
return shift(view.getUint16(pos + 1, true), 8) + view.getUint8(pos);
|
|
3837
|
+
};
|
|
3838
|
+
getUint48 = (view, pos) => {
|
|
3839
|
+
return shift(view.getUint32(pos + 2, true), 16) + view.getUint16(pos, true);
|
|
3840
|
+
};
|
|
3841
|
+
compare = (tz, tx, ty, view, i3) => {
|
|
3842
|
+
if (tz != view.getUint8(i3))
|
|
3843
|
+
return tz - view.getUint8(i3);
|
|
3844
|
+
const x3 = getUint24(view, i3 + 1);
|
|
3845
|
+
if (tx != x3)
|
|
3846
|
+
return tx - x3;
|
|
3847
|
+
const y2 = getUint24(view, i3 + 4);
|
|
3848
|
+
if (ty != y2)
|
|
3849
|
+
return ty - y2;
|
|
3850
|
+
return 0;
|
|
3851
|
+
};
|
|
3852
|
+
queryLeafdir = (view, z, x3, y2) => {
|
|
3853
|
+
const offset_len = queryView(view, z | 128, x3, y2);
|
|
3854
|
+
if (offset_len) {
|
|
3855
|
+
return {
|
|
3856
|
+
z,
|
|
3857
|
+
x: x3,
|
|
3858
|
+
y: y2,
|
|
3859
|
+
offset: offset_len[0],
|
|
3860
|
+
length: offset_len[1],
|
|
3861
|
+
is_dir: true
|
|
3862
|
+
};
|
|
3863
|
+
}
|
|
3864
|
+
return null;
|
|
3865
|
+
};
|
|
3866
|
+
queryTile = (view, z, x3, y2) => {
|
|
3867
|
+
const offset_len = queryView(view, z, x3, y2);
|
|
3868
|
+
if (offset_len) {
|
|
3869
|
+
return {
|
|
3870
|
+
z,
|
|
3871
|
+
x: x3,
|
|
3872
|
+
y: y2,
|
|
3873
|
+
offset: offset_len[0],
|
|
3874
|
+
length: offset_len[1],
|
|
3875
|
+
is_dir: false
|
|
3876
|
+
};
|
|
3877
|
+
}
|
|
3878
|
+
return null;
|
|
3879
|
+
};
|
|
3880
|
+
queryView = (view, z, x3, y2) => {
|
|
3881
|
+
let m = 0;
|
|
3882
|
+
let n = view.byteLength / 17 - 1;
|
|
3883
|
+
while (m <= n) {
|
|
3884
|
+
const k = n + m >> 1;
|
|
3885
|
+
const cmp = compare(z, x3, y2, view, k * 17);
|
|
3886
|
+
if (cmp > 0) {
|
|
3887
|
+
m = k + 1;
|
|
3888
|
+
} else if (cmp < 0) {
|
|
3889
|
+
n = k - 1;
|
|
3890
|
+
} else {
|
|
3891
|
+
return [getUint48(view, k * 17 + 7), view.getUint32(k * 17 + 13, true)];
|
|
3892
|
+
}
|
|
3893
|
+
}
|
|
3894
|
+
return null;
|
|
3895
|
+
};
|
|
3896
|
+
entrySort = (a, b) => {
|
|
3897
|
+
if (a.is_dir && !b.is_dir) {
|
|
3898
|
+
return 1;
|
|
3899
|
+
}
|
|
3900
|
+
if (!a.is_dir && b.is_dir) {
|
|
3901
|
+
return -1;
|
|
3902
|
+
}
|
|
3903
|
+
if (a.z !== b.z) {
|
|
3904
|
+
return a.z - b.z;
|
|
3905
|
+
}
|
|
3906
|
+
if (a.x !== b.x) {
|
|
3907
|
+
return a.x - b.x;
|
|
3908
|
+
}
|
|
3909
|
+
return a.y - b.y;
|
|
3910
|
+
};
|
|
3911
|
+
parseEntry = (dataview, i3) => {
|
|
3912
|
+
const z_raw = dataview.getUint8(i3 * 17);
|
|
3913
|
+
const z = z_raw & 127;
|
|
3914
|
+
return {
|
|
3915
|
+
z,
|
|
3916
|
+
x: getUint24(dataview, i3 * 17 + 1),
|
|
3917
|
+
y: getUint24(dataview, i3 * 17 + 4),
|
|
3918
|
+
offset: getUint48(dataview, i3 * 17 + 7),
|
|
3919
|
+
length: dataview.getUint32(i3 * 17 + 13, true),
|
|
3920
|
+
is_dir: z_raw >> 7 === 1
|
|
3921
|
+
};
|
|
3922
|
+
};
|
|
3923
|
+
sortDir = (a) => {
|
|
3924
|
+
const entries = [];
|
|
3925
|
+
const view = new DataView(a);
|
|
3926
|
+
for (let i3 = 0; i3 < view.byteLength / 17; i3++) {
|
|
3927
|
+
entries.push(parseEntry(view, i3));
|
|
3928
|
+
}
|
|
3929
|
+
return createDirectory(entries);
|
|
3930
|
+
};
|
|
3931
|
+
createDirectory = (entries) => {
|
|
3932
|
+
entries.sort(entrySort);
|
|
3933
|
+
const buffer = new ArrayBuffer(17 * entries.length);
|
|
3934
|
+
const arr = new Uint8Array(buffer);
|
|
3935
|
+
for (let i3 = 0; i3 < entries.length; i3++) {
|
|
3936
|
+
const entry = entries[i3];
|
|
3937
|
+
let z = entry.z;
|
|
3938
|
+
if (entry.is_dir)
|
|
3939
|
+
z = z | 128;
|
|
3940
|
+
arr[i3 * 17] = z;
|
|
3941
|
+
arr[i3 * 17 + 1] = entry.x & 255;
|
|
3942
|
+
arr[i3 * 17 + 2] = entry.x >> 8 & 255;
|
|
3943
|
+
arr[i3 * 17 + 3] = entry.x >> 16 & 255;
|
|
3944
|
+
arr[i3 * 17 + 4] = entry.y & 255;
|
|
3945
|
+
arr[i3 * 17 + 5] = entry.y >> 8 & 255;
|
|
3946
|
+
arr[i3 * 17 + 6] = entry.y >> 16 & 255;
|
|
3947
|
+
arr[i3 * 17 + 7] = entry.offset & 255;
|
|
3948
|
+
arr[i3 * 17 + 8] = unshift(entry.offset, 8) & 255;
|
|
3949
|
+
arr[i3 * 17 + 9] = unshift(entry.offset, 16) & 255;
|
|
3950
|
+
arr[i3 * 17 + 10] = unshift(entry.offset, 24) & 255;
|
|
3951
|
+
arr[i3 * 17 + 11] = unshift(entry.offset, 32) & 255;
|
|
3952
|
+
arr[i3 * 17 + 12] = unshift(entry.offset, 48) & 255;
|
|
3953
|
+
arr[i3 * 17 + 13] = entry.length & 255;
|
|
3954
|
+
arr[i3 * 17 + 14] = entry.length >> 8 & 255;
|
|
3955
|
+
arr[i3 * 17 + 15] = entry.length >> 16 & 255;
|
|
3956
|
+
arr[i3 * 17 + 16] = entry.length >> 24 & 255;
|
|
3957
|
+
}
|
|
3958
|
+
return buffer;
|
|
3959
|
+
};
|
|
3960
|
+
deriveLeaf = (view, tile) => {
|
|
3961
|
+
if (view.byteLength < 17)
|
|
3962
|
+
return null;
|
|
3963
|
+
const numEntries = view.byteLength / 17;
|
|
3964
|
+
const entry = parseEntry(view, numEntries - 1);
|
|
3965
|
+
if (entry.is_dir) {
|
|
3966
|
+
const leaf_level = entry.z;
|
|
3967
|
+
const level_diff = tile.z - leaf_level;
|
|
3968
|
+
const leaf_x = Math.trunc(tile.x / (1 << level_diff));
|
|
3969
|
+
const leaf_y = Math.trunc(tile.y / (1 << level_diff));
|
|
3970
|
+
return { z: leaf_level, x: leaf_x, y: leaf_y };
|
|
3971
|
+
}
|
|
3972
|
+
return null;
|
|
3973
|
+
};
|
|
3974
|
+
v2_default = {
|
|
3975
|
+
getHeader,
|
|
3976
|
+
getZxy
|
|
3977
|
+
};
|
|
3978
|
+
tzValues = [
|
|
3979
|
+
0,
|
|
3980
|
+
1,
|
|
3981
|
+
5,
|
|
3982
|
+
21,
|
|
3983
|
+
85,
|
|
3984
|
+
341,
|
|
3985
|
+
1365,
|
|
3986
|
+
5461,
|
|
3987
|
+
21845,
|
|
3988
|
+
87381,
|
|
3989
|
+
349525,
|
|
3990
|
+
1398101,
|
|
3991
|
+
5592405,
|
|
3992
|
+
22369621,
|
|
3993
|
+
89478485,
|
|
3994
|
+
357913941,
|
|
3995
|
+
1431655765,
|
|
3996
|
+
5726623061,
|
|
3997
|
+
22906492245,
|
|
3998
|
+
91625968981,
|
|
3999
|
+
366503875925,
|
|
4000
|
+
1466015503701,
|
|
4001
|
+
5864062014805,
|
|
4002
|
+
23456248059221,
|
|
4003
|
+
93824992236885,
|
|
4004
|
+
375299968947541,
|
|
4005
|
+
1501199875790165
|
|
4006
|
+
];
|
|
4007
|
+
TileType = /* @__PURE__ */ ((TileType2) => {
|
|
4008
|
+
TileType2[TileType2["Unknown"] = 0] = "Unknown";
|
|
4009
|
+
TileType2[TileType2["Mvt"] = 1] = "Mvt";
|
|
4010
|
+
TileType2[TileType2["Png"] = 2] = "Png";
|
|
4011
|
+
TileType2[TileType2["Jpeg"] = 3] = "Jpeg";
|
|
4012
|
+
TileType2[TileType2["Webp"] = 4] = "Webp";
|
|
4013
|
+
TileType2[TileType2["Avif"] = 5] = "Avif";
|
|
4014
|
+
return TileType2;
|
|
4015
|
+
})(TileType || {});
|
|
4016
|
+
HEADER_SIZE_BYTES = 127;
|
|
4017
|
+
FetchSource = class {
|
|
4018
|
+
constructor(url) {
|
|
4019
|
+
this.url = url;
|
|
4020
|
+
}
|
|
4021
|
+
getKey() {
|
|
4022
|
+
return this.url;
|
|
4023
|
+
}
|
|
4024
|
+
getBytes(offset, length2, signal) {
|
|
4025
|
+
return __async(this, null, function* () {
|
|
4026
|
+
let controller;
|
|
4027
|
+
if (!signal) {
|
|
4028
|
+
controller = new AbortController();
|
|
4029
|
+
signal = controller.signal;
|
|
4030
|
+
}
|
|
4031
|
+
let resp = yield fetch(this.url, {
|
|
4032
|
+
signal,
|
|
4033
|
+
headers: { Range: "bytes=" + offset + "-" + (offset + length2 - 1) }
|
|
4034
|
+
});
|
|
4035
|
+
if (resp.status === 416 && offset === 0) {
|
|
4036
|
+
const content_range = resp.headers.get("Content-Range");
|
|
4037
|
+
if (!content_range || !content_range.startsWith("bytes */")) {
|
|
4038
|
+
throw Error("Missing content-length on 416 response");
|
|
4039
|
+
}
|
|
4040
|
+
const actual_length = +content_range.substr(8);
|
|
4041
|
+
resp = yield fetch(this.url, {
|
|
4042
|
+
signal,
|
|
4043
|
+
headers: { Range: "bytes=0-" + (actual_length - 1) }
|
|
4044
|
+
});
|
|
4045
|
+
}
|
|
4046
|
+
if (resp.status >= 300) {
|
|
4047
|
+
throw Error("Bad response code: " + resp.status);
|
|
4048
|
+
}
|
|
4049
|
+
const content_length = resp.headers.get("Content-Length");
|
|
4050
|
+
if (resp.status === 200 && (!content_length || +content_length > length2)) {
|
|
4051
|
+
if (controller)
|
|
4052
|
+
controller.abort();
|
|
4053
|
+
throw Error("Server returned no content-length header or content-length exceeding request. Check that your storage backend supports HTTP Byte Serving.");
|
|
4054
|
+
}
|
|
4055
|
+
const a = yield resp.arrayBuffer();
|
|
4056
|
+
return {
|
|
4057
|
+
data: a,
|
|
4058
|
+
etag: resp.headers.get("ETag") || void 0,
|
|
4059
|
+
cacheControl: resp.headers.get("Cache-Control") || void 0,
|
|
4060
|
+
expires: resp.headers.get("Expires") || void 0
|
|
4061
|
+
};
|
|
4062
|
+
});
|
|
4063
|
+
}
|
|
4064
|
+
};
|
|
4065
|
+
EtagMismatch = class extends Error {
|
|
4066
|
+
};
|
|
4067
|
+
SharedPromiseCache = class {
|
|
4068
|
+
constructor(maxCacheEntries = 100, prefetch = true, decompress = defaultDecompress) {
|
|
4069
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
4070
|
+
this.maxCacheEntries = maxCacheEntries;
|
|
4071
|
+
this.counter = 1;
|
|
4072
|
+
this.prefetch = prefetch;
|
|
4073
|
+
this.decompress = decompress;
|
|
4074
|
+
}
|
|
4075
|
+
getHeader(source, current_etag) {
|
|
4076
|
+
return __async(this, null, function* () {
|
|
4077
|
+
const cacheKey = source.getKey();
|
|
4078
|
+
if (this.cache.has(cacheKey)) {
|
|
4079
|
+
this.cache.get(cacheKey).lastUsed = this.counter++;
|
|
4080
|
+
const data = yield this.cache.get(cacheKey).data;
|
|
4081
|
+
return data;
|
|
4082
|
+
}
|
|
4083
|
+
const p = new Promise((resolve, reject) => {
|
|
4084
|
+
getHeaderAndRoot(source, this.decompress, this.prefetch, current_etag).then((res) => {
|
|
4085
|
+
if (res[1]) {
|
|
4086
|
+
this.cache.set(res[1][0], {
|
|
4087
|
+
lastUsed: this.counter++,
|
|
4088
|
+
data: Promise.resolve(res[1][2])
|
|
4089
|
+
});
|
|
4090
|
+
}
|
|
4091
|
+
resolve(res[0]);
|
|
4092
|
+
this.prune();
|
|
4093
|
+
}).catch((e) => {
|
|
4094
|
+
reject(e);
|
|
4095
|
+
});
|
|
4096
|
+
});
|
|
4097
|
+
this.cache.set(cacheKey, { lastUsed: this.counter++, data: p });
|
|
4098
|
+
return p;
|
|
4099
|
+
});
|
|
4100
|
+
}
|
|
4101
|
+
getDirectory(source, offset, length2, header) {
|
|
4102
|
+
return __async(this, null, function* () {
|
|
4103
|
+
const cacheKey = source.getKey() + "|" + (header.etag || "") + "|" + offset + "|" + length2;
|
|
4104
|
+
if (this.cache.has(cacheKey)) {
|
|
4105
|
+
this.cache.get(cacheKey).lastUsed = this.counter++;
|
|
4106
|
+
const data = yield this.cache.get(cacheKey).data;
|
|
4107
|
+
return data;
|
|
4108
|
+
}
|
|
4109
|
+
const p = new Promise((resolve, reject) => {
|
|
4110
|
+
getDirectory(source, this.decompress, offset, length2, header).then((directory) => {
|
|
4111
|
+
resolve(directory);
|
|
4112
|
+
this.prune();
|
|
4113
|
+
}).catch((e) => {
|
|
4114
|
+
reject(e);
|
|
4115
|
+
});
|
|
4116
|
+
});
|
|
4117
|
+
this.cache.set(cacheKey, { lastUsed: this.counter++, data: p });
|
|
4118
|
+
return p;
|
|
4119
|
+
});
|
|
4120
|
+
}
|
|
4121
|
+
getArrayBuffer(source, offset, length2, header) {
|
|
4122
|
+
return __async(this, null, function* () {
|
|
4123
|
+
const cacheKey = source.getKey() + "|" + (header.etag || "") + "|" + offset + "|" + length2;
|
|
4124
|
+
if (this.cache.has(cacheKey)) {
|
|
4125
|
+
this.cache.get(cacheKey).lastUsed = this.counter++;
|
|
4126
|
+
const data = yield this.cache.get(cacheKey).data;
|
|
4127
|
+
return data;
|
|
4128
|
+
}
|
|
4129
|
+
const p = new Promise((resolve, reject) => {
|
|
4130
|
+
source.getBytes(offset, length2).then((resp) => {
|
|
4131
|
+
if (header.etag && header.etag !== resp.etag) {
|
|
4132
|
+
throw new EtagMismatch(resp.etag);
|
|
4133
|
+
}
|
|
4134
|
+
resolve(resp.data);
|
|
4135
|
+
if (this.cache.has(cacheKey)) {
|
|
4136
|
+
}
|
|
4137
|
+
this.prune();
|
|
4138
|
+
}).catch((e) => {
|
|
4139
|
+
reject(e);
|
|
4140
|
+
});
|
|
4141
|
+
});
|
|
4142
|
+
this.cache.set(cacheKey, { lastUsed: this.counter++, data: p });
|
|
4143
|
+
return p;
|
|
4144
|
+
});
|
|
4145
|
+
}
|
|
4146
|
+
prune() {
|
|
4147
|
+
if (this.cache.size >= this.maxCacheEntries) {
|
|
4148
|
+
let minUsed = Infinity;
|
|
4149
|
+
let minKey = void 0;
|
|
4150
|
+
this.cache.forEach((cache_value, key) => {
|
|
4151
|
+
if (cache_value.lastUsed < minUsed) {
|
|
4152
|
+
minUsed = cache_value.lastUsed;
|
|
4153
|
+
minKey = key;
|
|
4154
|
+
}
|
|
4155
|
+
});
|
|
4156
|
+
if (minKey) {
|
|
4157
|
+
this.cache.delete(minKey);
|
|
4158
|
+
}
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
invalidate(source, current_etag) {
|
|
4162
|
+
return __async(this, null, function* () {
|
|
4163
|
+
this.cache.delete(source.getKey());
|
|
4164
|
+
yield this.getHeader(source, current_etag);
|
|
4165
|
+
});
|
|
4166
|
+
}
|
|
4167
|
+
};
|
|
4168
|
+
PMTiles = class {
|
|
4169
|
+
constructor(source, cache, decompress) {
|
|
4170
|
+
if (typeof source === "string") {
|
|
4171
|
+
this.source = new FetchSource(source);
|
|
4172
|
+
} else {
|
|
4173
|
+
this.source = source;
|
|
4174
|
+
}
|
|
4175
|
+
if (decompress) {
|
|
4176
|
+
this.decompress = decompress;
|
|
4177
|
+
} else {
|
|
4178
|
+
this.decompress = defaultDecompress;
|
|
4179
|
+
}
|
|
4180
|
+
if (cache) {
|
|
4181
|
+
this.cache = cache;
|
|
4182
|
+
} else {
|
|
4183
|
+
this.cache = new SharedPromiseCache();
|
|
4184
|
+
}
|
|
4185
|
+
}
|
|
4186
|
+
getHeader() {
|
|
4187
|
+
return __async(this, null, function* () {
|
|
4188
|
+
return yield this.cache.getHeader(this.source);
|
|
4189
|
+
});
|
|
4190
|
+
}
|
|
4191
|
+
getZxyAttempt(z, x3, y2, signal) {
|
|
4192
|
+
return __async(this, null, function* () {
|
|
4193
|
+
const tile_id = zxyToTileId(z, x3, y2);
|
|
4194
|
+
const header = yield this.cache.getHeader(this.source);
|
|
4195
|
+
if (header.specVersion < 3) {
|
|
4196
|
+
return v2_default.getZxy(header, this.source, this.cache, z, x3, y2, signal);
|
|
4197
|
+
}
|
|
4198
|
+
if (z < header.minZoom || z > header.maxZoom) {
|
|
4199
|
+
return void 0;
|
|
4200
|
+
}
|
|
4201
|
+
let d_o = header.rootDirectoryOffset;
|
|
4202
|
+
let d_l = header.rootDirectoryLength;
|
|
4203
|
+
for (let depth = 0; depth <= 3; depth++) {
|
|
4204
|
+
const directory = yield this.cache.getDirectory(this.source, d_o, d_l, header);
|
|
4205
|
+
const entry = findTile(directory, tile_id);
|
|
4206
|
+
if (entry) {
|
|
4207
|
+
if (entry.runLength > 0) {
|
|
4208
|
+
const resp = yield this.source.getBytes(header.tileDataOffset + entry.offset, entry.length, signal);
|
|
4209
|
+
if (header.etag && header.etag !== resp.etag) {
|
|
4210
|
+
throw new EtagMismatch(resp.etag);
|
|
4211
|
+
}
|
|
4212
|
+
return {
|
|
4213
|
+
data: yield this.decompress(resp.data, header.tileCompression),
|
|
4214
|
+
cacheControl: resp.cacheControl,
|
|
4215
|
+
expires: resp.expires
|
|
4216
|
+
};
|
|
4217
|
+
} else {
|
|
4218
|
+
d_o = header.leafDirectoryOffset + entry.offset;
|
|
4219
|
+
d_l = entry.length;
|
|
4220
|
+
}
|
|
4221
|
+
} else {
|
|
4222
|
+
return void 0;
|
|
4223
|
+
}
|
|
4224
|
+
}
|
|
4225
|
+
throw Error("Maximum directory depth exceeded");
|
|
4226
|
+
});
|
|
4227
|
+
}
|
|
4228
|
+
getZxy(z, x3, y2, signal) {
|
|
4229
|
+
return __async(this, null, function* () {
|
|
4230
|
+
try {
|
|
4231
|
+
return yield this.getZxyAttempt(z, x3, y2, signal);
|
|
4232
|
+
} catch (e) {
|
|
4233
|
+
if (e instanceof EtagMismatch) {
|
|
4234
|
+
this.cache.invalidate(this.source, e.message);
|
|
4235
|
+
return yield this.getZxyAttempt(z, x3, y2, signal);
|
|
4236
|
+
} else {
|
|
4237
|
+
throw e;
|
|
4238
|
+
}
|
|
4239
|
+
}
|
|
4240
|
+
});
|
|
4241
|
+
}
|
|
4242
|
+
getMetadataAttempt() {
|
|
4243
|
+
return __async(this, null, function* () {
|
|
4244
|
+
const header = yield this.cache.getHeader(this.source);
|
|
4245
|
+
const resp = yield this.source.getBytes(header.jsonMetadataOffset, header.jsonMetadataLength);
|
|
4246
|
+
if (header.etag && header.etag !== resp.etag) {
|
|
4247
|
+
throw new EtagMismatch(resp.etag);
|
|
4248
|
+
}
|
|
4249
|
+
const decompressed = yield this.decompress(resp.data, header.internalCompression);
|
|
4250
|
+
const dec = new TextDecoder("utf-8");
|
|
4251
|
+
return JSON.parse(dec.decode(decompressed));
|
|
4252
|
+
});
|
|
4253
|
+
}
|
|
4254
|
+
getMetadata() {
|
|
4255
|
+
return __async(this, null, function* () {
|
|
4256
|
+
try {
|
|
4257
|
+
return yield this.getMetadataAttempt();
|
|
4258
|
+
} catch (e) {
|
|
4259
|
+
if (e instanceof EtagMismatch) {
|
|
4260
|
+
this.cache.invalidate(this.source, e.message);
|
|
4261
|
+
return yield this.getMetadataAttempt();
|
|
4262
|
+
} else {
|
|
4263
|
+
throw e;
|
|
4264
|
+
}
|
|
4265
|
+
}
|
|
4266
|
+
});
|
|
4267
|
+
}
|
|
4268
|
+
};
|
|
4269
|
+
}
|
|
4270
|
+
});
|
|
4271
|
+
|
|
4272
|
+
// src/lib/parse-pmtiles.ts
|
|
4273
|
+
function parsePMTilesHeader(header, tilejsonMetadata, options) {
|
|
4274
|
+
const partialMetadata = {};
|
|
4275
|
+
if (typeof tilejsonMetadata?.name === "string") {
|
|
4276
|
+
partialMetadata.name = tilejsonMetadata.name;
|
|
4277
|
+
}
|
|
4278
|
+
if (typeof tilejsonMetadata?.attribution === "string") {
|
|
4279
|
+
partialMetadata.attributions = [tilejsonMetadata.attribution];
|
|
4280
|
+
}
|
|
4281
|
+
const metadata = {
|
|
4282
|
+
...partialMetadata,
|
|
4283
|
+
format: "pmtiles",
|
|
4284
|
+
formatVersion: header.specVersion,
|
|
4285
|
+
mimeType: decodeTileType(header.tileType),
|
|
4286
|
+
tileType: header.tileType,
|
|
4287
|
+
minZoom: header.minZoom,
|
|
4288
|
+
maxZoom: header.maxZoom,
|
|
4289
|
+
boundingBox: [
|
|
4290
|
+
[header.minLon, header.minLat],
|
|
4291
|
+
[header.maxLon, header.maxLat]
|
|
4292
|
+
],
|
|
4293
|
+
center: [header.centerLon, header.centerLat],
|
|
4294
|
+
centerZoom: header.centerZoom,
|
|
4295
|
+
etag: header.etag
|
|
4296
|
+
};
|
|
4297
|
+
if (tilejsonMetadata) {
|
|
4298
|
+
try {
|
|
4299
|
+
metadata.tileJSON = TileJSONLoader.parseTextSync?.(JSON.stringify(tilejsonMetadata)) || void 0;
|
|
4300
|
+
} catch (error) {
|
|
4301
|
+
metadata.tilejsonMetadata = tilejsonMetadata;
|
|
4302
|
+
}
|
|
4303
|
+
}
|
|
4304
|
+
if (options?.includeFormatHeader) {
|
|
4305
|
+
metadata.formatHeader = header;
|
|
4306
|
+
}
|
|
4307
|
+
return metadata;
|
|
4308
|
+
}
|
|
4309
|
+
function decodeTileType(tileType) {
|
|
4310
|
+
switch (tileType) {
|
|
4311
|
+
case TileType.Mvt:
|
|
4312
|
+
return "application/vnd.mapbox-vector-tile";
|
|
4313
|
+
case TileType.Png:
|
|
4314
|
+
return "image/png";
|
|
4315
|
+
case TileType.Jpeg:
|
|
4316
|
+
return "image/jpeg";
|
|
4317
|
+
case TileType.Webp:
|
|
4318
|
+
return "image/webp";
|
|
4319
|
+
case TileType.Avif:
|
|
4320
|
+
return "image/avif";
|
|
4321
|
+
default:
|
|
4322
|
+
return "application/octet-stream";
|
|
4323
|
+
}
|
|
4324
|
+
}
|
|
4325
|
+
var init_parse_pmtiles = __esm({
|
|
4326
|
+
"src/lib/parse-pmtiles.ts"() {
|
|
4327
|
+
init_dist();
|
|
4328
|
+
init_src4();
|
|
4329
|
+
}
|
|
4330
|
+
});
|
|
4331
|
+
|
|
4332
|
+
// src/pmtiles-source.ts
|
|
4333
|
+
var BlobSource, PMTilesSource;
|
|
4334
|
+
var init_pmtiles_source = __esm({
|
|
4335
|
+
"src/pmtiles-source.ts"() {
|
|
4336
|
+
init_src();
|
|
4337
|
+
init_src2();
|
|
4338
|
+
init_src4();
|
|
4339
|
+
init_dist();
|
|
4340
|
+
init_parse_pmtiles();
|
|
4341
|
+
BlobSource = class {
|
|
4342
|
+
constructor(blob, key) {
|
|
4343
|
+
this.blob = blob;
|
|
4344
|
+
this.key = key;
|
|
4345
|
+
}
|
|
4346
|
+
getKey() {
|
|
4347
|
+
return this.blob.url || "";
|
|
4348
|
+
}
|
|
4349
|
+
async getBytes(offset, length2, signal) {
|
|
4350
|
+
const slice = this.blob.slice(offset, offset + length2);
|
|
4351
|
+
const data = await slice.arrayBuffer();
|
|
4352
|
+
return {
|
|
4353
|
+
data
|
|
4354
|
+
};
|
|
4355
|
+
}
|
|
4356
|
+
};
|
|
4357
|
+
PMTilesSource = class extends DataSource {
|
|
4358
|
+
constructor(props) {
|
|
4359
|
+
super(props);
|
|
4360
|
+
this.props = props;
|
|
4361
|
+
const url = typeof props.url === "string" ? resolvePath(props.url) : new BlobSource(props.url, "pmtiles");
|
|
4362
|
+
this.pmtiles = new PMTiles(url);
|
|
4363
|
+
this.getTileData = this.getTileData.bind(this);
|
|
4364
|
+
this.metadata = this.getMetadata();
|
|
4365
|
+
}
|
|
4366
|
+
async getMetadata() {
|
|
4367
|
+
const pmtilesHeader = await this.pmtiles.getHeader();
|
|
4368
|
+
const pmtilesMetadata = await this.pmtiles.getMetadata();
|
|
4369
|
+
const metadata = parsePMTilesHeader(pmtilesHeader, pmtilesMetadata);
|
|
4370
|
+
if (this.props.attributions) {
|
|
4371
|
+
metadata.attributions = [...this.props.attributions, ...metadata.attributions || []];
|
|
4372
|
+
}
|
|
4373
|
+
return metadata;
|
|
4374
|
+
}
|
|
4375
|
+
async getTile(tileParams) {
|
|
4376
|
+
const { x: x3, y: y2, zoom: z } = tileParams;
|
|
4377
|
+
const rangeResponse = await this.pmtiles.getZxy(z, x3, y2);
|
|
4378
|
+
const arrayBuffer = rangeResponse?.data;
|
|
4379
|
+
if (!arrayBuffer) {
|
|
4380
|
+
return null;
|
|
4381
|
+
}
|
|
4382
|
+
return arrayBuffer;
|
|
4383
|
+
}
|
|
4384
|
+
async getTileData(tileParams) {
|
|
4385
|
+
const { x: x3, y: y2, z } = tileParams.index;
|
|
4386
|
+
const metadata = await this.metadata;
|
|
4387
|
+
switch (metadata.mimeType) {
|
|
4388
|
+
case "application/vnd.mapbox-vector-tile":
|
|
4389
|
+
return await this.getVectorTile({ x: x3, y: y2, zoom: z, layers: [] });
|
|
4390
|
+
default:
|
|
4391
|
+
return await this.getImageTile({ x: x3, y: y2, zoom: z, layers: [] });
|
|
4392
|
+
}
|
|
4393
|
+
}
|
|
4394
|
+
async getImageTile(tileParams) {
|
|
4395
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
4396
|
+
return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;
|
|
4397
|
+
}
|
|
4398
|
+
async getVectorTile(tileParams) {
|
|
4399
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
4400
|
+
const loadOptions = {
|
|
4401
|
+
shape: "geojson-table",
|
|
4402
|
+
mvt: {
|
|
4403
|
+
coordinates: "wgs84",
|
|
4404
|
+
tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.zoom },
|
|
4405
|
+
...this.loadOptions?.mvt
|
|
4406
|
+
},
|
|
4407
|
+
...this.loadOptions
|
|
4408
|
+
};
|
|
4409
|
+
return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;
|
|
4410
|
+
}
|
|
4411
|
+
};
|
|
4412
|
+
}
|
|
4413
|
+
});
|
|
4414
|
+
|
|
4415
|
+
// src/index.ts
|
|
4416
|
+
var src_exports = {};
|
|
4417
|
+
__export(src_exports, {
|
|
4418
|
+
PMTilesSource: () => PMTilesSource
|
|
4419
|
+
});
|
|
4420
|
+
var init_src5 = __esm({
|
|
4421
|
+
"src/index.ts"() {
|
|
4422
|
+
init_pmtiles_source();
|
|
4423
|
+
}
|
|
4424
|
+
});
|
|
4425
|
+
|
|
4426
|
+
// src/bundle.ts
|
|
4427
|
+
var require_bundle = __commonJS({
|
|
4428
|
+
"src/bundle.ts"(exports, module) {
|
|
4429
|
+
var moduleExports = (init_src5(), src_exports);
|
|
4430
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
4431
|
+
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
4432
|
+
}
|
|
4433
|
+
});
|
|
4434
|
+
require_bundle();
|
|
4435
|
+
})();
|
|
4436
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|