@loaders.gl/mvt 3.1.8 → 3.2.0-alpha.3

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/dist/dist.min.js CHANGED
@@ -29,531 +29,231 @@
29
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
30
  };
31
31
 
32
- // src/helpers/mapbox-util-functions.ts
33
- function classifyRings(rings) {
34
- const len = rings.length;
35
- if (len <= 1)
36
- return [rings];
37
- const polygons = [];
38
- let polygon;
39
- let ccw;
40
- for (let i2 = 0; i2 < len; i2++) {
41
- const area2 = signedArea(rings[i2]);
42
- if (area2 === 0)
43
- continue;
44
- if (ccw === void 0)
45
- ccw = area2 < 0;
46
- if (ccw === area2 < 0) {
47
- if (polygon)
48
- polygons.push(polygon);
49
- polygon = [rings[i2]];
50
- } else if (polygon)
51
- polygon.push(rings[i2]);
32
+ // ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
33
+ function getPolygonSignedArea(points, options = {}) {
34
+ const {
35
+ start = 0,
36
+ end = points.length
37
+ } = options;
38
+ const dim = options.size || 2;
39
+ let area2 = 0;
40
+ for (let i2 = start, j = end - dim; i2 < end; i2 += dim) {
41
+ area2 += (points[i2] - points[j]) * (points[i2 + 1] + points[j + 1]);
42
+ j = i2;
52
43
  }
53
- if (polygon)
54
- polygons.push(polygon);
55
- return polygons;
44
+ return area2 / 2;
56
45
  }
57
- function signedArea(ring) {
58
- let sum = 0;
59
- for (let i2 = 0, j = ring.length - 1, p1, p2; i2 < ring.length; j = i2++) {
60
- p1 = ring[i2];
61
- p2 = ring[j];
62
- sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
46
+ var init_polygon_utils = __esm({
47
+ "../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
63
48
  }
64
- return sum;
49
+ });
50
+
51
+ // ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
52
+ var init_polygon = __esm({
53
+ "../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
54
+ init_polygon_utils();
55
+ }
56
+ });
57
+
58
+ // ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
59
+ function earcut(data, holeIndices, dim, areas) {
60
+ dim = dim || 2;
61
+ const hasHoles = holeIndices && holeIndices.length;
62
+ const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
63
+ let outerNode = linkedList(data, 0, outerLen, dim, true, areas && areas[0]);
64
+ const triangles = [];
65
+ if (!outerNode || outerNode.next === outerNode.prev)
66
+ return triangles;
67
+ let invSize;
68
+ let maxX;
69
+ let maxY;
70
+ let minX;
71
+ let minY;
72
+ let x2;
73
+ let y2;
74
+ if (hasHoles)
75
+ outerNode = eliminateHoles(data, holeIndices, outerNode, dim, areas);
76
+ if (data.length > 80 * dim) {
77
+ minX = maxX = data[0];
78
+ minY = maxY = data[1];
79
+ for (let i2 = dim; i2 < outerLen; i2 += dim) {
80
+ x2 = data[i2];
81
+ y2 = data[i2 + 1];
82
+ if (x2 < minX)
83
+ minX = x2;
84
+ if (y2 < minY)
85
+ minY = y2;
86
+ if (x2 > maxX)
87
+ maxX = x2;
88
+ if (y2 > maxY)
89
+ maxY = y2;
90
+ }
91
+ invSize = Math.max(maxX - minX, maxY - minY);
92
+ invSize = invSize !== 0 ? 1 / invSize : 0;
93
+ }
94
+ earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
95
+ return triangles;
65
96
  }
66
- function readFeature(tag, feature, pbf) {
67
- if (feature && pbf) {
68
- if (tag === 1)
69
- feature.id = pbf.readVarint();
70
- else if (tag === 2)
71
- readTag(pbf, feature);
72
- else if (tag === 3)
73
- feature.type = pbf.readVarint();
74
- else if (tag === 4)
75
- feature._geometry = pbf.pos;
97
+ function linkedList(data, start, end, dim, clockwise, area2) {
98
+ let i2;
99
+ let last;
100
+ if (area2 === void 0) {
101
+ area2 = getPolygonSignedArea(data, {
102
+ start,
103
+ end,
104
+ size: dim
105
+ });
106
+ }
107
+ if (clockwise === area2 < 0) {
108
+ for (i2 = start; i2 < end; i2 += dim)
109
+ last = insertNode(i2, data[i2], data[i2 + 1], last);
110
+ } else {
111
+ for (i2 = end - dim; i2 >= start; i2 -= dim)
112
+ last = insertNode(i2, data[i2], data[i2 + 1], last);
113
+ }
114
+ if (last && equals(last, last.next)) {
115
+ removeNode(last);
116
+ last = last.next;
76
117
  }
118
+ return last;
77
119
  }
78
- function readTag(pbf, feature) {
79
- const end = pbf.readVarint() + pbf.pos;
80
- while (pbf.pos < end) {
81
- const key = feature._keys[pbf.readVarint()];
82
- const value = feature._values[pbf.readVarint()];
83
- feature.properties[key] = value;
120
+ function filterPoints(start, end) {
121
+ if (!start)
122
+ return start;
123
+ if (!end)
124
+ end = start;
125
+ let p = start;
126
+ let again;
127
+ do {
128
+ again = false;
129
+ if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
130
+ removeNode(p);
131
+ p = end = p.prev;
132
+ if (p === p.next)
133
+ break;
134
+ again = true;
135
+ } else {
136
+ p = p.next;
137
+ }
138
+ } while (again || p !== end);
139
+ return end;
140
+ }
141
+ function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
142
+ if (!ear)
143
+ return;
144
+ if (!pass && invSize)
145
+ indexCurve(ear, minX, minY, invSize);
146
+ let stop = ear;
147
+ let prev;
148
+ let next;
149
+ while (ear.prev !== ear.next) {
150
+ prev = ear.prev;
151
+ next = ear.next;
152
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
153
+ triangles.push(prev.i / dim);
154
+ triangles.push(ear.i / dim);
155
+ triangles.push(next.i / dim);
156
+ removeNode(ear);
157
+ ear = next.next;
158
+ stop = next.next;
159
+ continue;
160
+ }
161
+ ear = next;
162
+ if (ear === stop) {
163
+ if (!pass) {
164
+ earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
165
+ } else if (pass === 1) {
166
+ ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
167
+ earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
168
+ } else if (pass === 2) {
169
+ splitEarcut(ear, triangles, dim, minX, minY, invSize);
170
+ }
171
+ break;
172
+ }
84
173
  }
85
174
  }
86
- var init_mapbox_util_functions = __esm({
87
- "src/helpers/mapbox-util-functions.ts"() {
175
+ function isEar(ear) {
176
+ const a = ear.prev;
177
+ const b = ear;
178
+ const c = ear.next;
179
+ if (area(a, b, c) >= 0)
180
+ return false;
181
+ let p = ear.next.next;
182
+ while (p !== ear.prev) {
183
+ 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)
184
+ return false;
185
+ p = p.next;
88
186
  }
89
- });
90
-
91
- // src/lib/mapbox-vector-tile/vector-tile-feature.ts
92
- var VectorTileFeature;
93
- var init_vector_tile_feature = __esm({
94
- "src/lib/mapbox-vector-tile/vector-tile-feature.ts"() {
95
- init_mapbox_util_functions();
96
- VectorTileFeature = class {
97
- static get types() {
98
- return ["Unknown", "Point", "LineString", "Polygon"];
99
- }
100
- constructor(pbf, end, extent, keys, values) {
101
- this.properties = {};
102
- this.extent = extent;
103
- this.type = 0;
104
- this.id = null;
105
- this._pbf = pbf;
106
- this._geometry = -1;
107
- this._keys = keys;
108
- this._values = values;
109
- pbf.readFields(readFeature, this, end);
110
- }
111
- loadGeometry() {
112
- const pbf = this._pbf;
113
- pbf.pos = this._geometry;
114
- const end = pbf.readVarint() + pbf.pos;
115
- let cmd2 = 1;
116
- let length2 = 0;
117
- let x2 = 0;
118
- let y2 = 0;
119
- const lines = [];
120
- let line;
121
- while (pbf.pos < end) {
122
- if (length2 <= 0) {
123
- const cmdLen2 = pbf.readVarint();
124
- cmd2 = cmdLen2 & 7;
125
- length2 = cmdLen2 >> 3;
126
- }
127
- length2--;
128
- if (cmd2 === 1 || cmd2 === 2) {
129
- x2 += pbf.readSVarint();
130
- y2 += pbf.readSVarint();
131
- if (cmd2 === 1) {
132
- if (line)
133
- lines.push(line);
134
- line = [];
135
- }
136
- if (line)
137
- line.push([x2, y2]);
138
- } else if (cmd2 === 7) {
139
- if (line) {
140
- line.push(line[0].slice());
141
- }
142
- } else {
143
- throw new Error(`unknown command ${cmd2}`);
144
- }
145
- }
146
- if (line)
147
- lines.push(line);
148
- return lines;
149
- }
150
- bbox() {
151
- const pbf = this._pbf;
152
- pbf.pos = this._geometry;
153
- const end = pbf.readVarint() + pbf.pos;
154
- let cmd2 = 1;
155
- let length2 = 0;
156
- let x2 = 0;
157
- let y2 = 0;
158
- let x1 = Infinity;
159
- let x22 = -Infinity;
160
- let y1 = Infinity;
161
- let y22 = -Infinity;
162
- while (pbf.pos < end) {
163
- if (length2 <= 0) {
164
- const cmdLen2 = pbf.readVarint();
165
- cmd2 = cmdLen2 & 7;
166
- length2 = cmdLen2 >> 3;
167
- }
168
- length2--;
169
- if (cmd2 === 1 || cmd2 === 2) {
170
- x2 += pbf.readSVarint();
171
- y2 += pbf.readSVarint();
172
- if (x2 < x1)
173
- x1 = x2;
174
- if (x2 > x22)
175
- x22 = x2;
176
- if (y2 < y1)
177
- y1 = y2;
178
- if (y2 > y22)
179
- y22 = y2;
180
- } else if (cmd2 !== 7) {
181
- throw new Error(`unknown command ${cmd2}`);
182
- }
183
- }
184
- return [x1, y1, x22, y22];
185
- }
186
- _toGeoJSON(transform) {
187
- let coords = this.loadGeometry();
188
- let type = VectorTileFeature.types[this.type];
189
- let i2;
190
- let j;
191
- switch (this.type) {
192
- case 1:
193
- const points = [];
194
- for (i2 = 0; i2 < coords.length; i2++) {
195
- points[i2] = coords[i2][0];
196
- }
197
- coords = points;
198
- transform(coords, this);
199
- break;
200
- case 2:
201
- for (i2 = 0; i2 < coords.length; i2++) {
202
- transform(coords[i2], this);
203
- }
204
- break;
205
- case 3:
206
- coords = classifyRings(coords);
207
- for (i2 = 0; i2 < coords.length; i2++) {
208
- for (j = 0; j < coords[i2].length; j++) {
209
- transform(coords[i2][j], this);
210
- }
211
- }
212
- break;
213
- }
214
- if (coords.length === 1) {
215
- coords = coords[0];
216
- } else {
217
- type = `Multi${type}`;
218
- }
219
- const result = {
220
- type: "Feature",
221
- geometry: {
222
- type,
223
- coordinates: coords
224
- },
225
- properties: this.properties
226
- };
227
- if (this.id !== null) {
228
- result.id = this.id;
229
- }
230
- return result;
231
- }
232
- toGeoJSON(options) {
233
- if (typeof options === "function") {
234
- return this._toGeoJSON(options);
235
- }
236
- const { x: x2, y: y2, z } = options;
237
- const size = this.extent * Math.pow(2, z);
238
- const x0 = this.extent * x2;
239
- const y0 = this.extent * y2;
240
- function project2(line) {
241
- for (let j = 0; j < line.length; j++) {
242
- const p = line[j];
243
- p[0] = (p[0] + x0) * 360 / size - 180;
244
- const y22 = 180 - (p[1] + y0) * 360 / size;
245
- p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
246
- }
247
- }
248
- return this._toGeoJSON(project2);
249
- }
250
- };
187
+ return true;
188
+ }
189
+ function isEarHashed(ear, minX, minY, invSize) {
190
+ const a = ear.prev;
191
+ const b = ear;
192
+ const c = ear.next;
193
+ if (area(a, b, c) >= 0)
194
+ return false;
195
+ const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
196
+ const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
197
+ const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
198
+ const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
199
+ const minZ = zOrder(minTX, minTY, minX, minY, invSize);
200
+ const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
201
+ let p = ear.prevZ;
202
+ let n = ear.nextZ;
203
+ while (p && p.z >= minZ && n && n.z <= maxZ) {
204
+ 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)
205
+ return false;
206
+ p = p.prevZ;
207
+ 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)
208
+ return false;
209
+ n = n.nextZ;
251
210
  }
252
- });
253
-
254
- // src/lib/mapbox-vector-tile/vector-tile-layer.ts
255
- function readLayer(tag, layer, pbf) {
256
- if (layer && pbf) {
257
- if (tag === 15)
258
- layer.version = pbf.readVarint();
259
- else if (tag === 1)
260
- layer.name = pbf.readString();
261
- else if (tag === 5)
262
- layer.extent = pbf.readVarint();
263
- else if (tag === 2)
264
- layer._features.push(pbf.pos);
265
- else if (tag === 3)
266
- layer._keys.push(pbf.readString());
267
- else if (tag === 4)
268
- layer._values.push(readValueMessage(pbf));
211
+ while (p && p.z >= minZ) {
212
+ 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)
213
+ return false;
214
+ p = p.prevZ;
269
215
  }
270
- }
271
- function readValueMessage(pbf) {
272
- let value = null;
273
- const end = pbf.readVarint() + pbf.pos;
274
- while (pbf.pos < end) {
275
- const tag = pbf.readVarint() >> 3;
276
- 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;
216
+ while (n && n.z <= maxZ) {
217
+ 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)
218
+ return false;
219
+ n = n.nextZ;
277
220
  }
278
- return value;
221
+ return true;
279
222
  }
280
- var VectorTileLayer;
281
- var init_vector_tile_layer = __esm({
282
- "src/lib/mapbox-vector-tile/vector-tile-layer.ts"() {
283
- init_vector_tile_feature();
284
- VectorTileLayer = class {
285
- constructor(pbf, end) {
286
- this.version = 1;
287
- this.name = "";
288
- this.extent = 4096;
289
- this.length = 0;
290
- this._pbf = pbf;
291
- this._keys = [];
292
- this._values = [];
293
- this._features = [];
294
- pbf.readFields(readLayer, this, end);
295
- this.length = this._features.length;
296
- }
297
- feature(i2) {
298
- if (i2 < 0 || i2 >= this._features.length) {
299
- throw new Error("feature index out of bounds");
300
- }
301
- this._pbf.pos = this._features[i2];
302
- const end = this._pbf.readVarint() + this._pbf.pos;
303
- return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
304
- }
305
- };
306
- }
307
- });
308
-
309
- // src/lib/mapbox-vector-tile/vector-tile.ts
310
- function readTile(tag, layers, pbf) {
311
- if (tag === 3) {
312
- if (pbf) {
313
- const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
314
- if (layer.length && layers) {
315
- layers[layer.name] = layer;
316
- }
223
+ function cureLocalIntersections(start, triangles, dim) {
224
+ let p = start;
225
+ do {
226
+ const a = p.prev;
227
+ const b = p.next.next;
228
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
229
+ triangles.push(a.i / dim);
230
+ triangles.push(p.i / dim);
231
+ triangles.push(b.i / dim);
232
+ removeNode(p);
233
+ removeNode(p.next);
234
+ p = start = b;
317
235
  }
318
- }
236
+ p = p.next;
237
+ } while (p !== start);
238
+ return filterPoints(p);
319
239
  }
320
- var VectorTile;
321
- var init_vector_tile = __esm({
322
- "src/lib/mapbox-vector-tile/vector-tile.ts"() {
323
- init_vector_tile_layer();
324
- VectorTile = class {
325
- constructor(pbf, end) {
326
- this.layers = pbf.readFields(readTile, {}, end);
240
+ function splitEarcut(start, triangles, dim, minX, minY, invSize) {
241
+ let a = start;
242
+ do {
243
+ let b = a.next.next;
244
+ while (b !== a.prev) {
245
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
246
+ let c = splitPolygon(a, b);
247
+ a = filterPoints(a, a.next);
248
+ c = filterPoints(c, c.next);
249
+ earcutLinked(a, triangles, dim, minX, minY, invSize);
250
+ earcutLinked(c, triangles, dim, minX, minY, invSize);
251
+ return;
327
252
  }
328
- };
329
- }
330
- });
331
-
332
- // ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
333
- function getPolygonSignedArea(points, options = {}) {
334
- const {
335
- start = 0,
336
- end = points.length
337
- } = options;
338
- const dim = options.size || 2;
339
- let area2 = 0;
340
- for (let i2 = start, j = end - dim; i2 < end; i2 += dim) {
341
- area2 += (points[i2] - points[j]) * (points[i2 + 1] + points[j + 1]);
342
- j = i2;
343
- }
344
- return area2 / 2;
345
- }
346
- var init_polygon_utils = __esm({
347
- "../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
348
- }
349
- });
350
-
351
- // ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
352
- var init_polygon = __esm({
353
- "../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
354
- init_polygon_utils();
355
- }
356
- });
357
-
358
- // ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
359
- function earcut(data, holeIndices, dim, areas) {
360
- dim = dim || 2;
361
- const hasHoles = holeIndices && holeIndices.length;
362
- const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
363
- let outerNode = linkedList(data, 0, outerLen, dim, true, areas && areas[0]);
364
- const triangles = [];
365
- if (!outerNode || outerNode.next === outerNode.prev)
366
- return triangles;
367
- let invSize;
368
- let maxX;
369
- let maxY;
370
- let minX;
371
- let minY;
372
- let x2;
373
- let y2;
374
- if (hasHoles)
375
- outerNode = eliminateHoles(data, holeIndices, outerNode, dim, areas);
376
- if (data.length > 80 * dim) {
377
- minX = maxX = data[0];
378
- minY = maxY = data[1];
379
- for (let i2 = dim; i2 < outerLen; i2 += dim) {
380
- x2 = data[i2];
381
- y2 = data[i2 + 1];
382
- if (x2 < minX)
383
- minX = x2;
384
- if (y2 < minY)
385
- minY = y2;
386
- if (x2 > maxX)
387
- maxX = x2;
388
- if (y2 > maxY)
389
- maxY = y2;
390
- }
391
- invSize = Math.max(maxX - minX, maxY - minY);
392
- invSize = invSize !== 0 ? 1 / invSize : 0;
393
- }
394
- earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
395
- return triangles;
396
- }
397
- function linkedList(data, start, end, dim, clockwise, area2) {
398
- let i2;
399
- let last;
400
- if (area2 === void 0) {
401
- area2 = getPolygonSignedArea(data, {
402
- start,
403
- end,
404
- size: dim
405
- });
406
- }
407
- if (clockwise === area2 < 0) {
408
- for (i2 = start; i2 < end; i2 += dim)
409
- last = insertNode(i2, data[i2], data[i2 + 1], last);
410
- } else {
411
- for (i2 = end - dim; i2 >= start; i2 -= dim)
412
- last = insertNode(i2, data[i2], data[i2 + 1], last);
413
- }
414
- if (last && equals(last, last.next)) {
415
- removeNode(last);
416
- last = last.next;
417
- }
418
- return last;
419
- }
420
- function filterPoints(start, end) {
421
- if (!start)
422
- return start;
423
- if (!end)
424
- end = start;
425
- let p = start;
426
- let again;
427
- do {
428
- again = false;
429
- if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
430
- removeNode(p);
431
- p = end = p.prev;
432
- if (p === p.next)
433
- break;
434
- again = true;
435
- } else {
436
- p = p.next;
437
- }
438
- } while (again || p !== end);
439
- return end;
440
- }
441
- function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
442
- if (!ear)
443
- return;
444
- if (!pass && invSize)
445
- indexCurve(ear, minX, minY, invSize);
446
- let stop = ear;
447
- let prev;
448
- let next;
449
- while (ear.prev !== ear.next) {
450
- prev = ear.prev;
451
- next = ear.next;
452
- if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
453
- triangles.push(prev.i / dim);
454
- triangles.push(ear.i / dim);
455
- triangles.push(next.i / dim);
456
- removeNode(ear);
457
- ear = next.next;
458
- stop = next.next;
459
- continue;
460
- }
461
- ear = next;
462
- if (ear === stop) {
463
- if (!pass) {
464
- earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
465
- } else if (pass === 1) {
466
- ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
467
- earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
468
- } else if (pass === 2) {
469
- splitEarcut(ear, triangles, dim, minX, minY, invSize);
470
- }
471
- break;
472
- }
473
- }
474
- }
475
- function isEar(ear) {
476
- const a = ear.prev;
477
- const b = ear;
478
- const c = ear.next;
479
- if (area(a, b, c) >= 0)
480
- return false;
481
- let p = ear.next.next;
482
- while (p !== ear.prev) {
483
- 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)
484
- return false;
485
- p = p.next;
486
- }
487
- return true;
488
- }
489
- function isEarHashed(ear, minX, minY, invSize) {
490
- const a = ear.prev;
491
- const b = ear;
492
- const c = ear.next;
493
- if (area(a, b, c) >= 0)
494
- return false;
495
- const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
496
- const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
497
- const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
498
- const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
499
- const minZ = zOrder(minTX, minTY, minX, minY, invSize);
500
- const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
501
- let p = ear.prevZ;
502
- let n = ear.nextZ;
503
- while (p && p.z >= minZ && n && n.z <= maxZ) {
504
- 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)
505
- return false;
506
- p = p.prevZ;
507
- 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)
508
- return false;
509
- n = n.nextZ;
510
- }
511
- while (p && p.z >= minZ) {
512
- 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)
513
- return false;
514
- p = p.prevZ;
515
- }
516
- while (n && n.z <= maxZ) {
517
- 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)
518
- return false;
519
- n = n.nextZ;
520
- }
521
- return true;
522
- }
523
- function cureLocalIntersections(start, triangles, dim) {
524
- let p = start;
525
- do {
526
- const a = p.prev;
527
- const b = p.next.next;
528
- if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
529
- triangles.push(a.i / dim);
530
- triangles.push(p.i / dim);
531
- triangles.push(b.i / dim);
532
- removeNode(p);
533
- removeNode(p.next);
534
- p = start = b;
535
- }
536
- p = p.next;
537
- } while (p !== start);
538
- return filterPoints(p);
539
- }
540
- function splitEarcut(start, triangles, dim, minX, minY, invSize) {
541
- let a = start;
542
- do {
543
- let b = a.next.next;
544
- while (b !== a.prev) {
545
- if (a.i !== b.i && isValidDiagonal(a, b)) {
546
- let c = splitPolygon(a, b);
547
- a = filterPoints(a, a.next);
548
- c = filterPoints(c, c.next);
549
- earcutLinked(a, triangles, dim, minX, minY, invSize);
550
- earcutLinked(c, triangles, dim, minX, minY, invSize);
551
- return;
552
- }
553
- b = b.next;
554
- }
555
- a = a.next;
556
- } while (a !== start);
253
+ b = b.next;
254
+ }
255
+ a = a.next;
256
+ } while (a !== start);
557
257
  }
558
258
  function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
559
259
  const queue = [];
@@ -875,292 +575,26 @@
875
575
  }
876
576
  });
877
577
 
878
- // src/helpers/binary-util-functions.ts
879
- function classifyRings2(geom) {
880
- const len = geom.indices.length;
881
- const type = "Polygon";
882
- if (len <= 1) {
883
- return {
884
- type,
885
- data: geom.data,
886
- areas: [[getPolygonSignedArea(geom.data)]],
887
- indices: [geom.indices]
888
- };
889
- }
890
- const areas = [];
891
- const polygons = [];
892
- let ringAreas = [];
893
- let polygon = [];
894
- let ccw;
895
- let offset = 0;
896
- for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
897
- startIndex = geom.indices[i2] - offset;
898
- endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
899
- const shape = geom.data.slice(startIndex, endIndex);
900
- const area2 = getPolygonSignedArea(shape);
901
- if (area2 === 0) {
902
- const before = geom.data.slice(0, startIndex);
903
- const after = geom.data.slice(endIndex);
904
- geom.data = before.concat(after);
905
- offset += endIndex - startIndex;
906
- continue;
907
- }
908
- if (ccw === void 0)
909
- ccw = area2 < 0;
910
- if (ccw === area2 < 0) {
911
- if (polygon.length) {
912
- areas.push(ringAreas);
913
- polygons.push(polygon);
914
- }
915
- polygon = [startIndex];
916
- ringAreas = [area2];
917
- } else {
918
- ringAreas.push(area2);
919
- polygon.push(startIndex);
920
- }
921
- }
922
- if (ringAreas)
923
- areas.push(ringAreas);
924
- if (polygon.length)
925
- polygons.push(polygon);
926
- return { type, areas, indices: polygons, data: geom.data };
927
- }
928
- function project(data, x0, y0, size) {
929
- for (let j = 0, jl = data.length; j < jl; j += 2) {
930
- data[j] = (data[j] + x0) * 360 / size - 180;
931
- const y2 = 180 - (data[j + 1] + y0) * 360 / size;
932
- data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
933
- }
934
- }
935
- function readFeature2(tag, feature, pbf) {
936
- if (feature && pbf) {
937
- if (tag === 1)
938
- feature.id = pbf.readVarint();
939
- else if (tag === 2)
940
- readTag2(pbf, feature);
941
- else if (tag === 3)
942
- feature.type = pbf.readVarint();
943
- else if (tag === 4)
944
- feature._geometry = pbf.pos;
945
- }
946
- }
947
- function readTag2(pbf, feature) {
948
- const end = pbf.readVarint() + pbf.pos;
949
- while (pbf.pos < end) {
950
- const key = feature._keys[pbf.readVarint()];
951
- const value = feature._values[pbf.readVarint()];
952
- feature.properties[key] = value;
953
- }
954
- }
955
- var init_binary_util_functions = __esm({
956
- "src/helpers/binary-util-functions.ts"() {
957
- init_esm();
958
- }
959
- });
960
-
961
- // src/lib/binary-vector-tile/vector-tile-feature.ts
962
- var endPos, cmd, cmdLen, length, x, y, i, VectorTileFeature2;
963
- var init_vector_tile_feature2 = __esm({
964
- "src/lib/binary-vector-tile/vector-tile-feature.ts"() {
965
- init_binary_util_functions();
966
- VectorTileFeature2 = class {
967
- constructor(pbf, end, extent, keys, values, geometryInfo) {
968
- this.properties = {};
969
- this.extent = extent;
970
- this.type = 0;
971
- this.id = null;
972
- this._pbf = pbf;
973
- this._geometry = -1;
974
- this._keys = keys;
975
- this._values = values;
976
- this._geometryInfo = geometryInfo;
977
- pbf.readFields(readFeature2, this, end);
978
- }
979
- loadGeometry() {
980
- const pbf = this._pbf;
981
- pbf.pos = this._geometry;
982
- endPos = pbf.readVarint() + pbf.pos;
983
- cmd = 1;
984
- length = 0;
985
- x = 0;
986
- y = 0;
987
- i = 0;
988
- const indices = [];
989
- const data = [];
990
- while (pbf.pos < endPos) {
991
- if (length <= 0) {
992
- cmdLen = pbf.readVarint();
993
- cmd = cmdLen & 7;
994
- length = cmdLen >> 3;
995
- }
996
- length--;
997
- if (cmd === 1 || cmd === 2) {
998
- x += pbf.readSVarint();
999
- y += pbf.readSVarint();
1000
- if (cmd === 1) {
1001
- indices.push(i);
1002
- }
1003
- data.push(x, y);
1004
- i += 2;
1005
- } else if (cmd === 7) {
1006
- if (i > 0) {
1007
- const start = indices[indices.length - 1];
1008
- data.push(data[start], data[start + 1]);
1009
- i += 2;
1010
- }
1011
- } else {
1012
- throw new Error(`unknown command ${cmd}`);
1013
- }
1014
- }
1015
- return { data, indices };
1016
- }
1017
- _toBinaryCoordinates(transform) {
1018
- const geom = this.loadGeometry();
1019
- let geometry;
1020
- transform(geom.data, this);
1021
- const coordLength = 2;
1022
- switch (this.type) {
1023
- case 1:
1024
- this._geometryInfo.pointFeaturesCount++;
1025
- this._geometryInfo.pointPositionsCount += geom.indices.length;
1026
- geometry = { type: "Point", ...geom };
1027
- break;
1028
- case 2:
1029
- this._geometryInfo.lineFeaturesCount++;
1030
- this._geometryInfo.linePathsCount += geom.indices.length;
1031
- this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
1032
- geometry = { type: "LineString", ...geom };
1033
- break;
1034
- case 3:
1035
- geometry = classifyRings2(geom);
1036
- this._geometryInfo.polygonFeaturesCount++;
1037
- this._geometryInfo.polygonObjectsCount += geometry.indices.length;
1038
- for (const indices of geometry.indices) {
1039
- this._geometryInfo.polygonRingsCount += indices.length;
1040
- }
1041
- this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
1042
- break;
1043
- default:
1044
- throw new Error(`Invalid geometry type: ${this.type}`);
1045
- }
1046
- const result = { type: "Feature", geometry, properties: this.properties };
1047
- if (this.id !== null) {
1048
- result.id = this.id;
1049
- }
1050
- return result;
1051
- }
1052
- toBinaryCoordinates(options) {
1053
- if (typeof options === "function") {
1054
- return this._toBinaryCoordinates(options);
1055
- }
1056
- const { x: x2, y: y2, z } = options;
1057
- const size = this.extent * Math.pow(2, z);
1058
- const x0 = this.extent * x2;
1059
- const y0 = this.extent * y2;
1060
- return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
1061
- }
1062
- };
1063
- }
1064
- });
1065
-
1066
- // src/lib/binary-vector-tile/vector-tile-layer.ts
1067
- function readLayer2(tag, layer, pbf) {
1068
- if (layer && pbf) {
1069
- if (tag === 15)
1070
- layer.version = pbf.readVarint();
1071
- else if (tag === 1)
1072
- layer.name = pbf.readString();
1073
- else if (tag === 5)
1074
- layer.extent = pbf.readVarint();
1075
- else if (tag === 2)
1076
- layer._features.push(pbf.pos);
1077
- else if (tag === 3)
1078
- layer._keys.push(pbf.readString());
1079
- else if (tag === 4)
1080
- layer._values.push(readValueMessage2(pbf));
1081
- }
1082
- }
1083
- function readValueMessage2(pbf) {
1084
- let value = null;
1085
- const end = pbf.readVarint() + pbf.pos;
1086
- while (pbf.pos < end) {
1087
- const tag = pbf.readVarint() >> 3;
1088
- 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;
1089
- }
1090
- return value;
1091
- }
1092
- var VectorTileLayer2;
1093
- var init_vector_tile_layer2 = __esm({
1094
- "src/lib/binary-vector-tile/vector-tile-layer.ts"() {
1095
- init_vector_tile_feature2();
1096
- VectorTileLayer2 = class {
1097
- constructor(pbf, end) {
1098
- this.version = 1;
1099
- this.name = "";
1100
- this.extent = 4096;
1101
- this.length = 0;
1102
- this._pbf = pbf;
1103
- this._keys = [];
1104
- this._values = [];
1105
- this._features = [];
1106
- pbf.readFields(readLayer2, this, end);
1107
- this.length = this._features.length;
1108
- }
1109
- feature(i2, geometryInfo) {
1110
- if (i2 < 0 || i2 >= this._features.length) {
1111
- throw new Error("feature index out of bounds");
1112
- }
1113
- this._pbf.pos = this._features[i2];
1114
- const end = this._pbf.readVarint() + this._pbf.pos;
1115
- return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
1116
- }
1117
- };
1118
- }
1119
- });
1120
-
1121
- // src/lib/binary-vector-tile/vector-tile.ts
1122
- function readTile2(tag, layers, pbf) {
1123
- if (tag === 3) {
1124
- if (pbf) {
1125
- const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
1126
- if (layer.length && layers) {
1127
- layers[layer.name] = layer;
1128
- }
1129
- }
1130
- }
1131
- }
1132
- var VectorTile2;
1133
- var init_vector_tile2 = __esm({
1134
- "src/lib/binary-vector-tile/vector-tile.ts"() {
1135
- init_vector_tile_layer2();
1136
- VectorTile2 = class {
1137
- constructor(pbf, end) {
1138
- this.layers = pbf.readFields(readTile2, {}, end);
1139
- }
1140
- };
1141
- }
1142
- });
1143
-
1144
- // ../gis/src/lib/flat-geojson-to-binary.ts
1145
- function flatGeojsonToBinary(features, geometryInfo, options) {
1146
- const propArrayTypes = extractNumericPropTypes(features);
1147
- const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
1148
- return fillArrays(features, {
1149
- propArrayTypes,
1150
- ...geometryInfo
1151
- }, {
1152
- numericPropKeys: options && options.numericPropKeys || numericPropKeys,
1153
- PositionDataType: options ? options.PositionDataType : Float32Array
1154
- });
1155
- }
1156
- function extractNumericPropTypes(features) {
1157
- const propArrayTypes = {};
1158
- for (const feature of features) {
1159
- if (feature.properties) {
1160
- for (const key in feature.properties) {
1161
- const val = feature.properties[key];
1162
- propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
1163
- }
578
+ // ../gis/src/lib/flat-geojson-to-binary.ts
579
+ function flatGeojsonToBinary(features, geometryInfo, options) {
580
+ const propArrayTypes = extractNumericPropTypes(features);
581
+ const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
582
+ return fillArrays(features, {
583
+ propArrayTypes,
584
+ ...geometryInfo
585
+ }, {
586
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
587
+ PositionDataType: options ? options.PositionDataType : Float32Array
588
+ });
589
+ }
590
+ function extractNumericPropTypes(features) {
591
+ const propArrayTypes = {};
592
+ for (const feature of features) {
593
+ if (feature.properties) {
594
+ for (const key in feature.properties) {
595
+ const val = feature.properties[key];
596
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
597
+ }
1164
598
  }
1165
599
  }
1166
600
  return propArrayTypes;
@@ -2038,173 +1472,774 @@
2038
1472
  if (b0 < 128) {
2039
1473
  c = b0;
2040
1474
  }
2041
- } else if (bytesPerSequence === 2) {
2042
- b1 = buf[i2 + 1];
2043
- if ((b1 & 192) === 128) {
2044
- c = (b0 & 31) << 6 | b1 & 63;
2045
- if (c <= 127) {
2046
- c = null;
1475
+ } else if (bytesPerSequence === 2) {
1476
+ b1 = buf[i2 + 1];
1477
+ if ((b1 & 192) === 128) {
1478
+ c = (b0 & 31) << 6 | b1 & 63;
1479
+ if (c <= 127) {
1480
+ c = null;
1481
+ }
1482
+ }
1483
+ } else if (bytesPerSequence === 3) {
1484
+ b1 = buf[i2 + 1];
1485
+ b2 = buf[i2 + 2];
1486
+ if ((b1 & 192) === 128 && (b2 & 192) === 128) {
1487
+ c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
1488
+ if (c <= 2047 || c >= 55296 && c <= 57343) {
1489
+ c = null;
1490
+ }
1491
+ }
1492
+ } else if (bytesPerSequence === 4) {
1493
+ b1 = buf[i2 + 1];
1494
+ b2 = buf[i2 + 2];
1495
+ b3 = buf[i2 + 3];
1496
+ if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
1497
+ c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
1498
+ if (c <= 65535 || c >= 1114112) {
1499
+ c = null;
1500
+ }
1501
+ }
1502
+ }
1503
+ if (c === null) {
1504
+ c = 65533;
1505
+ bytesPerSequence = 1;
1506
+ } else if (c > 65535) {
1507
+ c -= 65536;
1508
+ str += String.fromCharCode(c >>> 10 & 1023 | 55296);
1509
+ c = 56320 | c & 1023;
1510
+ }
1511
+ str += String.fromCharCode(c);
1512
+ i2 += bytesPerSequence;
1513
+ }
1514
+ return str;
1515
+ }
1516
+ function readUtf8TextDecoder(buf, pos, end) {
1517
+ return utf8TextDecoder.decode(buf.subarray(pos, end));
1518
+ }
1519
+ function writeUtf8(buf, str, pos) {
1520
+ for (var i2 = 0, c, lead; i2 < str.length; i2++) {
1521
+ c = str.charCodeAt(i2);
1522
+ if (c > 55295 && c < 57344) {
1523
+ if (lead) {
1524
+ if (c < 56320) {
1525
+ buf[pos++] = 239;
1526
+ buf[pos++] = 191;
1527
+ buf[pos++] = 189;
1528
+ lead = c;
1529
+ continue;
1530
+ } else {
1531
+ c = lead - 55296 << 10 | c - 56320 | 65536;
1532
+ lead = null;
1533
+ }
1534
+ } else {
1535
+ if (c > 56319 || i2 + 1 === str.length) {
1536
+ buf[pos++] = 239;
1537
+ buf[pos++] = 191;
1538
+ buf[pos++] = 189;
1539
+ } else {
1540
+ lead = c;
1541
+ }
1542
+ continue;
1543
+ }
1544
+ } else if (lead) {
1545
+ buf[pos++] = 239;
1546
+ buf[pos++] = 191;
1547
+ buf[pos++] = 189;
1548
+ lead = null;
1549
+ }
1550
+ if (c < 128) {
1551
+ buf[pos++] = c;
1552
+ } else {
1553
+ if (c < 2048) {
1554
+ buf[pos++] = c >> 6 | 192;
1555
+ } else {
1556
+ if (c < 65536) {
1557
+ buf[pos++] = c >> 12 | 224;
1558
+ } else {
1559
+ buf[pos++] = c >> 18 | 240;
1560
+ buf[pos++] = c >> 12 & 63 | 128;
1561
+ }
1562
+ buf[pos++] = c >> 6 & 63 | 128;
1563
+ }
1564
+ buf[pos++] = c & 63 | 128;
1565
+ }
1566
+ }
1567
+ return pos;
1568
+ }
1569
+ }
1570
+ });
1571
+
1572
+ // src/helpers/mapbox-util-functions.ts
1573
+ function classifyRings(rings) {
1574
+ const len = rings.length;
1575
+ if (len <= 1)
1576
+ return [rings];
1577
+ const polygons = [];
1578
+ let polygon;
1579
+ let ccw;
1580
+ for (let i2 = 0; i2 < len; i2++) {
1581
+ const area2 = signedArea(rings[i2]);
1582
+ if (area2 === 0)
1583
+ continue;
1584
+ if (ccw === void 0)
1585
+ ccw = area2 < 0;
1586
+ if (ccw === area2 < 0) {
1587
+ if (polygon)
1588
+ polygons.push(polygon);
1589
+ polygon = [rings[i2]];
1590
+ } else if (polygon)
1591
+ polygon.push(rings[i2]);
1592
+ }
1593
+ if (polygon)
1594
+ polygons.push(polygon);
1595
+ return polygons;
1596
+ }
1597
+ function signedArea(ring) {
1598
+ let sum = 0;
1599
+ for (let i2 = 0, j = ring.length - 1, p1, p2; i2 < ring.length; j = i2++) {
1600
+ p1 = ring[i2];
1601
+ p2 = ring[j];
1602
+ sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
1603
+ }
1604
+ return sum;
1605
+ }
1606
+ function readFeature(tag, feature, pbf) {
1607
+ if (feature && pbf) {
1608
+ if (tag === 1)
1609
+ feature.id = pbf.readVarint();
1610
+ else if (tag === 2)
1611
+ readTag(pbf, feature);
1612
+ else if (tag === 3)
1613
+ feature.type = pbf.readVarint();
1614
+ else if (tag === 4)
1615
+ feature._geometry = pbf.pos;
1616
+ }
1617
+ }
1618
+ function readTag(pbf, feature) {
1619
+ const end = pbf.readVarint() + pbf.pos;
1620
+ while (pbf.pos < end) {
1621
+ const key = feature._keys[pbf.readVarint()];
1622
+ const value = feature._values[pbf.readVarint()];
1623
+ feature.properties[key] = value;
1624
+ }
1625
+ }
1626
+ var init_mapbox_util_functions = __esm({
1627
+ "src/helpers/mapbox-util-functions.ts"() {
1628
+ }
1629
+ });
1630
+
1631
+ // src/lib/mapbox-vector-tile/vector-tile-feature.ts
1632
+ var VectorTileFeature;
1633
+ var init_vector_tile_feature = __esm({
1634
+ "src/lib/mapbox-vector-tile/vector-tile-feature.ts"() {
1635
+ init_mapbox_util_functions();
1636
+ VectorTileFeature = class {
1637
+ static get types() {
1638
+ return ["Unknown", "Point", "LineString", "Polygon"];
1639
+ }
1640
+ constructor(pbf, end, extent, keys, values) {
1641
+ this.properties = {};
1642
+ this.extent = extent;
1643
+ this.type = 0;
1644
+ this.id = null;
1645
+ this._pbf = pbf;
1646
+ this._geometry = -1;
1647
+ this._keys = keys;
1648
+ this._values = values;
1649
+ pbf.readFields(readFeature, this, end);
1650
+ }
1651
+ loadGeometry() {
1652
+ const pbf = this._pbf;
1653
+ pbf.pos = this._geometry;
1654
+ const end = pbf.readVarint() + pbf.pos;
1655
+ let cmd2 = 1;
1656
+ let length2 = 0;
1657
+ let x2 = 0;
1658
+ let y2 = 0;
1659
+ const lines = [];
1660
+ let line;
1661
+ while (pbf.pos < end) {
1662
+ if (length2 <= 0) {
1663
+ const cmdLen2 = pbf.readVarint();
1664
+ cmd2 = cmdLen2 & 7;
1665
+ length2 = cmdLen2 >> 3;
1666
+ }
1667
+ length2--;
1668
+ if (cmd2 === 1 || cmd2 === 2) {
1669
+ x2 += pbf.readSVarint();
1670
+ y2 += pbf.readSVarint();
1671
+ if (cmd2 === 1) {
1672
+ if (line)
1673
+ lines.push(line);
1674
+ line = [];
1675
+ }
1676
+ if (line)
1677
+ line.push([x2, y2]);
1678
+ } else if (cmd2 === 7) {
1679
+ if (line) {
1680
+ line.push(line[0].slice());
1681
+ }
1682
+ } else {
1683
+ throw new Error(`unknown command ${cmd2}`);
1684
+ }
1685
+ }
1686
+ if (line)
1687
+ lines.push(line);
1688
+ return lines;
1689
+ }
1690
+ bbox() {
1691
+ const pbf = this._pbf;
1692
+ pbf.pos = this._geometry;
1693
+ const end = pbf.readVarint() + pbf.pos;
1694
+ let cmd2 = 1;
1695
+ let length2 = 0;
1696
+ let x2 = 0;
1697
+ let y2 = 0;
1698
+ let x1 = Infinity;
1699
+ let x22 = -Infinity;
1700
+ let y1 = Infinity;
1701
+ let y22 = -Infinity;
1702
+ while (pbf.pos < end) {
1703
+ if (length2 <= 0) {
1704
+ const cmdLen2 = pbf.readVarint();
1705
+ cmd2 = cmdLen2 & 7;
1706
+ length2 = cmdLen2 >> 3;
1707
+ }
1708
+ length2--;
1709
+ if (cmd2 === 1 || cmd2 === 2) {
1710
+ x2 += pbf.readSVarint();
1711
+ y2 += pbf.readSVarint();
1712
+ if (x2 < x1)
1713
+ x1 = x2;
1714
+ if (x2 > x22)
1715
+ x22 = x2;
1716
+ if (y2 < y1)
1717
+ y1 = y2;
1718
+ if (y2 > y22)
1719
+ y22 = y2;
1720
+ } else if (cmd2 !== 7) {
1721
+ throw new Error(`unknown command ${cmd2}`);
1722
+ }
1723
+ }
1724
+ return [x1, y1, x22, y22];
1725
+ }
1726
+ _toGeoJSON(transform) {
1727
+ let coords = this.loadGeometry();
1728
+ let type = VectorTileFeature.types[this.type];
1729
+ let i2;
1730
+ let j;
1731
+ switch (this.type) {
1732
+ case 1:
1733
+ const points = [];
1734
+ for (i2 = 0; i2 < coords.length; i2++) {
1735
+ points[i2] = coords[i2][0];
1736
+ }
1737
+ coords = points;
1738
+ transform(coords, this);
1739
+ break;
1740
+ case 2:
1741
+ for (i2 = 0; i2 < coords.length; i2++) {
1742
+ transform(coords[i2], this);
1743
+ }
1744
+ break;
1745
+ case 3:
1746
+ coords = classifyRings(coords);
1747
+ for (i2 = 0; i2 < coords.length; i2++) {
1748
+ for (j = 0; j < coords[i2].length; j++) {
1749
+ transform(coords[i2][j], this);
1750
+ }
1751
+ }
1752
+ break;
1753
+ }
1754
+ if (coords.length === 1) {
1755
+ coords = coords[0];
1756
+ } else {
1757
+ type = `Multi${type}`;
1758
+ }
1759
+ const result = {
1760
+ type: "Feature",
1761
+ geometry: {
1762
+ type,
1763
+ coordinates: coords
1764
+ },
1765
+ properties: this.properties
1766
+ };
1767
+ if (this.id !== null) {
1768
+ result.id = this.id;
1769
+ }
1770
+ return result;
1771
+ }
1772
+ toGeoJSON(options) {
1773
+ if (typeof options === "function") {
1774
+ return this._toGeoJSON(options);
1775
+ }
1776
+ const { x: x2, y: y2, z } = options;
1777
+ const size = this.extent * Math.pow(2, z);
1778
+ const x0 = this.extent * x2;
1779
+ const y0 = this.extent * y2;
1780
+ function project2(line) {
1781
+ for (let j = 0; j < line.length; j++) {
1782
+ const p = line[j];
1783
+ p[0] = (p[0] + x0) * 360 / size - 180;
1784
+ const y22 = 180 - (p[1] + y0) * 360 / size;
1785
+ p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
1786
+ }
1787
+ }
1788
+ return this._toGeoJSON(project2);
1789
+ }
1790
+ };
1791
+ }
1792
+ });
1793
+
1794
+ // src/lib/mapbox-vector-tile/vector-tile-layer.ts
1795
+ function readLayer(tag, layer, pbf) {
1796
+ if (layer && pbf) {
1797
+ if (tag === 15)
1798
+ layer.version = pbf.readVarint();
1799
+ else if (tag === 1)
1800
+ layer.name = pbf.readString();
1801
+ else if (tag === 5)
1802
+ layer.extent = pbf.readVarint();
1803
+ else if (tag === 2)
1804
+ layer._features.push(pbf.pos);
1805
+ else if (tag === 3)
1806
+ layer._keys.push(pbf.readString());
1807
+ else if (tag === 4)
1808
+ layer._values.push(readValueMessage(pbf));
1809
+ }
1810
+ }
1811
+ function readValueMessage(pbf) {
1812
+ let value = null;
1813
+ const end = pbf.readVarint() + pbf.pos;
1814
+ while (pbf.pos < end) {
1815
+ const tag = pbf.readVarint() >> 3;
1816
+ 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;
1817
+ }
1818
+ return value;
1819
+ }
1820
+ var VectorTileLayer;
1821
+ var init_vector_tile_layer = __esm({
1822
+ "src/lib/mapbox-vector-tile/vector-tile-layer.ts"() {
1823
+ init_vector_tile_feature();
1824
+ VectorTileLayer = class {
1825
+ constructor(pbf, end) {
1826
+ this.version = 1;
1827
+ this.name = "";
1828
+ this.extent = 4096;
1829
+ this.length = 0;
1830
+ this._pbf = pbf;
1831
+ this._keys = [];
1832
+ this._values = [];
1833
+ this._features = [];
1834
+ pbf.readFields(readLayer, this, end);
1835
+ this.length = this._features.length;
1836
+ }
1837
+ feature(i2) {
1838
+ if (i2 < 0 || i2 >= this._features.length) {
1839
+ throw new Error("feature index out of bounds");
1840
+ }
1841
+ this._pbf.pos = this._features[i2];
1842
+ const end = this._pbf.readVarint() + this._pbf.pos;
1843
+ return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
1844
+ }
1845
+ };
1846
+ }
1847
+ });
1848
+
1849
+ // src/lib/mapbox-vector-tile/vector-tile.ts
1850
+ function readTile(tag, layers, pbf) {
1851
+ if (tag === 3) {
1852
+ if (pbf) {
1853
+ const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
1854
+ if (layer.length && layers) {
1855
+ layers[layer.name] = layer;
1856
+ }
1857
+ }
1858
+ }
1859
+ }
1860
+ var VectorTile;
1861
+ var init_vector_tile = __esm({
1862
+ "src/lib/mapbox-vector-tile/vector-tile.ts"() {
1863
+ init_vector_tile_layer();
1864
+ VectorTile = class {
1865
+ constructor(pbf, end) {
1866
+ this.layers = pbf.readFields(readTile, {}, end);
1867
+ }
1868
+ };
1869
+ }
1870
+ });
1871
+
1872
+ // src/helpers/binary-util-functions.ts
1873
+ function classifyRings2(geom) {
1874
+ const len = geom.indices.length;
1875
+ const type = "Polygon";
1876
+ if (len <= 1) {
1877
+ return {
1878
+ type,
1879
+ data: geom.data,
1880
+ areas: [[getPolygonSignedArea(geom.data)]],
1881
+ indices: [geom.indices]
1882
+ };
1883
+ }
1884
+ const areas = [];
1885
+ const polygons = [];
1886
+ let ringAreas = [];
1887
+ let polygon = [];
1888
+ let ccw;
1889
+ let offset = 0;
1890
+ for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
1891
+ startIndex = geom.indices[i2] - offset;
1892
+ endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
1893
+ const shape = geom.data.slice(startIndex, endIndex);
1894
+ const area2 = getPolygonSignedArea(shape);
1895
+ if (area2 === 0) {
1896
+ const before = geom.data.slice(0, startIndex);
1897
+ const after = geom.data.slice(endIndex);
1898
+ geom.data = before.concat(after);
1899
+ offset += endIndex - startIndex;
1900
+ continue;
1901
+ }
1902
+ if (ccw === void 0)
1903
+ ccw = area2 < 0;
1904
+ if (ccw === area2 < 0) {
1905
+ if (polygon.length) {
1906
+ areas.push(ringAreas);
1907
+ polygons.push(polygon);
1908
+ }
1909
+ polygon = [startIndex];
1910
+ ringAreas = [area2];
1911
+ } else {
1912
+ ringAreas.push(area2);
1913
+ polygon.push(startIndex);
1914
+ }
1915
+ }
1916
+ if (ringAreas)
1917
+ areas.push(ringAreas);
1918
+ if (polygon.length)
1919
+ polygons.push(polygon);
1920
+ return { type, areas, indices: polygons, data: geom.data };
1921
+ }
1922
+ function project(data, x0, y0, size) {
1923
+ for (let j = 0, jl = data.length; j < jl; j += 2) {
1924
+ data[j] = (data[j] + x0) * 360 / size - 180;
1925
+ const y2 = 180 - (data[j + 1] + y0) * 360 / size;
1926
+ data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
1927
+ }
1928
+ }
1929
+ function readFeature2(tag, feature, pbf) {
1930
+ if (feature && pbf) {
1931
+ if (tag === 1)
1932
+ feature.id = pbf.readVarint();
1933
+ else if (tag === 2)
1934
+ readTag2(pbf, feature);
1935
+ else if (tag === 3)
1936
+ feature.type = pbf.readVarint();
1937
+ else if (tag === 4)
1938
+ feature._geometry = pbf.pos;
1939
+ }
1940
+ }
1941
+ function readTag2(pbf, feature) {
1942
+ const end = pbf.readVarint() + pbf.pos;
1943
+ while (pbf.pos < end) {
1944
+ const key = feature._keys[pbf.readVarint()];
1945
+ const value = feature._values[pbf.readVarint()];
1946
+ feature.properties[key] = value;
1947
+ }
1948
+ }
1949
+ var init_binary_util_functions = __esm({
1950
+ "src/helpers/binary-util-functions.ts"() {
1951
+ init_esm();
1952
+ }
1953
+ });
1954
+
1955
+ // src/lib/binary-vector-tile/vector-tile-feature.ts
1956
+ var endPos, cmd, cmdLen, length, x, y, i, VectorTileFeature2;
1957
+ var init_vector_tile_feature2 = __esm({
1958
+ "src/lib/binary-vector-tile/vector-tile-feature.ts"() {
1959
+ init_binary_util_functions();
1960
+ VectorTileFeature2 = class {
1961
+ constructor(pbf, end, extent, keys, values, geometryInfo) {
1962
+ this.properties = {};
1963
+ this.extent = extent;
1964
+ this.type = 0;
1965
+ this.id = null;
1966
+ this._pbf = pbf;
1967
+ this._geometry = -1;
1968
+ this._keys = keys;
1969
+ this._values = values;
1970
+ this._geometryInfo = geometryInfo;
1971
+ pbf.readFields(readFeature2, this, end);
1972
+ }
1973
+ loadGeometry() {
1974
+ const pbf = this._pbf;
1975
+ pbf.pos = this._geometry;
1976
+ endPos = pbf.readVarint() + pbf.pos;
1977
+ cmd = 1;
1978
+ length = 0;
1979
+ x = 0;
1980
+ y = 0;
1981
+ i = 0;
1982
+ const indices = [];
1983
+ const data = [];
1984
+ while (pbf.pos < endPos) {
1985
+ if (length <= 0) {
1986
+ cmdLen = pbf.readVarint();
1987
+ cmd = cmdLen & 7;
1988
+ length = cmdLen >> 3;
1989
+ }
1990
+ length--;
1991
+ if (cmd === 1 || cmd === 2) {
1992
+ x += pbf.readSVarint();
1993
+ y += pbf.readSVarint();
1994
+ if (cmd === 1) {
1995
+ indices.push(i);
2047
1996
  }
2048
- }
2049
- } else if (bytesPerSequence === 3) {
2050
- b1 = buf[i2 + 1];
2051
- b2 = buf[i2 + 2];
2052
- if ((b1 & 192) === 128 && (b2 & 192) === 128) {
2053
- c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
2054
- if (c <= 2047 || c >= 55296 && c <= 57343) {
2055
- c = null;
1997
+ data.push(x, y);
1998
+ i += 2;
1999
+ } else if (cmd === 7) {
2000
+ if (i > 0) {
2001
+ const start = indices[indices.length - 1];
2002
+ data.push(data[start], data[start + 1]);
2003
+ i += 2;
2056
2004
  }
2005
+ } else {
2006
+ throw new Error(`unknown command ${cmd}`);
2057
2007
  }
2058
- } else if (bytesPerSequence === 4) {
2059
- b1 = buf[i2 + 1];
2060
- b2 = buf[i2 + 2];
2061
- b3 = buf[i2 + 3];
2062
- if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
2063
- c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
2064
- if (c <= 65535 || c >= 1114112) {
2065
- c = null;
2008
+ }
2009
+ return { data, indices };
2010
+ }
2011
+ _toBinaryCoordinates(transform) {
2012
+ const geom = this.loadGeometry();
2013
+ let geometry;
2014
+ transform(geom.data, this);
2015
+ const coordLength = 2;
2016
+ switch (this.type) {
2017
+ case 1:
2018
+ this._geometryInfo.pointFeaturesCount++;
2019
+ this._geometryInfo.pointPositionsCount += geom.indices.length;
2020
+ geometry = { type: "Point", ...geom };
2021
+ break;
2022
+ case 2:
2023
+ this._geometryInfo.lineFeaturesCount++;
2024
+ this._geometryInfo.linePathsCount += geom.indices.length;
2025
+ this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
2026
+ geometry = { type: "LineString", ...geom };
2027
+ break;
2028
+ case 3:
2029
+ geometry = classifyRings2(geom);
2030
+ this._geometryInfo.polygonFeaturesCount++;
2031
+ this._geometryInfo.polygonObjectsCount += geometry.indices.length;
2032
+ for (const indices of geometry.indices) {
2033
+ this._geometryInfo.polygonRingsCount += indices.length;
2066
2034
  }
2067
- }
2035
+ this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
2036
+ break;
2037
+ default:
2038
+ throw new Error(`Invalid geometry type: ${this.type}`);
2068
2039
  }
2069
- if (c === null) {
2070
- c = 65533;
2071
- bytesPerSequence = 1;
2072
- } else if (c > 65535) {
2073
- c -= 65536;
2074
- str += String.fromCharCode(c >>> 10 & 1023 | 55296);
2075
- c = 56320 | c & 1023;
2040
+ const result = { type: "Feature", geometry, properties: this.properties };
2041
+ if (this.id !== null) {
2042
+ result.id = this.id;
2076
2043
  }
2077
- str += String.fromCharCode(c);
2078
- i2 += bytesPerSequence;
2044
+ return result;
2079
2045
  }
2080
- return str;
2081
- }
2082
- function readUtf8TextDecoder(buf, pos, end) {
2083
- return utf8TextDecoder.decode(buf.subarray(pos, end));
2084
- }
2085
- function writeUtf8(buf, str, pos) {
2086
- for (var i2 = 0, c, lead; i2 < str.length; i2++) {
2087
- c = str.charCodeAt(i2);
2088
- if (c > 55295 && c < 57344) {
2089
- if (lead) {
2090
- if (c < 56320) {
2091
- buf[pos++] = 239;
2092
- buf[pos++] = 191;
2093
- buf[pos++] = 189;
2094
- lead = c;
2095
- continue;
2096
- } else {
2097
- c = lead - 55296 << 10 | c - 56320 | 65536;
2098
- lead = null;
2099
- }
2100
- } else {
2101
- if (c > 56319 || i2 + 1 === str.length) {
2102
- buf[pos++] = 239;
2103
- buf[pos++] = 191;
2104
- buf[pos++] = 189;
2105
- } else {
2106
- lead = c;
2107
- }
2108
- continue;
2109
- }
2110
- } else if (lead) {
2111
- buf[pos++] = 239;
2112
- buf[pos++] = 191;
2113
- buf[pos++] = 189;
2114
- lead = null;
2046
+ toBinaryCoordinates(options) {
2047
+ if (typeof options === "function") {
2048
+ return this._toBinaryCoordinates(options);
2115
2049
  }
2116
- if (c < 128) {
2117
- buf[pos++] = c;
2118
- } else {
2119
- if (c < 2048) {
2120
- buf[pos++] = c >> 6 | 192;
2121
- } else {
2122
- if (c < 65536) {
2123
- buf[pos++] = c >> 12 | 224;
2124
- } else {
2125
- buf[pos++] = c >> 18 | 240;
2126
- buf[pos++] = c >> 12 & 63 | 128;
2127
- }
2128
- buf[pos++] = c >> 6 & 63 | 128;
2129
- }
2130
- buf[pos++] = c & 63 | 128;
2050
+ const { x: x2, y: y2, z } = options;
2051
+ const size = this.extent * Math.pow(2, z);
2052
+ const x0 = this.extent * x2;
2053
+ const y0 = this.extent * y2;
2054
+ return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
2055
+ }
2056
+ };
2057
+ }
2058
+ });
2059
+
2060
+ // src/lib/binary-vector-tile/vector-tile-layer.ts
2061
+ function readLayer2(tag, layer, pbf) {
2062
+ if (layer && pbf) {
2063
+ if (tag === 15)
2064
+ layer.version = pbf.readVarint();
2065
+ else if (tag === 1)
2066
+ layer.name = pbf.readString();
2067
+ else if (tag === 5)
2068
+ layer.extent = pbf.readVarint();
2069
+ else if (tag === 2)
2070
+ layer._features.push(pbf.pos);
2071
+ else if (tag === 3)
2072
+ layer._keys.push(pbf.readString());
2073
+ else if (tag === 4)
2074
+ layer._values.push(readValueMessage2(pbf));
2075
+ }
2076
+ }
2077
+ function readValueMessage2(pbf) {
2078
+ let value = null;
2079
+ const end = pbf.readVarint() + pbf.pos;
2080
+ while (pbf.pos < end) {
2081
+ const tag = pbf.readVarint() >> 3;
2082
+ 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;
2083
+ }
2084
+ return value;
2085
+ }
2086
+ var VectorTileLayer2;
2087
+ var init_vector_tile_layer2 = __esm({
2088
+ "src/lib/binary-vector-tile/vector-tile-layer.ts"() {
2089
+ init_vector_tile_feature2();
2090
+ VectorTileLayer2 = class {
2091
+ constructor(pbf, end) {
2092
+ this.version = 1;
2093
+ this.name = "";
2094
+ this.extent = 4096;
2095
+ this.length = 0;
2096
+ this._pbf = pbf;
2097
+ this._keys = [];
2098
+ this._values = [];
2099
+ this._features = [];
2100
+ pbf.readFields(readLayer2, this, end);
2101
+ this.length = this._features.length;
2102
+ }
2103
+ feature(i2, geometryInfo) {
2104
+ if (i2 < 0 || i2 >= this._features.length) {
2105
+ throw new Error("feature index out of bounds");
2131
2106
  }
2107
+ this._pbf.pos = this._features[i2];
2108
+ const end = this._pbf.readVarint() + this._pbf.pos;
2109
+ return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
2110
+ }
2111
+ };
2112
+ }
2113
+ });
2114
+
2115
+ // src/lib/binary-vector-tile/vector-tile.ts
2116
+ function readTile2(tag, layers, pbf) {
2117
+ if (tag === 3) {
2118
+ if (pbf) {
2119
+ const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
2120
+ if (layer.length && layers) {
2121
+ layers[layer.name] = layer;
2132
2122
  }
2133
- return pos;
2134
2123
  }
2135
2124
  }
2125
+ }
2126
+ var VectorTile2;
2127
+ var init_vector_tile2 = __esm({
2128
+ "src/lib/binary-vector-tile/vector-tile.ts"() {
2129
+ init_vector_tile_layer2();
2130
+ VectorTile2 = class {
2131
+ constructor(pbf, end) {
2132
+ this.layers = pbf.readFields(readTile2, {}, end);
2133
+ }
2134
+ };
2135
+ }
2136
2136
  });
2137
2137
 
2138
2138
  // src/lib/parse-mvt.ts
2139
2139
  function parseMVT(arrayBuffer, options) {
2140
- options = normalizeOptions(options);
2140
+ const mvtOptions = normalizeOptions(options);
2141
+ const shape = options?.gis?.format || options?.mvt?.shape;
2142
+ switch (shape) {
2143
+ case "columnar-table":
2144
+ return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
2145
+ case "geojson-row-table": {
2146
+ const table = {
2147
+ shape: "geojson-row-table",
2148
+ data: parseToGeojson(arrayBuffer, mvtOptions)
2149
+ };
2150
+ return table;
2151
+ }
2152
+ case "geojson":
2153
+ return parseToGeojson(arrayBuffer, mvtOptions);
2154
+ case "binary-geometry":
2155
+ return parseToBinary(arrayBuffer, mvtOptions);
2156
+ case "binary":
2157
+ return parseToBinary(arrayBuffer, mvtOptions);
2158
+ default:
2159
+ throw new Error(shape);
2160
+ }
2161
+ }
2162
+ function parseToBinary(arrayBuffer, options) {
2163
+ const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);
2164
+ const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, geometryInfo);
2165
+ binaryData.byteLength = arrayBuffer.byteLength;
2166
+ return binaryData;
2167
+ }
2168
+ function parseToFlatGeoJson(arrayBuffer, options) {
2141
2169
  const features = [];
2142
- if (options) {
2143
- const binary = options.gis.format === "binary";
2144
- const geometryInfo = {
2145
- coordLength: 2,
2146
- pointPositionsCount: 0,
2147
- pointFeaturesCount: 0,
2148
- linePositionsCount: 0,
2149
- linePathsCount: 0,
2150
- lineFeaturesCount: 0,
2151
- polygonPositionsCount: 0,
2152
- polygonObjectsCount: 0,
2153
- polygonRingsCount: 0,
2154
- polygonFeaturesCount: 0
2155
- };
2156
- if (arrayBuffer.byteLength > 0) {
2157
- const tile = binary ? new VectorTile2(new import_pbf.default(arrayBuffer)) : new VectorTile(new import_pbf.default(arrayBuffer));
2158
- const loaderOptions = options.mvt;
2159
- const selectedLayers = Array.isArray(loaderOptions.layers) ? loaderOptions.layers : Object.keys(tile.layers);
2160
- selectedLayers.forEach((layerName) => {
2161
- const vectorTileLayer = tile.layers[layerName];
2162
- const featureOptions = { ...loaderOptions, layerName };
2163
- if (!vectorTileLayer) {
2164
- return;
2165
- }
2166
- for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
2167
- const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
2168
- const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
2169
- features.push(decodedFeature);
2170
- }
2171
- });
2170
+ const geometryInfo = {
2171
+ coordLength: 2,
2172
+ pointPositionsCount: 0,
2173
+ pointFeaturesCount: 0,
2174
+ linePositionsCount: 0,
2175
+ linePathsCount: 0,
2176
+ lineFeaturesCount: 0,
2177
+ polygonPositionsCount: 0,
2178
+ polygonObjectsCount: 0,
2179
+ polygonRingsCount: 0,
2180
+ polygonFeaturesCount: 0
2181
+ };
2182
+ if (arrayBuffer.byteLength <= 0) {
2183
+ return [features, geometryInfo];
2184
+ }
2185
+ const tile = new VectorTile2(new import_pbf.default(arrayBuffer));
2186
+ const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
2187
+ selectedLayers.forEach((layerName) => {
2188
+ const vectorTileLayer = tile.layers[layerName];
2189
+ if (!vectorTileLayer) {
2190
+ return;
2172
2191
  }
2173
- if (binary) {
2174
- const data = flatGeojsonToBinary(features, geometryInfo);
2175
- data.byteLength = arrayBuffer.byteLength;
2176
- return data;
2192
+ for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
2193
+ const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
2194
+ const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
2195
+ features.push(decodedFeature);
2177
2196
  }
2197
+ });
2198
+ return [features, geometryInfo];
2199
+ }
2200
+ function parseToGeojson(arrayBuffer, options) {
2201
+ if (arrayBuffer.byteLength <= 0) {
2202
+ return [];
2178
2203
  }
2204
+ const features = [];
2205
+ const tile = new VectorTile(new import_pbf.default(arrayBuffer));
2206
+ const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
2207
+ selectedLayers.forEach((layerName) => {
2208
+ const vectorTileLayer = tile.layers[layerName];
2209
+ if (!vectorTileLayer) {
2210
+ return;
2211
+ }
2212
+ for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
2213
+ const vectorTileFeature = vectorTileLayer.feature(i2);
2214
+ const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
2215
+ features.push(decodedFeature);
2216
+ }
2217
+ });
2179
2218
  return features;
2180
2219
  }
2181
2220
  function normalizeOptions(options) {
2182
- if (options) {
2183
- options = {
2184
- ...options,
2185
- mvt: options.mvt || {},
2186
- gis: options.gis || {}
2187
- };
2188
- const wgs84Coordinates = options.coordinates === "wgs84";
2189
- const { tileIndex } = options;
2190
- const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
2191
- if (wgs84Coordinates && !hasTileIndex) {
2192
- throw new Error("MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.");
2193
- }
2221
+ if (!options?.mvt) {
2222
+ throw new Error("mvt options required");
2223
+ }
2224
+ const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
2225
+ const { tileIndex } = options.mvt;
2226
+ const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
2227
+ if (wgs84Coordinates && !hasTileIndex) {
2228
+ throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
2194
2229
  }
2195
- return options;
2230
+ return options.mvt;
2196
2231
  }
2197
- function getDecodedFeature(feature, options) {
2232
+ function getDecodedFeature(feature, options, layerName) {
2198
2233
  const decodedFeature = feature.toGeoJSON(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates);
2199
2234
  if (options.layerProperty) {
2200
- decodedFeature.properties[options.layerProperty] = options.layerName;
2235
+ decodedFeature.properties[options.layerProperty] = layerName;
2201
2236
  }
2202
2237
  return decodedFeature;
2203
2238
  }
2204
- function getDecodedFeatureBinary(feature, options) {
2239
+ function getDecodedFeatureBinary(feature, options, layerName) {
2205
2240
  const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
2206
2241
  if (options.layerProperty && decodedFeature.properties) {
2207
- decodedFeature.properties[options.layerProperty] = options.layerName;
2242
+ decodedFeature.properties[options.layerProperty] = layerName;
2208
2243
  }
2209
2244
  return decodedFeature;
2210
2245
  }
@@ -2225,19 +2260,28 @@
2225
2260
  var import_pbf;
2226
2261
  var init_parse_mvt = __esm({
2227
2262
  "src/lib/parse-mvt.ts"() {
2228
- init_vector_tile();
2229
- init_vector_tile2();
2230
2263
  init_src();
2231
2264
  import_pbf = __toModule(require_pbf());
2265
+ init_vector_tile();
2266
+ init_vector_tile2();
2232
2267
  }
2233
2268
  });
2234
2269
 
2235
2270
  // src/mvt-loader.ts
2236
- var VERSION, MVTWorkerLoader, MVTLoader;
2271
+ var VERSION, DEFAULT_MVT_LOADER_OPTIONS, MVTWorkerLoader, MVTLoader;
2237
2272
  var init_mvt_loader = __esm({
2238
2273
  "src/mvt-loader.ts"() {
2239
2274
  init_parse_mvt();
2240
2275
  VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2276
+ DEFAULT_MVT_LOADER_OPTIONS = {
2277
+ mvt: {
2278
+ shape: "geojson",
2279
+ coordinates: "local",
2280
+ layerProperty: "layerName",
2281
+ layers: void 0,
2282
+ tileIndex: null
2283
+ }
2284
+ };
2241
2285
  MVTWorkerLoader = {
2242
2286
  name: "Mapbox Vector Tile",
2243
2287
  id: "mvt",
@@ -2250,14 +2294,7 @@
2250
2294
  ],
2251
2295
  worker: true,
2252
2296
  category: "geometry",
2253
- options: {
2254
- mvt: {
2255
- coordinates: "local",
2256
- layerProperty: "layerName",
2257
- layers: null,
2258
- tileIndex: null
2259
- }
2260
- }
2297
+ options: DEFAULT_MVT_LOADER_OPTIONS
2261
2298
  };
2262
2299
  MVTLoader = {
2263
2300
  ...MVTWorkerLoader,