@loaders.gl/mvt 4.4.0-alpha.2 → 4.4.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/dist.dev.js +412 -39
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +414 -26
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/encode-mvt.d.ts +19 -0
- package/dist/lib/encode-mvt.d.ts.map +1 -0
- package/dist/lib/encode-mvt.js +15 -0
- package/dist/lib/encode-mvt.js.map +1 -0
- package/dist/lib/get-schemas-from-tilejson.js +1 -0
- package/dist/lib/get-schemas-from-tilejson.js.map +1 -0
- package/dist/lib/mapbox-vt-pbf/geojson-wrapper.d.ts +25 -0
- package/dist/lib/mapbox-vt-pbf/geojson-wrapper.d.ts.map +1 -0
- package/dist/lib/mapbox-vt-pbf/geojson-wrapper.js +73 -0
- package/dist/lib/mapbox-vt-pbf/geojson-wrapper.js.map +1 -0
- package/dist/lib/mapbox-vt-pbf/to-vector-tile.d.ts +52 -0
- package/dist/lib/mapbox-vt-pbf/to-vector-tile.d.ts.map +1 -0
- package/dist/lib/mapbox-vt-pbf/to-vector-tile.js +162 -0
- package/dist/lib/mapbox-vt-pbf/to-vector-tile.js.map +1 -0
- package/dist/lib/mvt-pbf/mvt-constants.d.ts.map +1 -0
- package/dist/lib/{pojo-parser → mvt-pbf}/mvt-constants.js +1 -0
- package/dist/lib/mvt-pbf/mvt-constants.js.map +1 -0
- package/dist/lib/mvt-pbf/mvt-types.d.ts.map +1 -0
- package/dist/lib/{pojo-parser → mvt-pbf}/mvt-types.js +1 -0
- package/dist/lib/mvt-pbf/mvt-types.js.map +1 -0
- package/dist/lib/mvt-pbf/parse-geometry-from-pbf.d.ts.map +1 -0
- package/dist/lib/{pojo-parser → mvt-pbf}/parse-geometry-from-pbf.js +1 -0
- package/dist/lib/mvt-pbf/parse-geometry-from-pbf.js.map +1 -0
- package/dist/lib/mvt-pbf/parse-mvt-from-pbf.d.ts.map +1 -0
- package/dist/lib/{pojo-parser → mvt-pbf}/parse-mvt-from-pbf.js +1 -0
- package/dist/lib/mvt-pbf/parse-mvt-from-pbf.js.map +1 -0
- package/dist/lib/mvt-pbf/write-mvt-to-pbf.d.ts +4 -0
- package/dist/lib/mvt-pbf/write-mvt-to-pbf.d.ts.map +1 -0
- package/dist/lib/mvt-pbf/write-mvt-to-pbf.js +130 -0
- package/dist/lib/mvt-pbf/write-mvt-to-pbf.js.map +1 -0
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +4 -1
- package/dist/lib/parse-mvt.js.map +1 -0
- package/dist/lib/parse-tilejson.js +1 -0
- package/dist/lib/parse-tilejson.js.map +1 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils/geometry-utils.js +1 -0
- package/dist/lib/utils/geometry-utils.js.map +1 -0
- package/dist/lib/vector-tile/vector-tile-feature.js +1 -0
- package/dist/lib/vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/lib/vector-tile/vector-tile-layer.js +1 -0
- package/dist/lib/vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/lib/vector-tile/vector-tile.js +1 -0
- package/dist/lib/vector-tile/vector-tile.js.map +1 -0
- package/dist/lib/vector-tiler/features/clip-features.js +1 -0
- package/dist/lib/vector-tiler/features/clip-features.js.map +1 -0
- package/dist/lib/vector-tiler/features/convert-feature.js +1 -0
- package/dist/lib/vector-tiler/features/convert-feature.js.map +1 -0
- package/dist/lib/vector-tiler/features/proto-feature.js +1 -0
- package/dist/lib/vector-tiler/features/proto-feature.js.map +1 -0
- package/dist/lib/vector-tiler/features/simplify-path.js +1 -0
- package/dist/lib/vector-tiler/features/simplify-path.js.map +1 -0
- package/dist/lib/vector-tiler/features/wrap-features.js +1 -0
- package/dist/lib/vector-tiler/features/wrap-features.js.map +1 -0
- package/dist/lib/vector-tiler/proto-tile.js +1 -0
- package/dist/lib/vector-tiler/proto-tile.js.map +1 -0
- package/dist/lib/vector-tiler/tile-to-geojson.js +1 -0
- package/dist/lib/vector-tiler/tile-to-geojson.js.map +1 -0
- package/dist/lib/vector-tiler/transform-tile.js +1 -0
- package/dist/lib/vector-tiler/transform-tile.js.map +1 -0
- package/dist/mvt-format.js +1 -0
- package/dist/mvt-format.js.map +1 -0
- package/dist/mvt-loader.js +2 -1
- package/dist/mvt-loader.js.map +1 -0
- package/dist/mvt-source.js +2 -1
- package/dist/mvt-source.js.map +1 -0
- package/dist/mvt-worker.js +6 -3
- package/dist/mvt-writer.d.ts +26 -0
- package/dist/mvt-writer.d.ts.map +1 -0
- package/dist/mvt-writer.js +32 -0
- package/dist/mvt-writer.js.map +1 -0
- package/dist/table-tile-source.js +1 -0
- package/dist/table-tile-source.js.map +1 -0
- package/dist/tilejson-loader.js +2 -1
- package/dist/tilejson-loader.js.map +1 -0
- package/dist/workers/mvt-worker.js +1 -0
- package/dist/workers/mvt-worker.js.map +1 -0
- package/package.json +6 -6
- package/src/index.ts +5 -0
- package/src/lib/encode-mvt.ts +31 -0
- package/src/lib/mapbox-vt-pbf/geojson-to-vt.ts.disabled +76 -0
- package/src/lib/mapbox-vt-pbf/geojson-wrapper.ts +89 -0
- package/src/lib/mapbox-vt-pbf/to-vector-tile.ts +229 -0
- package/src/lib/mvt-pbf/write-mvt-to-pbf.ts +158 -0
- package/src/lib/parse-mvt.ts +3 -1
- package/src/mvt-source.ts +1 -1
- package/src/mvt-writer.ts +35 -0
- package/dist/lib/pojo-parser/mvt-constants.d.ts.map +0 -1
- package/dist/lib/pojo-parser/mvt-types.d.ts.map +0 -1
- package/dist/lib/pojo-parser/parse-geometry-from-pbf.d.ts.map +0 -1
- package/dist/lib/pojo-parser/parse-mvt-from-pbf.d.ts.map +0 -1
- /package/dist/lib/{pojo-parser → mvt-pbf}/mvt-constants.d.ts +0 -0
- /package/dist/lib/{pojo-parser → mvt-pbf}/mvt-types.d.ts +0 -0
- /package/dist/lib/{pojo-parser → mvt-pbf}/parse-geometry-from-pbf.d.ts +0 -0
- /package/dist/lib/{pojo-parser → mvt-pbf}/parse-mvt-from-pbf.d.ts +0 -0
- /package/src/lib/{pojo-parser → mvt-pbf}/mvt-constants.ts +0 -0
- /package/src/lib/{pojo-parser → mvt-pbf}/mvt-types.ts +0 -0
- /package/src/lib/{pojo-parser → mvt-pbf}/parse-geometry-from-pbf.ts +0 -0
- /package/src/lib/{pojo-parser → mvt-pbf}/parse-mvt-from-pbf.ts +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @loaders.gl/mvt
|
|
2
2
|
|
|
3
|
-
This module contains a geometry loader for Mapbox Vector Tiles (MVT).
|
|
3
|
+
This module contains a geometry loader for Mapbox Vector Tiles (MVT) and a writer for generating MVT tiles from GeoJSON.
|
|
4
4
|
|
|
5
5
|
[loaders.gl](https://loaders.gl/docs) is a collection of framework-independent visualization-focused loaders (parsers).
|
|
6
|
+
|
|
7
|
+
## Writing
|
|
8
|
+
|
|
9
|
+
Use the `MVTWriter` with `@loaders.gl/core`'s `encode` helper to serialize GeoJSON into a Mapbox Vector Tile `ArrayBuffer`.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import {encode} from '@loaders.gl/core';
|
|
13
|
+
import {MVTWriter} from '@loaders.gl/mvt';
|
|
14
|
+
|
|
15
|
+
const arrayBuffer = await encode(geojson, MVTWriter, {
|
|
16
|
+
mvt: {layerName: 'my-layer', version: 2, extent: 4096}
|
|
17
|
+
});
|
|
18
|
+
```
|
package/dist/dist.dev.js
CHANGED
|
@@ -137,23 +137,23 @@ var __exports__ = (() => {
|
|
|
137
137
|
var require_pbf = __commonJS({
|
|
138
138
|
"../../node_modules/pbf/index.js"(exports, module) {
|
|
139
139
|
"use strict";
|
|
140
|
-
module.exports =
|
|
140
|
+
module.exports = Pbf2;
|
|
141
141
|
var ieee754 = require_ieee754();
|
|
142
|
-
function
|
|
142
|
+
function Pbf2(buf) {
|
|
143
143
|
this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
|
|
144
144
|
this.pos = 0;
|
|
145
145
|
this.type = 0;
|
|
146
146
|
this.length = this.buf.length;
|
|
147
147
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
148
|
+
Pbf2.Varint = 0;
|
|
149
|
+
Pbf2.Fixed64 = 1;
|
|
150
|
+
Pbf2.Bytes = 2;
|
|
151
|
+
Pbf2.Fixed32 = 5;
|
|
152
152
|
var SHIFT_LEFT_32 = (1 << 16) * (1 << 16);
|
|
153
153
|
var SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;
|
|
154
154
|
var TEXT_DECODER_MIN_LENGTH = 12;
|
|
155
155
|
var utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8");
|
|
156
|
-
|
|
156
|
+
Pbf2.prototype = {
|
|
157
157
|
destroy: function() {
|
|
158
158
|
this.buf = null;
|
|
159
159
|
},
|
|
@@ -251,7 +251,7 @@ var __exports__ = (() => {
|
|
|
251
251
|
},
|
|
252
252
|
// verbose for performance reasons; doesn't affect gzipped size
|
|
253
253
|
readPackedVarint: function(arr, isSigned) {
|
|
254
|
-
if (this.type !==
|
|
254
|
+
if (this.type !== Pbf2.Bytes)
|
|
255
255
|
return arr.push(this.readVarint(isSigned));
|
|
256
256
|
var end = readPackedEnd(this);
|
|
257
257
|
arr = arr || [];
|
|
@@ -260,7 +260,7 @@ var __exports__ = (() => {
|
|
|
260
260
|
return arr;
|
|
261
261
|
},
|
|
262
262
|
readPackedSVarint: function(arr) {
|
|
263
|
-
if (this.type !==
|
|
263
|
+
if (this.type !== Pbf2.Bytes)
|
|
264
264
|
return arr.push(this.readSVarint());
|
|
265
265
|
var end = readPackedEnd(this);
|
|
266
266
|
arr = arr || [];
|
|
@@ -269,7 +269,7 @@ var __exports__ = (() => {
|
|
|
269
269
|
return arr;
|
|
270
270
|
},
|
|
271
271
|
readPackedBoolean: function(arr) {
|
|
272
|
-
if (this.type !==
|
|
272
|
+
if (this.type !== Pbf2.Bytes)
|
|
273
273
|
return arr.push(this.readBoolean());
|
|
274
274
|
var end = readPackedEnd(this);
|
|
275
275
|
arr = arr || [];
|
|
@@ -278,7 +278,7 @@ var __exports__ = (() => {
|
|
|
278
278
|
return arr;
|
|
279
279
|
},
|
|
280
280
|
readPackedFloat: function(arr) {
|
|
281
|
-
if (this.type !==
|
|
281
|
+
if (this.type !== Pbf2.Bytes)
|
|
282
282
|
return arr.push(this.readFloat());
|
|
283
283
|
var end = readPackedEnd(this);
|
|
284
284
|
arr = arr || [];
|
|
@@ -287,7 +287,7 @@ var __exports__ = (() => {
|
|
|
287
287
|
return arr;
|
|
288
288
|
},
|
|
289
289
|
readPackedDouble: function(arr) {
|
|
290
|
-
if (this.type !==
|
|
290
|
+
if (this.type !== Pbf2.Bytes)
|
|
291
291
|
return arr.push(this.readDouble());
|
|
292
292
|
var end = readPackedEnd(this);
|
|
293
293
|
arr = arr || [];
|
|
@@ -296,7 +296,7 @@ var __exports__ = (() => {
|
|
|
296
296
|
return arr;
|
|
297
297
|
},
|
|
298
298
|
readPackedFixed32: function(arr) {
|
|
299
|
-
if (this.type !==
|
|
299
|
+
if (this.type !== Pbf2.Bytes)
|
|
300
300
|
return arr.push(this.readFixed32());
|
|
301
301
|
var end = readPackedEnd(this);
|
|
302
302
|
arr = arr || [];
|
|
@@ -305,7 +305,7 @@ var __exports__ = (() => {
|
|
|
305
305
|
return arr;
|
|
306
306
|
},
|
|
307
307
|
readPackedSFixed32: function(arr) {
|
|
308
|
-
if (this.type !==
|
|
308
|
+
if (this.type !== Pbf2.Bytes)
|
|
309
309
|
return arr.push(this.readSFixed32());
|
|
310
310
|
var end = readPackedEnd(this);
|
|
311
311
|
arr = arr || [];
|
|
@@ -314,7 +314,7 @@ var __exports__ = (() => {
|
|
|
314
314
|
return arr;
|
|
315
315
|
},
|
|
316
316
|
readPackedFixed64: function(arr) {
|
|
317
|
-
if (this.type !==
|
|
317
|
+
if (this.type !== Pbf2.Bytes)
|
|
318
318
|
return arr.push(this.readFixed64());
|
|
319
319
|
var end = readPackedEnd(this);
|
|
320
320
|
arr = arr || [];
|
|
@@ -323,7 +323,7 @@ var __exports__ = (() => {
|
|
|
323
323
|
return arr;
|
|
324
324
|
},
|
|
325
325
|
readPackedSFixed64: function(arr) {
|
|
326
|
-
if (this.type !==
|
|
326
|
+
if (this.type !== Pbf2.Bytes)
|
|
327
327
|
return arr.push(this.readSFixed64());
|
|
328
328
|
var end = readPackedEnd(this);
|
|
329
329
|
arr = arr || [];
|
|
@@ -333,14 +333,14 @@ var __exports__ = (() => {
|
|
|
333
333
|
},
|
|
334
334
|
skip: function(val) {
|
|
335
335
|
var type = val & 7;
|
|
336
|
-
if (type ===
|
|
336
|
+
if (type === Pbf2.Varint)
|
|
337
337
|
while (this.buf[this.pos++] > 127) {
|
|
338
338
|
}
|
|
339
|
-
else if (type ===
|
|
339
|
+
else if (type === Pbf2.Bytes)
|
|
340
340
|
this.pos = this.readVarint() + this.pos;
|
|
341
|
-
else if (type ===
|
|
341
|
+
else if (type === Pbf2.Fixed32)
|
|
342
342
|
this.pos += 4;
|
|
343
|
-
else if (type ===
|
|
343
|
+
else if (type === Pbf2.Fixed64)
|
|
344
344
|
this.pos += 8;
|
|
345
345
|
else
|
|
346
346
|
throw new Error("Unimplemented type: " + type);
|
|
@@ -453,7 +453,7 @@ var __exports__ = (() => {
|
|
|
453
453
|
this.pos += len;
|
|
454
454
|
},
|
|
455
455
|
writeMessage: function(tag, fn, obj) {
|
|
456
|
-
this.writeTag(tag,
|
|
456
|
+
this.writeTag(tag, Pbf2.Bytes);
|
|
457
457
|
this.writeRawMessage(fn, obj);
|
|
458
458
|
},
|
|
459
459
|
writePackedVarint: function(tag, arr) {
|
|
@@ -493,43 +493,43 @@ var __exports__ = (() => {
|
|
|
493
493
|
this.writeMessage(tag, writePackedSFixed64, arr);
|
|
494
494
|
},
|
|
495
495
|
writeBytesField: function(tag, buffer) {
|
|
496
|
-
this.writeTag(tag,
|
|
496
|
+
this.writeTag(tag, Pbf2.Bytes);
|
|
497
497
|
this.writeBytes(buffer);
|
|
498
498
|
},
|
|
499
499
|
writeFixed32Field: function(tag, val) {
|
|
500
|
-
this.writeTag(tag,
|
|
500
|
+
this.writeTag(tag, Pbf2.Fixed32);
|
|
501
501
|
this.writeFixed32(val);
|
|
502
502
|
},
|
|
503
503
|
writeSFixed32Field: function(tag, val) {
|
|
504
|
-
this.writeTag(tag,
|
|
504
|
+
this.writeTag(tag, Pbf2.Fixed32);
|
|
505
505
|
this.writeSFixed32(val);
|
|
506
506
|
},
|
|
507
507
|
writeFixed64Field: function(tag, val) {
|
|
508
|
-
this.writeTag(tag,
|
|
508
|
+
this.writeTag(tag, Pbf2.Fixed64);
|
|
509
509
|
this.writeFixed64(val);
|
|
510
510
|
},
|
|
511
511
|
writeSFixed64Field: function(tag, val) {
|
|
512
|
-
this.writeTag(tag,
|
|
512
|
+
this.writeTag(tag, Pbf2.Fixed64);
|
|
513
513
|
this.writeSFixed64(val);
|
|
514
514
|
},
|
|
515
515
|
writeVarintField: function(tag, val) {
|
|
516
|
-
this.writeTag(tag,
|
|
516
|
+
this.writeTag(tag, Pbf2.Varint);
|
|
517
517
|
this.writeVarint(val);
|
|
518
518
|
},
|
|
519
519
|
writeSVarintField: function(tag, val) {
|
|
520
|
-
this.writeTag(tag,
|
|
520
|
+
this.writeTag(tag, Pbf2.Varint);
|
|
521
521
|
this.writeSVarint(val);
|
|
522
522
|
},
|
|
523
523
|
writeStringField: function(tag, str) {
|
|
524
|
-
this.writeTag(tag,
|
|
524
|
+
this.writeTag(tag, Pbf2.Bytes);
|
|
525
525
|
this.writeString(str);
|
|
526
526
|
},
|
|
527
527
|
writeFloatField: function(tag, val) {
|
|
528
|
-
this.writeTag(tag,
|
|
528
|
+
this.writeTag(tag, Pbf2.Fixed32);
|
|
529
529
|
this.writeFloat(val);
|
|
530
530
|
},
|
|
531
531
|
writeDoubleField: function(tag, val) {
|
|
532
|
-
this.writeTag(tag,
|
|
532
|
+
this.writeTag(tag, Pbf2.Fixed64);
|
|
533
533
|
this.writeDouble(val);
|
|
534
534
|
},
|
|
535
535
|
writeBooleanField: function(tag, val) {
|
|
@@ -565,7 +565,7 @@ var __exports__ = (() => {
|
|
|
565
565
|
throw new Error("Expected varint not more than 10 bytes");
|
|
566
566
|
}
|
|
567
567
|
function readPackedEnd(pbf) {
|
|
568
|
-
return pbf.type ===
|
|
568
|
+
return pbf.type === Pbf2.Bytes ? pbf.readVarint() + pbf.pos : pbf.pos + 1;
|
|
569
569
|
}
|
|
570
570
|
function toNum(low, high, isSigned) {
|
|
571
571
|
if (isSigned) {
|
|
@@ -796,6 +796,7 @@ var __exports__ = (() => {
|
|
|
796
796
|
MVTLoader: () => MVTLoader,
|
|
797
797
|
MVTSource: () => MVTSource,
|
|
798
798
|
MVTWorkerLoader: () => MVTWorkerLoader,
|
|
799
|
+
MVTWriter: () => MVTWriter,
|
|
799
800
|
TableTileSource: () => TableTileSource,
|
|
800
801
|
TileJSONLoader: () => TileJSONLoader
|
|
801
802
|
});
|
|
@@ -2713,6 +2714,14 @@ var __exports__ = (() => {
|
|
|
2713
2714
|
return filename;
|
|
2714
2715
|
}
|
|
2715
2716
|
|
|
2717
|
+
// ../loader-utils/src/lib/binary-utils/memory-conversion-utils.ts
|
|
2718
|
+
function copyToArrayBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
2719
|
+
const view = new Uint8Array(buffer, byteOffset, byteLength);
|
|
2720
|
+
const copy2 = new Uint8Array(view.length);
|
|
2721
|
+
copy2.set(view);
|
|
2722
|
+
return copy2.buffer;
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2716
2725
|
// ../loader-utils/src/lib/sources/data-source.ts
|
|
2717
2726
|
var _DataSource = class {
|
|
2718
2727
|
optionsType;
|
|
@@ -2765,7 +2774,7 @@ var __exports__ = (() => {
|
|
|
2765
2774
|
}
|
|
2766
2775
|
});
|
|
2767
2776
|
function getFetchFunction(options) {
|
|
2768
|
-
const fetchFunction = options?.fetch;
|
|
2777
|
+
const fetchFunction = options?.core?.fetch;
|
|
2769
2778
|
if (fetchFunction && typeof fetchFunction === "function") {
|
|
2770
2779
|
return (url, fetchOptions2) => fetchFunction(url, fetchOptions2);
|
|
2771
2780
|
}
|
|
@@ -3476,8 +3485,368 @@ var __exports__ = (() => {
|
|
|
3476
3485
|
binary: true
|
|
3477
3486
|
};
|
|
3478
3487
|
|
|
3479
|
-
//
|
|
3488
|
+
// src/lib/mapbox-vt-pbf/to-vector-tile.ts
|
|
3489
|
+
var import_pbf2 = __toESM(require_pbf(), 1);
|
|
3490
|
+
|
|
3491
|
+
// src/lib/mvt-pbf/write-mvt-to-pbf.ts
|
|
3492
|
+
function writeMVT(tile, pbf) {
|
|
3493
|
+
for (const key in tile.layers) {
|
|
3494
|
+
const context = {
|
|
3495
|
+
layer: tile.layers[key],
|
|
3496
|
+
keys: [],
|
|
3497
|
+
values: [],
|
|
3498
|
+
keycache: {},
|
|
3499
|
+
valuecache: {}
|
|
3500
|
+
};
|
|
3501
|
+
pbf.writeMessage(3 /* layers */, writeLayer, context);
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3504
|
+
function writeLayer(context, pbf) {
|
|
3505
|
+
const { layer } = context;
|
|
3506
|
+
pbf.writeVarintField(15 /* version */, layer.version || 1);
|
|
3507
|
+
pbf.writeStringField(1 /* name */, layer.name || "");
|
|
3508
|
+
pbf.writeVarintField(5 /* extent */, layer.extent || 4096);
|
|
3509
|
+
for (let i = 0; i < layer.length; i++) {
|
|
3510
|
+
context.feature = layer.feature(i);
|
|
3511
|
+
pbf.writeMessage(2 /* features */, writeFeature, context);
|
|
3512
|
+
}
|
|
3513
|
+
const keys = context.keys;
|
|
3514
|
+
for (let i = 0; i < keys.length; i++) {
|
|
3515
|
+
pbf.writeStringField(3 /* keys */, keys[i]);
|
|
3516
|
+
}
|
|
3517
|
+
const values = context.values;
|
|
3518
|
+
for (let i = 0; i < values.length; i++) {
|
|
3519
|
+
pbf.writeMessage(4 /* values */, writeValue, values[i]);
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
function writeFeature(context, pbf) {
|
|
3523
|
+
const feature = context.feature;
|
|
3524
|
+
if (feature.id !== void 0) {
|
|
3525
|
+
pbf.writeVarintField(1 /* id */, feature.id);
|
|
3526
|
+
}
|
|
3527
|
+
pbf.writeMessage(2 /* tags */, writeProperties, context);
|
|
3528
|
+
pbf.writeVarintField(3 /* type */, feature.type);
|
|
3529
|
+
pbf.writeMessage(4 /* geometry */, writeGeometry, feature);
|
|
3530
|
+
}
|
|
3531
|
+
function writeProperties(context, pbf) {
|
|
3532
|
+
const feature = context.feature;
|
|
3533
|
+
const { keys, values, keycache, valuecache } = context;
|
|
3534
|
+
for (const key in feature.properties) {
|
|
3535
|
+
let keyIndex = keycache[key];
|
|
3536
|
+
if (typeof keyIndex === "undefined") {
|
|
3537
|
+
keys.push(key);
|
|
3538
|
+
keyIndex = keys.length - 1;
|
|
3539
|
+
keycache[key] = keyIndex;
|
|
3540
|
+
}
|
|
3541
|
+
pbf.writeVarint(keyIndex);
|
|
3542
|
+
let value = feature.properties[key];
|
|
3543
|
+
const type = typeof value;
|
|
3544
|
+
if (type !== "string" && type !== "boolean" && type !== "number") {
|
|
3545
|
+
value = JSON.stringify(value);
|
|
3546
|
+
}
|
|
3547
|
+
const valueKey = `${type}:${value}`;
|
|
3548
|
+
let valueIndex = valuecache[valueKey];
|
|
3549
|
+
if (typeof valueIndex === "undefined") {
|
|
3550
|
+
values.push(value);
|
|
3551
|
+
valueIndex = values.length - 1;
|
|
3552
|
+
valuecache[valueKey] = valueIndex;
|
|
3553
|
+
}
|
|
3554
|
+
pbf.writeVarint(valueIndex);
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
function command(cmd, length) {
|
|
3558
|
+
return (length << 3) + (cmd & 7);
|
|
3559
|
+
}
|
|
3560
|
+
function zigzag(num) {
|
|
3561
|
+
return num << 1 ^ num >> 31;
|
|
3562
|
+
}
|
|
3563
|
+
function writeGeometry(feature, pbf) {
|
|
3564
|
+
const geometry = feature.loadGeometry();
|
|
3565
|
+
const type = feature.type;
|
|
3566
|
+
let x = 0;
|
|
3567
|
+
let y = 0;
|
|
3568
|
+
const rings = geometry.length;
|
|
3569
|
+
for (let r = 0; r < rings; r++) {
|
|
3570
|
+
const ring = geometry[r];
|
|
3571
|
+
let count = 1;
|
|
3572
|
+
if (type === 1) {
|
|
3573
|
+
count = ring.length;
|
|
3574
|
+
}
|
|
3575
|
+
pbf.writeVarint(command(1, count));
|
|
3576
|
+
const lineCount = type === 3 ? ring.length - 1 : ring.length;
|
|
3577
|
+
for (let i = 0; i < lineCount; i++) {
|
|
3578
|
+
if (i === 1 && type !== 1) {
|
|
3579
|
+
pbf.writeVarint(command(2, lineCount - 1));
|
|
3580
|
+
}
|
|
3581
|
+
const dx = ring[i].x - x;
|
|
3582
|
+
const dy = ring[i].y - y;
|
|
3583
|
+
pbf.writeVarint(zigzag(dx));
|
|
3584
|
+
pbf.writeVarint(zigzag(dy));
|
|
3585
|
+
x += dx;
|
|
3586
|
+
y += dy;
|
|
3587
|
+
}
|
|
3588
|
+
if (type === 3) {
|
|
3589
|
+
pbf.writeVarint(command(7, 1));
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
function writeValue(value, pbf) {
|
|
3594
|
+
switch (typeof value) {
|
|
3595
|
+
case "string":
|
|
3596
|
+
pbf.writeStringField(1, value);
|
|
3597
|
+
break;
|
|
3598
|
+
case "boolean":
|
|
3599
|
+
pbf.writeBooleanField(7, value);
|
|
3600
|
+
break;
|
|
3601
|
+
case "number":
|
|
3602
|
+
if (value % 1 !== 0) {
|
|
3603
|
+
pbf.writeDoubleField(3, value);
|
|
3604
|
+
} else if (value < 0) {
|
|
3605
|
+
pbf.writeSVarintField(6, value);
|
|
3606
|
+
} else {
|
|
3607
|
+
pbf.writeVarintField(5, value);
|
|
3608
|
+
}
|
|
3609
|
+
break;
|
|
3610
|
+
default:
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
// src/lib/mapbox-vt-pbf/geojson-wrapper.ts
|
|
3615
|
+
var Point = class {
|
|
3616
|
+
x;
|
|
3617
|
+
y;
|
|
3618
|
+
constructor(x, y) {
|
|
3619
|
+
this.x = x;
|
|
3620
|
+
this.y = y;
|
|
3621
|
+
}
|
|
3622
|
+
};
|
|
3623
|
+
var GeoJSONWrapper = class {
|
|
3624
|
+
options;
|
|
3625
|
+
features;
|
|
3626
|
+
length;
|
|
3627
|
+
constructor(features2, options = {}) {
|
|
3628
|
+
this.options = options;
|
|
3629
|
+
this.features = features2;
|
|
3630
|
+
this.length = features2.length;
|
|
3631
|
+
}
|
|
3632
|
+
feature(index) {
|
|
3633
|
+
return new FeatureWrapper(this.features[index], this.options.extent);
|
|
3634
|
+
}
|
|
3635
|
+
};
|
|
3636
|
+
var FeatureWrapper = class {
|
|
3637
|
+
id;
|
|
3638
|
+
type;
|
|
3639
|
+
rawGeometry;
|
|
3640
|
+
properties;
|
|
3641
|
+
extent;
|
|
3642
|
+
geometry = [];
|
|
3643
|
+
constructor(feature, extent) {
|
|
3644
|
+
this.id = typeof feature.id === "number" ? feature.id : void 0;
|
|
3645
|
+
this.type = feature.type;
|
|
3646
|
+
this.rawGeometry = feature.type === 1 ? [feature.geometry] : feature.geometry;
|
|
3647
|
+
this.properties = feature.tags;
|
|
3648
|
+
this.extent = extent || 4096;
|
|
3649
|
+
}
|
|
3650
|
+
loadGeometry() {
|
|
3651
|
+
const rings = this.rawGeometry;
|
|
3652
|
+
this.geometry = [];
|
|
3653
|
+
for (const ring of rings) {
|
|
3654
|
+
const newRing = [];
|
|
3655
|
+
for (const coord of ring) {
|
|
3656
|
+
newRing.push(new Point(coord[0], coord[1]));
|
|
3657
|
+
}
|
|
3658
|
+
this.geometry.push(newRing);
|
|
3659
|
+
}
|
|
3660
|
+
return this.geometry;
|
|
3661
|
+
}
|
|
3662
|
+
bbox() {
|
|
3663
|
+
if (!this.geometry) {
|
|
3664
|
+
this.loadGeometry();
|
|
3665
|
+
}
|
|
3666
|
+
const rings = this.geometry;
|
|
3667
|
+
let x1 = Infinity;
|
|
3668
|
+
let x2 = -Infinity;
|
|
3669
|
+
let y1 = Infinity;
|
|
3670
|
+
let y2 = -Infinity;
|
|
3671
|
+
for (const ring of rings) {
|
|
3672
|
+
for (const coord of ring) {
|
|
3673
|
+
x1 = Math.min(x1, coord.x);
|
|
3674
|
+
x2 = Math.max(x2, coord.x);
|
|
3675
|
+
y1 = Math.min(y1, coord.y);
|
|
3676
|
+
y2 = Math.max(y2, coord.y);
|
|
3677
|
+
}
|
|
3678
|
+
}
|
|
3679
|
+
return [x1, y1, x2, y2];
|
|
3680
|
+
}
|
|
3681
|
+
// toGeoJSON(x, y, z) {
|
|
3682
|
+
// return VectorTileFeature.prototype.toGeoJSON.call(this, x, y, z);
|
|
3683
|
+
// }
|
|
3684
|
+
};
|
|
3685
|
+
|
|
3686
|
+
// src/lib/mapbox-vt-pbf/to-vector-tile.ts
|
|
3687
|
+
function fromGeojson(geojson, options) {
|
|
3688
|
+
options = options || {};
|
|
3689
|
+
geojson = normalizeGeojson(geojson);
|
|
3690
|
+
const extent = options.extent || 4096;
|
|
3691
|
+
const features2 = convertFeaturesToVectorTileFeatures(geojson.features, extent, options.tileIndex);
|
|
3692
|
+
const layer = new GeoJSONWrapper(features2, { ...options, extent });
|
|
3693
|
+
layer.name = options.layerName || "geojsonLayer";
|
|
3694
|
+
layer.version = options.version || 1;
|
|
3695
|
+
layer.extent = options.extent || 4096;
|
|
3696
|
+
return fromVectorTileJs({ layers: { [layer.name]: layer } });
|
|
3697
|
+
}
|
|
3698
|
+
function fromVectorTileJs(tile) {
|
|
3699
|
+
const pbf = new import_pbf2.default();
|
|
3700
|
+
writeMVT(tile, pbf);
|
|
3701
|
+
const uint8Array = pbf.finish();
|
|
3702
|
+
return copyToArrayBuffer(
|
|
3703
|
+
uint8Array.buffer,
|
|
3704
|
+
uint8Array.byteOffset,
|
|
3705
|
+
uint8Array.byteOffset + uint8Array.byteLength
|
|
3706
|
+
);
|
|
3707
|
+
}
|
|
3708
|
+
function normalizeGeojson(geojson) {
|
|
3709
|
+
if (Array.isArray(geojson)) {
|
|
3710
|
+
return {
|
|
3711
|
+
type: "FeatureCollection",
|
|
3712
|
+
features: geojson
|
|
3713
|
+
};
|
|
3714
|
+
}
|
|
3715
|
+
if (geojson.type === "Feature") {
|
|
3716
|
+
return {
|
|
3717
|
+
type: "FeatureCollection",
|
|
3718
|
+
features: [geojson]
|
|
3719
|
+
};
|
|
3720
|
+
}
|
|
3721
|
+
throw new Error("Invalid GeoJSON object");
|
|
3722
|
+
}
|
|
3723
|
+
function convertFeaturesToVectorTileFeatures(features2, extent, tileIndex) {
|
|
3724
|
+
if (features2.every(isVectorTileFeature)) {
|
|
3725
|
+
return features2;
|
|
3726
|
+
}
|
|
3727
|
+
return features2.map((feature) => convertFeatureToVectorTile(feature, extent, tileIndex));
|
|
3728
|
+
}
|
|
3729
|
+
function convertFeatureToVectorTile(feature, extent, tileIndex) {
|
|
3730
|
+
const geometry = feature.geometry;
|
|
3731
|
+
const type = getVectorTileType(geometry.type);
|
|
3732
|
+
return {
|
|
3733
|
+
id: typeof feature.id === "number" ? feature.id : void 0,
|
|
3734
|
+
type,
|
|
3735
|
+
geometry: projectGeometryToTileSpace(geometry, extent, tileIndex),
|
|
3736
|
+
tags: feature.properties || {}
|
|
3737
|
+
};
|
|
3738
|
+
}
|
|
3739
|
+
function projectGeometryToTileSpace(geometry, extent, tileIndex) {
|
|
3740
|
+
switch (geometry.type) {
|
|
3741
|
+
case "Point":
|
|
3742
|
+
return [projectPointToTile(geometry.coordinates, extent, tileIndex)];
|
|
3743
|
+
case "MultiPoint":
|
|
3744
|
+
return geometry.coordinates.map(
|
|
3745
|
+
(coord) => projectPointToTile(coord, extent, tileIndex)
|
|
3746
|
+
);
|
|
3747
|
+
case "LineString":
|
|
3748
|
+
return [
|
|
3749
|
+
geometry.coordinates.map(
|
|
3750
|
+
(coord) => projectPointToTile(coord, extent, tileIndex)
|
|
3751
|
+
)
|
|
3752
|
+
];
|
|
3753
|
+
case "MultiLineString":
|
|
3754
|
+
return geometry.coordinates.map(
|
|
3755
|
+
(line) => line.map((coord) => projectPointToTile(coord, extent, tileIndex))
|
|
3756
|
+
);
|
|
3757
|
+
case "Polygon":
|
|
3758
|
+
return geometry.coordinates.map(
|
|
3759
|
+
(ring) => ring.map((coord) => projectPointToTile(coord, extent, tileIndex))
|
|
3760
|
+
);
|
|
3761
|
+
case "MultiPolygon":
|
|
3762
|
+
return geometry.coordinates.flatMap(
|
|
3763
|
+
(polygon) => polygon.map(
|
|
3764
|
+
(ring) => ring.map((coord) => projectPointToTile(coord, extent, tileIndex))
|
|
3765
|
+
)
|
|
3766
|
+
);
|
|
3767
|
+
default:
|
|
3768
|
+
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
3769
|
+
}
|
|
3770
|
+
}
|
|
3771
|
+
function projectPointToTile(point, extent, tileIndex) {
|
|
3772
|
+
if (isNormalizedPoint(point)) {
|
|
3773
|
+
return [Math.round(point[0] * extent), Math.round(point[1] * extent)];
|
|
3774
|
+
}
|
|
3775
|
+
if (tileIndex && isLngLatPoint(point)) {
|
|
3776
|
+
return projectLngLatToTile(point, tileIndex, extent);
|
|
3777
|
+
}
|
|
3778
|
+
return [Math.round(point[0]), Math.round(point[1])];
|
|
3779
|
+
}
|
|
3780
|
+
function isNormalizedPoint(point) {
|
|
3781
|
+
return Math.abs(point[0]) <= 1 && Math.abs(point[1]) <= 1;
|
|
3782
|
+
}
|
|
3783
|
+
function isLngLatPoint(point) {
|
|
3784
|
+
return Math.abs(point[0]) <= 180 && Math.abs(point[1]) <= 90;
|
|
3785
|
+
}
|
|
3786
|
+
function projectLngLatToTile(point, tileIndex, extent) {
|
|
3787
|
+
const [lng, lat] = point;
|
|
3788
|
+
const { x, y, z } = tileIndex;
|
|
3789
|
+
const size = extent * Math.pow(2, z);
|
|
3790
|
+
const x0 = extent * x;
|
|
3791
|
+
const y0 = extent * y;
|
|
3792
|
+
const worldX = (lng + 180) / 360 * size;
|
|
3793
|
+
const worldY = (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 180 / 2))) * size / 360;
|
|
3794
|
+
return [Math.round(worldX - x0), Math.round(worldY - y0)];
|
|
3795
|
+
}
|
|
3796
|
+
function isVectorTileFeature(feature) {
|
|
3797
|
+
return typeof feature?.type === "number" && Array.isArray(feature.geometry);
|
|
3798
|
+
}
|
|
3799
|
+
function getVectorTileType(type) {
|
|
3800
|
+
switch (type) {
|
|
3801
|
+
case "Point":
|
|
3802
|
+
case "MultiPoint":
|
|
3803
|
+
return 1;
|
|
3804
|
+
case "LineString":
|
|
3805
|
+
case "MultiLineString":
|
|
3806
|
+
return 2;
|
|
3807
|
+
case "Polygon":
|
|
3808
|
+
case "MultiPolygon":
|
|
3809
|
+
return 3;
|
|
3810
|
+
default:
|
|
3811
|
+
throw new Error(`Unknown geometry type: ${type}`);
|
|
3812
|
+
}
|
|
3813
|
+
}
|
|
3814
|
+
|
|
3815
|
+
// src/lib/encode-mvt.ts
|
|
3816
|
+
function encodeMVT(data, options) {
|
|
3817
|
+
const { mvt } = options || {};
|
|
3818
|
+
const encodeOptions = {
|
|
3819
|
+
layerName: mvt?.layerName || "geojsonLayer",
|
|
3820
|
+
version: mvt?.version || 1,
|
|
3821
|
+
extent: mvt?.extent || 4096,
|
|
3822
|
+
tileIndex: mvt?.tileIndex
|
|
3823
|
+
};
|
|
3824
|
+
return fromGeojson(data, encodeOptions);
|
|
3825
|
+
}
|
|
3826
|
+
|
|
3827
|
+
// src/mvt-writer.ts
|
|
3480
3828
|
var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3829
|
+
var MVTWriter = {
|
|
3830
|
+
...MVTFormat,
|
|
3831
|
+
version: VERSION5,
|
|
3832
|
+
binary: true,
|
|
3833
|
+
options: {
|
|
3834
|
+
mvt: {
|
|
3835
|
+
layerName: "geojsonLayer",
|
|
3836
|
+
version: 1,
|
|
3837
|
+
extent: 4096
|
|
3838
|
+
}
|
|
3839
|
+
},
|
|
3840
|
+
async encode(data, options) {
|
|
3841
|
+
return encodeMVT(data, options);
|
|
3842
|
+
},
|
|
3843
|
+
encodeSync(data, options) {
|
|
3844
|
+
return encodeMVT(data, options);
|
|
3845
|
+
}
|
|
3846
|
+
};
|
|
3847
|
+
|
|
3848
|
+
// ../images/src/lib/utils/version.ts
|
|
3849
|
+
var VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
3481
3850
|
|
|
3482
3851
|
// ../images/src/lib/category-api/image-type.ts
|
|
3483
3852
|
var parseImageNode = globalThis.loaders?.parseImageNode;
|
|
@@ -3615,7 +3984,6 @@ var __exports__ = (() => {
|
|
|
3615
3984
|
}
|
|
3616
3985
|
|
|
3617
3986
|
// ../images/src/lib/parsers/parse-to-image-bitmap.ts
|
|
3618
|
-
var EMPTY_OBJECT = {};
|
|
3619
3987
|
var imagebitmapOptionsSupported = true;
|
|
3620
3988
|
async function parseToImageBitmap(arrayBuffer, options, url) {
|
|
3621
3989
|
let blob;
|
|
@@ -3643,8 +4011,13 @@ var __exports__ = (() => {
|
|
|
3643
4011
|
return await createImageBitmap(blob);
|
|
3644
4012
|
}
|
|
3645
4013
|
function isEmptyObject(object) {
|
|
3646
|
-
|
|
3647
|
-
return
|
|
4014
|
+
if (!object) {
|
|
4015
|
+
return true;
|
|
4016
|
+
}
|
|
4017
|
+
for (const key in object) {
|
|
4018
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
4019
|
+
return false;
|
|
4020
|
+
}
|
|
3648
4021
|
}
|
|
3649
4022
|
return true;
|
|
3650
4023
|
}
|
|
@@ -3875,7 +4248,7 @@ var __exports__ = (() => {
|
|
|
3875
4248
|
id: "image",
|
|
3876
4249
|
module: "images",
|
|
3877
4250
|
name: "Images",
|
|
3878
|
-
version:
|
|
4251
|
+
version: VERSION6,
|
|
3879
4252
|
mimeTypes: MIME_TYPES,
|
|
3880
4253
|
extensions: EXTENSIONS,
|
|
3881
4254
|
parse: parseImage,
|
|
@@ -3982,8 +4355,8 @@ var __exports__ = (() => {
|
|
|
3982
4355
|
}
|
|
3983
4356
|
async _parseVectorTile(arrayBuffer, tileParams) {
|
|
3984
4357
|
const loadOptions = {
|
|
3985
|
-
shape: "geojson-table",
|
|
3986
4358
|
mvt: {
|
|
4359
|
+
shape: "geojson-table",
|
|
3987
4360
|
coordinates: "wgs84",
|
|
3988
4361
|
tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.z },
|
|
3989
4362
|
...this.loadOptions?.mvt
|