@loaders.gl/mvt 4.0.0-alpha.4 → 4.0.0-alpha.5
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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/dist.min.js +2289 -0
- package/dist/helpers/binary-util-functions.d.ts +35 -0
- package/dist/helpers/binary-util-functions.d.ts.map +1 -0
- package/dist/helpers/binary-util-functions.js +8 -5
- package/dist/helpers/binary-util-functions.js.map +1 -1
- package/dist/helpers/mapbox-util-functions.d.ts +29 -0
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +41 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +31 -30
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +2 -2
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +27 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/parse-mvt.d.ts +17 -0
- package/dist/lib/parse-mvt.d.ts.map +1 -0
- package/dist/lib/parse-mvt.js +6 -5
- package/dist/lib/parse-mvt.js.map +1 -1
- package/dist/lib/types.d.ts +28 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/mvt-loader.d.ts +10 -0
- package/dist/mvt-loader.d.ts.map +1 -0
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-worker.js +103 -98
- package/dist/workers/mvt-worker.d.ts +2 -0
- package/dist/workers/mvt-worker.d.ts.map +1 -0
- package/package.json +8 -7
- package/src/helpers/binary-util-functions.ts +9 -7
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +36 -44
- package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
- package/src/lib/parse-mvt.ts +11 -9
- package/src/lib/types.ts +0 -69
- package/dist/lib/binary-vector-tile/features-to-binary.js +0 -327
- package/dist/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
package/dist/dist.min.js
ADDED
|
@@ -0,0 +1,2289 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
12
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
13
|
+
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
|
+
};
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
__markAsModule(target);
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, module, desc) => {
|
|
21
|
+
if (module && typeof module === "object" || typeof module === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(module))
|
|
23
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
24
|
+
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
};
|
|
28
|
+
var __toModule = (module) => {
|
|
29
|
+
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// 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]);
|
|
52
|
+
}
|
|
53
|
+
if (polygon)
|
|
54
|
+
polygons.push(polygon);
|
|
55
|
+
return polygons;
|
|
56
|
+
}
|
|
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]);
|
|
63
|
+
}
|
|
64
|
+
return sum;
|
|
65
|
+
}
|
|
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;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
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;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
var init_mapbox_util_functions = __esm({
|
|
87
|
+
"src/helpers/mapbox-util-functions.ts"() {
|
|
88
|
+
}
|
|
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
|
+
};
|
|
251
|
+
}
|
|
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));
|
|
269
|
+
}
|
|
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;
|
|
277
|
+
}
|
|
278
|
+
return value;
|
|
279
|
+
}
|
|
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
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
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);
|
|
327
|
+
}
|
|
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);
|
|
557
|
+
}
|
|
558
|
+
function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
|
|
559
|
+
const queue = [];
|
|
560
|
+
let i2;
|
|
561
|
+
let len;
|
|
562
|
+
let start;
|
|
563
|
+
let end;
|
|
564
|
+
let list;
|
|
565
|
+
for (i2 = 0, len = holeIndices.length; i2 < len; i2++) {
|
|
566
|
+
start = holeIndices[i2] * dim;
|
|
567
|
+
end = i2 < len - 1 ? holeIndices[i2 + 1] * dim : data.length;
|
|
568
|
+
list = linkedList(data, start, end, dim, false, areas && areas[i2 + 1]);
|
|
569
|
+
if (list === list.next)
|
|
570
|
+
list.steiner = true;
|
|
571
|
+
queue.push(getLeftmost(list));
|
|
572
|
+
}
|
|
573
|
+
queue.sort(compareX);
|
|
574
|
+
for (i2 = 0; i2 < queue.length; i2++) {
|
|
575
|
+
eliminateHole(queue[i2], outerNode);
|
|
576
|
+
outerNode = filterPoints(outerNode, outerNode.next);
|
|
577
|
+
}
|
|
578
|
+
return outerNode;
|
|
579
|
+
}
|
|
580
|
+
function compareX(a, b) {
|
|
581
|
+
return a.x - b.x;
|
|
582
|
+
}
|
|
583
|
+
function eliminateHole(hole, outerNode) {
|
|
584
|
+
outerNode = findHoleBridge(hole, outerNode);
|
|
585
|
+
if (outerNode) {
|
|
586
|
+
const b = splitPolygon(outerNode, hole);
|
|
587
|
+
filterPoints(outerNode, outerNode.next);
|
|
588
|
+
filterPoints(b, b.next);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
function findHoleBridge(hole, outerNode) {
|
|
592
|
+
let p = outerNode;
|
|
593
|
+
const hx = hole.x;
|
|
594
|
+
const hy = hole.y;
|
|
595
|
+
let qx = -Infinity;
|
|
596
|
+
let m;
|
|
597
|
+
do {
|
|
598
|
+
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
|
599
|
+
const x2 = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
|
600
|
+
if (x2 <= hx && x2 > qx) {
|
|
601
|
+
qx = x2;
|
|
602
|
+
if (x2 === hx) {
|
|
603
|
+
if (hy === p.y)
|
|
604
|
+
return p;
|
|
605
|
+
if (hy === p.next.y)
|
|
606
|
+
return p.next;
|
|
607
|
+
}
|
|
608
|
+
m = p.x < p.next.x ? p : p.next;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
p = p.next;
|
|
612
|
+
} while (p !== outerNode);
|
|
613
|
+
if (!m)
|
|
614
|
+
return null;
|
|
615
|
+
if (hx === qx)
|
|
616
|
+
return m;
|
|
617
|
+
const stop = m;
|
|
618
|
+
const mx = m.x;
|
|
619
|
+
const my = m.y;
|
|
620
|
+
let tanMin = Infinity;
|
|
621
|
+
let tan;
|
|
622
|
+
p = m;
|
|
623
|
+
do {
|
|
624
|
+
if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
|
625
|
+
tan = Math.abs(hy - p.y) / (hx - p.x);
|
|
626
|
+
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
|
|
627
|
+
m = p;
|
|
628
|
+
tanMin = tan;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
p = p.next;
|
|
632
|
+
} while (p !== stop);
|
|
633
|
+
return m;
|
|
634
|
+
}
|
|
635
|
+
function sectorContainsSector(m, p) {
|
|
636
|
+
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
|
637
|
+
}
|
|
638
|
+
function indexCurve(start, minX, minY, invSize) {
|
|
639
|
+
let p = start;
|
|
640
|
+
do {
|
|
641
|
+
if (p.z === null)
|
|
642
|
+
p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
|
643
|
+
p.prevZ = p.prev;
|
|
644
|
+
p.nextZ = p.next;
|
|
645
|
+
p = p.next;
|
|
646
|
+
} while (p !== start);
|
|
647
|
+
p.prevZ.nextZ = null;
|
|
648
|
+
p.prevZ = null;
|
|
649
|
+
sortLinked(p);
|
|
650
|
+
}
|
|
651
|
+
function sortLinked(list) {
|
|
652
|
+
let e;
|
|
653
|
+
let i2;
|
|
654
|
+
let inSize = 1;
|
|
655
|
+
let numMerges;
|
|
656
|
+
let p;
|
|
657
|
+
let pSize;
|
|
658
|
+
let q;
|
|
659
|
+
let qSize;
|
|
660
|
+
let tail;
|
|
661
|
+
do {
|
|
662
|
+
p = list;
|
|
663
|
+
list = null;
|
|
664
|
+
tail = null;
|
|
665
|
+
numMerges = 0;
|
|
666
|
+
while (p) {
|
|
667
|
+
numMerges++;
|
|
668
|
+
q = p;
|
|
669
|
+
pSize = 0;
|
|
670
|
+
for (i2 = 0; i2 < inSize; i2++) {
|
|
671
|
+
pSize++;
|
|
672
|
+
q = q.nextZ;
|
|
673
|
+
if (!q)
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
qSize = inSize;
|
|
677
|
+
while (pSize > 0 || qSize > 0 && q) {
|
|
678
|
+
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
|
679
|
+
e = p;
|
|
680
|
+
p = p.nextZ;
|
|
681
|
+
pSize--;
|
|
682
|
+
} else {
|
|
683
|
+
e = q;
|
|
684
|
+
q = q.nextZ;
|
|
685
|
+
qSize--;
|
|
686
|
+
}
|
|
687
|
+
if (tail)
|
|
688
|
+
tail.nextZ = e;
|
|
689
|
+
else
|
|
690
|
+
list = e;
|
|
691
|
+
e.prevZ = tail;
|
|
692
|
+
tail = e;
|
|
693
|
+
}
|
|
694
|
+
p = q;
|
|
695
|
+
}
|
|
696
|
+
tail.nextZ = null;
|
|
697
|
+
inSize *= 2;
|
|
698
|
+
} while (numMerges > 1);
|
|
699
|
+
return list;
|
|
700
|
+
}
|
|
701
|
+
function zOrder(x2, y2, minX, minY, invSize) {
|
|
702
|
+
x2 = 32767 * (x2 - minX) * invSize;
|
|
703
|
+
y2 = 32767 * (y2 - minY) * invSize;
|
|
704
|
+
x2 = (x2 | x2 << 8) & 16711935;
|
|
705
|
+
x2 = (x2 | x2 << 4) & 252645135;
|
|
706
|
+
x2 = (x2 | x2 << 2) & 858993459;
|
|
707
|
+
x2 = (x2 | x2 << 1) & 1431655765;
|
|
708
|
+
y2 = (y2 | y2 << 8) & 16711935;
|
|
709
|
+
y2 = (y2 | y2 << 4) & 252645135;
|
|
710
|
+
y2 = (y2 | y2 << 2) & 858993459;
|
|
711
|
+
y2 = (y2 | y2 << 1) & 1431655765;
|
|
712
|
+
return x2 | y2 << 1;
|
|
713
|
+
}
|
|
714
|
+
function getLeftmost(start) {
|
|
715
|
+
let p = start;
|
|
716
|
+
let leftmost = start;
|
|
717
|
+
do {
|
|
718
|
+
if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
|
|
719
|
+
leftmost = p;
|
|
720
|
+
p = p.next;
|
|
721
|
+
} while (p !== start);
|
|
722
|
+
return leftmost;
|
|
723
|
+
}
|
|
724
|
+
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
|
725
|
+
return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
|
|
726
|
+
}
|
|
727
|
+
function isValidDiagonal(a, b) {
|
|
728
|
+
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
|
|
729
|
+
}
|
|
730
|
+
function area(p, q, r) {
|
|
731
|
+
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
732
|
+
}
|
|
733
|
+
function equals(p1, p2) {
|
|
734
|
+
return p1.x === p2.x && p1.y === p2.y;
|
|
735
|
+
}
|
|
736
|
+
function intersects(p1, q1, p2, q2) {
|
|
737
|
+
const o1 = sign(area(p1, q1, p2));
|
|
738
|
+
const o2 = sign(area(p1, q1, q2));
|
|
739
|
+
const o3 = sign(area(p2, q2, p1));
|
|
740
|
+
const o4 = sign(area(p2, q2, q1));
|
|
741
|
+
if (o1 !== o2 && o3 !== o4)
|
|
742
|
+
return true;
|
|
743
|
+
if (o1 === 0 && onSegment(p1, p2, q1))
|
|
744
|
+
return true;
|
|
745
|
+
if (o2 === 0 && onSegment(p1, q2, q1))
|
|
746
|
+
return true;
|
|
747
|
+
if (o3 === 0 && onSegment(p2, p1, q2))
|
|
748
|
+
return true;
|
|
749
|
+
if (o4 === 0 && onSegment(p2, q1, q2))
|
|
750
|
+
return true;
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
function onSegment(p, q, r) {
|
|
754
|
+
return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
|
|
755
|
+
}
|
|
756
|
+
function sign(num) {
|
|
757
|
+
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
|
758
|
+
}
|
|
759
|
+
function intersectsPolygon(a, b) {
|
|
760
|
+
let p = a;
|
|
761
|
+
do {
|
|
762
|
+
if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
|
|
763
|
+
return true;
|
|
764
|
+
p = p.next;
|
|
765
|
+
} while (p !== a);
|
|
766
|
+
return false;
|
|
767
|
+
}
|
|
768
|
+
function locallyInside(a, b) {
|
|
769
|
+
return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
|
|
770
|
+
}
|
|
771
|
+
function middleInside(a, b) {
|
|
772
|
+
let p = a;
|
|
773
|
+
let inside = false;
|
|
774
|
+
const px = (a.x + b.x) / 2;
|
|
775
|
+
const py = (a.y + b.y) / 2;
|
|
776
|
+
do {
|
|
777
|
+
if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
|
|
778
|
+
inside = !inside;
|
|
779
|
+
p = p.next;
|
|
780
|
+
} while (p !== a);
|
|
781
|
+
return inside;
|
|
782
|
+
}
|
|
783
|
+
function splitPolygon(a, b) {
|
|
784
|
+
const a2 = new Node(a.i, a.x, a.y);
|
|
785
|
+
const b2 = new Node(b.i, b.x, b.y);
|
|
786
|
+
const an = a.next;
|
|
787
|
+
const bp = b.prev;
|
|
788
|
+
a.next = b;
|
|
789
|
+
b.prev = a;
|
|
790
|
+
a2.next = an;
|
|
791
|
+
an.prev = a2;
|
|
792
|
+
b2.next = a2;
|
|
793
|
+
a2.prev = b2;
|
|
794
|
+
bp.next = b2;
|
|
795
|
+
b2.prev = bp;
|
|
796
|
+
return b2;
|
|
797
|
+
}
|
|
798
|
+
function insertNode(i2, x2, y2, last) {
|
|
799
|
+
const p = new Node(i2, x2, y2);
|
|
800
|
+
if (!last) {
|
|
801
|
+
p.prev = p;
|
|
802
|
+
p.next = p;
|
|
803
|
+
} else {
|
|
804
|
+
p.next = last.next;
|
|
805
|
+
p.prev = last;
|
|
806
|
+
last.next.prev = p;
|
|
807
|
+
last.next = p;
|
|
808
|
+
}
|
|
809
|
+
return p;
|
|
810
|
+
}
|
|
811
|
+
function removeNode(p) {
|
|
812
|
+
p.next.prev = p.prev;
|
|
813
|
+
p.prev.next = p.next;
|
|
814
|
+
if (p.prevZ)
|
|
815
|
+
p.prevZ.nextZ = p.nextZ;
|
|
816
|
+
if (p.nextZ)
|
|
817
|
+
p.nextZ.prevZ = p.prevZ;
|
|
818
|
+
}
|
|
819
|
+
function Node(i2, x2, y2) {
|
|
820
|
+
this.i = i2;
|
|
821
|
+
this.x = x2;
|
|
822
|
+
this.y = y2;
|
|
823
|
+
this.prev = null;
|
|
824
|
+
this.next = null;
|
|
825
|
+
this.z = null;
|
|
826
|
+
this.prevZ = null;
|
|
827
|
+
this.nextZ = null;
|
|
828
|
+
this.steiner = false;
|
|
829
|
+
}
|
|
830
|
+
var init_earcut = __esm({
|
|
831
|
+
"../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
|
|
832
|
+
init_polygon_utils();
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/utils.js
|
|
837
|
+
var init_utils = __esm({
|
|
838
|
+
"../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
|
|
843
|
+
var init_lineclip = __esm({
|
|
844
|
+
"../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
|
|
845
|
+
init_utils();
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
|
|
850
|
+
var init_cut_by_grid = __esm({
|
|
851
|
+
"../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
|
|
852
|
+
init_lineclip();
|
|
853
|
+
init_utils();
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
|
|
858
|
+
var init_cut_by_mercator_bounds = __esm({
|
|
859
|
+
"../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
|
|
860
|
+
init_cut_by_grid();
|
|
861
|
+
init_utils();
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/index.js
|
|
866
|
+
var init_esm = __esm({
|
|
867
|
+
"../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
|
|
868
|
+
init_polygon();
|
|
869
|
+
init_polygon_utils();
|
|
870
|
+
init_earcut();
|
|
871
|
+
init_lineclip();
|
|
872
|
+
init_cut_by_grid();
|
|
873
|
+
init_cut_by_mercator_bounds();
|
|
874
|
+
init_polygon();
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
|
|
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
|
+
return this._toBinaryCoordinates(project);
|
|
1057
|
+
}
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
|
|
1062
|
+
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
1063
|
+
function readLayer2(tag, layer, pbf) {
|
|
1064
|
+
if (layer && pbf) {
|
|
1065
|
+
if (tag === 15)
|
|
1066
|
+
layer.version = pbf.readVarint();
|
|
1067
|
+
else if (tag === 1)
|
|
1068
|
+
layer.name = pbf.readString();
|
|
1069
|
+
else if (tag === 5)
|
|
1070
|
+
layer.extent = pbf.readVarint();
|
|
1071
|
+
else if (tag === 2)
|
|
1072
|
+
layer._features.push(pbf.pos);
|
|
1073
|
+
else if (tag === 3)
|
|
1074
|
+
layer._keys.push(pbf.readString());
|
|
1075
|
+
else if (tag === 4)
|
|
1076
|
+
layer._values.push(readValueMessage2(pbf));
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
function readValueMessage2(pbf) {
|
|
1080
|
+
let value = null;
|
|
1081
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1082
|
+
while (pbf.pos < end) {
|
|
1083
|
+
const tag = pbf.readVarint() >> 3;
|
|
1084
|
+
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;
|
|
1085
|
+
}
|
|
1086
|
+
return value;
|
|
1087
|
+
}
|
|
1088
|
+
var VectorTileLayer2;
|
|
1089
|
+
var init_vector_tile_layer2 = __esm({
|
|
1090
|
+
"src/lib/binary-vector-tile/vector-tile-layer.ts"() {
|
|
1091
|
+
init_vector_tile_feature2();
|
|
1092
|
+
VectorTileLayer2 = class {
|
|
1093
|
+
constructor(pbf, end) {
|
|
1094
|
+
this.version = 1;
|
|
1095
|
+
this.name = "";
|
|
1096
|
+
this.extent = 4096;
|
|
1097
|
+
this.length = 0;
|
|
1098
|
+
this._pbf = pbf;
|
|
1099
|
+
this._keys = [];
|
|
1100
|
+
this._values = [];
|
|
1101
|
+
this._features = [];
|
|
1102
|
+
pbf.readFields(readLayer2, this, end);
|
|
1103
|
+
this.length = this._features.length;
|
|
1104
|
+
}
|
|
1105
|
+
feature(i2, geometryInfo) {
|
|
1106
|
+
if (i2 < 0 || i2 >= this._features.length) {
|
|
1107
|
+
throw new Error("feature index out of bounds");
|
|
1108
|
+
}
|
|
1109
|
+
this._pbf.pos = this._features[i2];
|
|
1110
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1111
|
+
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
|
|
1117
|
+
// src/lib/binary-vector-tile/vector-tile.ts
|
|
1118
|
+
function readTile2(tag, layers, pbf) {
|
|
1119
|
+
if (tag === 3) {
|
|
1120
|
+
if (pbf) {
|
|
1121
|
+
const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
|
|
1122
|
+
if (layer.length && layers) {
|
|
1123
|
+
layers[layer.name] = layer;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
var VectorTile2;
|
|
1129
|
+
var init_vector_tile2 = __esm({
|
|
1130
|
+
"src/lib/binary-vector-tile/vector-tile.ts"() {
|
|
1131
|
+
init_vector_tile_layer2();
|
|
1132
|
+
VectorTile2 = class {
|
|
1133
|
+
constructor(pbf, end) {
|
|
1134
|
+
this.layers = pbf.readFields(readTile2, {}, end);
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
});
|
|
1139
|
+
|
|
1140
|
+
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1141
|
+
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1142
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
1143
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1144
|
+
return fillArrays(features, {
|
|
1145
|
+
propArrayTypes,
|
|
1146
|
+
...geometryInfo
|
|
1147
|
+
}, {
|
|
1148
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1149
|
+
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
function extractNumericPropTypes(features) {
|
|
1153
|
+
const propArrayTypes = {};
|
|
1154
|
+
for (const feature of features) {
|
|
1155
|
+
if (feature.properties) {
|
|
1156
|
+
for (const key in feature.properties) {
|
|
1157
|
+
const val = feature.properties[key];
|
|
1158
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
return propArrayTypes;
|
|
1163
|
+
}
|
|
1164
|
+
function fillArrays(features, geometryInfo, options) {
|
|
1165
|
+
const {
|
|
1166
|
+
pointPositionsCount,
|
|
1167
|
+
pointFeaturesCount,
|
|
1168
|
+
linePositionsCount,
|
|
1169
|
+
linePathsCount,
|
|
1170
|
+
lineFeaturesCount,
|
|
1171
|
+
polygonPositionsCount,
|
|
1172
|
+
polygonObjectsCount,
|
|
1173
|
+
polygonRingsCount,
|
|
1174
|
+
polygonFeaturesCount,
|
|
1175
|
+
propArrayTypes,
|
|
1176
|
+
coordLength
|
|
1177
|
+
} = geometryInfo;
|
|
1178
|
+
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
1179
|
+
const hasGlobalId = features[0] && "id" in features[0];
|
|
1180
|
+
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1181
|
+
const points = {
|
|
1182
|
+
type: "Point",
|
|
1183
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1184
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1185
|
+
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1186
|
+
numericProps: {},
|
|
1187
|
+
properties: [],
|
|
1188
|
+
fields: []
|
|
1189
|
+
};
|
|
1190
|
+
const lines = {
|
|
1191
|
+
type: "LineString",
|
|
1192
|
+
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
1193
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
1194
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
1195
|
+
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
1196
|
+
numericProps: {},
|
|
1197
|
+
properties: [],
|
|
1198
|
+
fields: []
|
|
1199
|
+
};
|
|
1200
|
+
const polygons = {
|
|
1201
|
+
type: "Polygon",
|
|
1202
|
+
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1203
|
+
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1204
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
1205
|
+
triangles: [],
|
|
1206
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1207
|
+
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1208
|
+
numericProps: {},
|
|
1209
|
+
properties: [],
|
|
1210
|
+
fields: []
|
|
1211
|
+
};
|
|
1212
|
+
for (const object of [points, lines, polygons]) {
|
|
1213
|
+
for (const propName of numericPropKeys) {
|
|
1214
|
+
const T = propArrayTypes[propName];
|
|
1215
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
1219
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
1220
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
1221
|
+
const indexMap = {
|
|
1222
|
+
pointPosition: 0,
|
|
1223
|
+
pointFeature: 0,
|
|
1224
|
+
linePosition: 0,
|
|
1225
|
+
linePath: 0,
|
|
1226
|
+
lineFeature: 0,
|
|
1227
|
+
polygonPosition: 0,
|
|
1228
|
+
polygonObject: 0,
|
|
1229
|
+
polygonRing: 0,
|
|
1230
|
+
polygonFeature: 0,
|
|
1231
|
+
feature: 0
|
|
1232
|
+
};
|
|
1233
|
+
for (const feature of features) {
|
|
1234
|
+
const geometry = feature.geometry;
|
|
1235
|
+
const properties = feature.properties || {};
|
|
1236
|
+
switch (geometry.type) {
|
|
1237
|
+
case "Point":
|
|
1238
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1239
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1240
|
+
if (hasGlobalId) {
|
|
1241
|
+
points.fields.push({ id: feature.id });
|
|
1242
|
+
}
|
|
1243
|
+
indexMap.pointFeature++;
|
|
1244
|
+
break;
|
|
1245
|
+
case "LineString":
|
|
1246
|
+
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1247
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1248
|
+
if (hasGlobalId) {
|
|
1249
|
+
lines.fields.push({ id: feature.id });
|
|
1250
|
+
}
|
|
1251
|
+
indexMap.lineFeature++;
|
|
1252
|
+
break;
|
|
1253
|
+
case "Polygon":
|
|
1254
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1255
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1256
|
+
if (hasGlobalId) {
|
|
1257
|
+
polygons.fields.push({ id: feature.id });
|
|
1258
|
+
}
|
|
1259
|
+
indexMap.polygonFeature++;
|
|
1260
|
+
break;
|
|
1261
|
+
default:
|
|
1262
|
+
throw new Error("Invalid geometry type");
|
|
1263
|
+
}
|
|
1264
|
+
indexMap.feature++;
|
|
1265
|
+
}
|
|
1266
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
1267
|
+
}
|
|
1268
|
+
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
1269
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
1270
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1271
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
1272
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1273
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1274
|
+
indexMap.pointPosition += nPositions;
|
|
1275
|
+
}
|
|
1276
|
+
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1277
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1278
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1279
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1280
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1281
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1282
|
+
for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
|
|
1283
|
+
const start = geometry.indices[i2];
|
|
1284
|
+
const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
|
|
1285
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1286
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
1290
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
1291
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1292
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
1293
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1294
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1295
|
+
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
1296
|
+
const startPosition = indexMap.polygonPosition;
|
|
1297
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
1298
|
+
const areas = geometry.areas[l];
|
|
1299
|
+
const indices = geometry.indices[l];
|
|
1300
|
+
const nextIndices = geometry.indices[l + 1];
|
|
1301
|
+
for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
|
|
1302
|
+
const start = indices[i2];
|
|
1303
|
+
const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
|
|
1304
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
1305
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
1306
|
+
}
|
|
1307
|
+
const endPosition = indexMap.polygonPosition;
|
|
1308
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
function triangulatePolygon(polygons, areas, indices, {
|
|
1312
|
+
startPosition,
|
|
1313
|
+
endPosition,
|
|
1314
|
+
coordLength
|
|
1315
|
+
}) {
|
|
1316
|
+
const start = startPosition * coordLength;
|
|
1317
|
+
const end = endPosition * coordLength;
|
|
1318
|
+
const polygonPositions = polygons.positions.subarray(start, end);
|
|
1319
|
+
const offset = indices[0];
|
|
1320
|
+
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
1321
|
+
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
1322
|
+
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
1323
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
function wrapProps(obj, size) {
|
|
1327
|
+
const returnObj = {};
|
|
1328
|
+
for (const key in obj) {
|
|
1329
|
+
returnObj[key] = { value: obj[key], size };
|
|
1330
|
+
}
|
|
1331
|
+
return returnObj;
|
|
1332
|
+
}
|
|
1333
|
+
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1334
|
+
return {
|
|
1335
|
+
points: {
|
|
1336
|
+
...points,
|
|
1337
|
+
positions: { value: points.positions, size: coordLength },
|
|
1338
|
+
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
1339
|
+
featureIds: { value: points.featureIds, size: 1 },
|
|
1340
|
+
numericProps: wrapProps(points.numericProps, 1)
|
|
1341
|
+
},
|
|
1342
|
+
lines: {
|
|
1343
|
+
...lines,
|
|
1344
|
+
positions: { value: lines.positions, size: coordLength },
|
|
1345
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1346
|
+
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
1347
|
+
featureIds: { value: lines.featureIds, size: 1 },
|
|
1348
|
+
numericProps: wrapProps(lines.numericProps, 1)
|
|
1349
|
+
},
|
|
1350
|
+
polygons: {
|
|
1351
|
+
...polygons,
|
|
1352
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
1353
|
+
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
1354
|
+
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
1355
|
+
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
1356
|
+
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
1357
|
+
featureIds: { value: polygons.featureIds, size: 1 },
|
|
1358
|
+
numericProps: wrapProps(polygons.numericProps, 1)
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
function fillNumericProperties(object, properties, index, length2) {
|
|
1363
|
+
for (const numericPropName in object.numericProps) {
|
|
1364
|
+
if (numericPropName in properties) {
|
|
1365
|
+
const value = properties[numericPropName];
|
|
1366
|
+
object.numericProps[numericPropName].fill(value, index, index + length2);
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
function keepStringProperties(properties, numericKeys) {
|
|
1371
|
+
const props = {};
|
|
1372
|
+
for (const key in properties) {
|
|
1373
|
+
if (!numericKeys.includes(key)) {
|
|
1374
|
+
props[key] = properties[key];
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
return props;
|
|
1378
|
+
}
|
|
1379
|
+
function deduceArrayType(x2, constructor) {
|
|
1380
|
+
if (constructor === Array || !Number.isFinite(x2)) {
|
|
1381
|
+
return Array;
|
|
1382
|
+
}
|
|
1383
|
+
return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
|
|
1384
|
+
}
|
|
1385
|
+
var init_flat_geojson_to_binary = __esm({
|
|
1386
|
+
"../gis/src/lib/flat-geojson-to-binary.ts"() {
|
|
1387
|
+
init_esm();
|
|
1388
|
+
}
|
|
1389
|
+
});
|
|
1390
|
+
|
|
1391
|
+
// ../gis/src/index.ts
|
|
1392
|
+
var init_src = __esm({
|
|
1393
|
+
"../gis/src/index.ts"() {
|
|
1394
|
+
init_flat_geojson_to_binary();
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
// ../../node_modules/ieee754/index.js
|
|
1399
|
+
var require_ieee754 = __commonJS({
|
|
1400
|
+
"../../node_modules/ieee754/index.js"(exports) {
|
|
1401
|
+
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
1402
|
+
var e, m;
|
|
1403
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
1404
|
+
var eMax = (1 << eLen) - 1;
|
|
1405
|
+
var eBias = eMax >> 1;
|
|
1406
|
+
var nBits = -7;
|
|
1407
|
+
var i2 = isLE ? nBytes - 1 : 0;
|
|
1408
|
+
var d = isLE ? -1 : 1;
|
|
1409
|
+
var s = buffer[offset + i2];
|
|
1410
|
+
i2 += d;
|
|
1411
|
+
e = s & (1 << -nBits) - 1;
|
|
1412
|
+
s >>= -nBits;
|
|
1413
|
+
nBits += eLen;
|
|
1414
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
|
|
1415
|
+
}
|
|
1416
|
+
m = e & (1 << -nBits) - 1;
|
|
1417
|
+
e >>= -nBits;
|
|
1418
|
+
nBits += mLen;
|
|
1419
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
|
|
1420
|
+
}
|
|
1421
|
+
if (e === 0) {
|
|
1422
|
+
e = 1 - eBias;
|
|
1423
|
+
} else if (e === eMax) {
|
|
1424
|
+
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
1425
|
+
} else {
|
|
1426
|
+
m = m + Math.pow(2, mLen);
|
|
1427
|
+
e = e - eBias;
|
|
1428
|
+
}
|
|
1429
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
1430
|
+
};
|
|
1431
|
+
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
1432
|
+
var e, m, c;
|
|
1433
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
1434
|
+
var eMax = (1 << eLen) - 1;
|
|
1435
|
+
var eBias = eMax >> 1;
|
|
1436
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
1437
|
+
var i2 = isLE ? 0 : nBytes - 1;
|
|
1438
|
+
var d = isLE ? 1 : -1;
|
|
1439
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
1440
|
+
value = Math.abs(value);
|
|
1441
|
+
if (isNaN(value) || value === Infinity) {
|
|
1442
|
+
m = isNaN(value) ? 1 : 0;
|
|
1443
|
+
e = eMax;
|
|
1444
|
+
} else {
|
|
1445
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
1446
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
1447
|
+
e--;
|
|
1448
|
+
c *= 2;
|
|
1449
|
+
}
|
|
1450
|
+
if (e + eBias >= 1) {
|
|
1451
|
+
value += rt / c;
|
|
1452
|
+
} else {
|
|
1453
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
1454
|
+
}
|
|
1455
|
+
if (value * c >= 2) {
|
|
1456
|
+
e++;
|
|
1457
|
+
c /= 2;
|
|
1458
|
+
}
|
|
1459
|
+
if (e + eBias >= eMax) {
|
|
1460
|
+
m = 0;
|
|
1461
|
+
e = eMax;
|
|
1462
|
+
} else if (e + eBias >= 1) {
|
|
1463
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
1464
|
+
e = e + eBias;
|
|
1465
|
+
} else {
|
|
1466
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
1467
|
+
e = 0;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
for (; mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8) {
|
|
1471
|
+
}
|
|
1472
|
+
e = e << mLen | m;
|
|
1473
|
+
eLen += mLen;
|
|
1474
|
+
for (; eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8) {
|
|
1475
|
+
}
|
|
1476
|
+
buffer[offset + i2 - d] |= s * 128;
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
|
|
1481
|
+
// ../../node_modules/pbf/index.js
|
|
1482
|
+
var require_pbf = __commonJS({
|
|
1483
|
+
"../../node_modules/pbf/index.js"(exports, module) {
|
|
1484
|
+
"use strict";
|
|
1485
|
+
module.exports = Pbf;
|
|
1486
|
+
var ieee754 = require_ieee754();
|
|
1487
|
+
function Pbf(buf) {
|
|
1488
|
+
this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
|
|
1489
|
+
this.pos = 0;
|
|
1490
|
+
this.type = 0;
|
|
1491
|
+
this.length = this.buf.length;
|
|
1492
|
+
}
|
|
1493
|
+
Pbf.Varint = 0;
|
|
1494
|
+
Pbf.Fixed64 = 1;
|
|
1495
|
+
Pbf.Bytes = 2;
|
|
1496
|
+
Pbf.Fixed32 = 5;
|
|
1497
|
+
var SHIFT_LEFT_32 = (1 << 16) * (1 << 16);
|
|
1498
|
+
var SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;
|
|
1499
|
+
var TEXT_DECODER_MIN_LENGTH = 12;
|
|
1500
|
+
var utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf8");
|
|
1501
|
+
Pbf.prototype = {
|
|
1502
|
+
destroy: function() {
|
|
1503
|
+
this.buf = null;
|
|
1504
|
+
},
|
|
1505
|
+
readFields: function(readField, result, end) {
|
|
1506
|
+
end = end || this.length;
|
|
1507
|
+
while (this.pos < end) {
|
|
1508
|
+
var val = this.readVarint(), tag = val >> 3, startPos = this.pos;
|
|
1509
|
+
this.type = val & 7;
|
|
1510
|
+
readField(tag, result, this);
|
|
1511
|
+
if (this.pos === startPos)
|
|
1512
|
+
this.skip(val);
|
|
1513
|
+
}
|
|
1514
|
+
return result;
|
|
1515
|
+
},
|
|
1516
|
+
readMessage: function(readField, result) {
|
|
1517
|
+
return this.readFields(readField, result, this.readVarint() + this.pos);
|
|
1518
|
+
},
|
|
1519
|
+
readFixed32: function() {
|
|
1520
|
+
var val = readUInt32(this.buf, this.pos);
|
|
1521
|
+
this.pos += 4;
|
|
1522
|
+
return val;
|
|
1523
|
+
},
|
|
1524
|
+
readSFixed32: function() {
|
|
1525
|
+
var val = readInt32(this.buf, this.pos);
|
|
1526
|
+
this.pos += 4;
|
|
1527
|
+
return val;
|
|
1528
|
+
},
|
|
1529
|
+
readFixed64: function() {
|
|
1530
|
+
var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
|
|
1531
|
+
this.pos += 8;
|
|
1532
|
+
return val;
|
|
1533
|
+
},
|
|
1534
|
+
readSFixed64: function() {
|
|
1535
|
+
var val = readUInt32(this.buf, this.pos) + readInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
|
|
1536
|
+
this.pos += 8;
|
|
1537
|
+
return val;
|
|
1538
|
+
},
|
|
1539
|
+
readFloat: function() {
|
|
1540
|
+
var val = ieee754.read(this.buf, this.pos, true, 23, 4);
|
|
1541
|
+
this.pos += 4;
|
|
1542
|
+
return val;
|
|
1543
|
+
},
|
|
1544
|
+
readDouble: function() {
|
|
1545
|
+
var val = ieee754.read(this.buf, this.pos, true, 52, 8);
|
|
1546
|
+
this.pos += 8;
|
|
1547
|
+
return val;
|
|
1548
|
+
},
|
|
1549
|
+
readVarint: function(isSigned) {
|
|
1550
|
+
var buf = this.buf, val, b;
|
|
1551
|
+
b = buf[this.pos++];
|
|
1552
|
+
val = b & 127;
|
|
1553
|
+
if (b < 128)
|
|
1554
|
+
return val;
|
|
1555
|
+
b = buf[this.pos++];
|
|
1556
|
+
val |= (b & 127) << 7;
|
|
1557
|
+
if (b < 128)
|
|
1558
|
+
return val;
|
|
1559
|
+
b = buf[this.pos++];
|
|
1560
|
+
val |= (b & 127) << 14;
|
|
1561
|
+
if (b < 128)
|
|
1562
|
+
return val;
|
|
1563
|
+
b = buf[this.pos++];
|
|
1564
|
+
val |= (b & 127) << 21;
|
|
1565
|
+
if (b < 128)
|
|
1566
|
+
return val;
|
|
1567
|
+
b = buf[this.pos];
|
|
1568
|
+
val |= (b & 15) << 28;
|
|
1569
|
+
return readVarintRemainder(val, isSigned, this);
|
|
1570
|
+
},
|
|
1571
|
+
readVarint64: function() {
|
|
1572
|
+
return this.readVarint(true);
|
|
1573
|
+
},
|
|
1574
|
+
readSVarint: function() {
|
|
1575
|
+
var num = this.readVarint();
|
|
1576
|
+
return num % 2 === 1 ? (num + 1) / -2 : num / 2;
|
|
1577
|
+
},
|
|
1578
|
+
readBoolean: function() {
|
|
1579
|
+
return Boolean(this.readVarint());
|
|
1580
|
+
},
|
|
1581
|
+
readString: function() {
|
|
1582
|
+
var end = this.readVarint() + this.pos;
|
|
1583
|
+
var pos = this.pos;
|
|
1584
|
+
this.pos = end;
|
|
1585
|
+
if (end - pos >= TEXT_DECODER_MIN_LENGTH && utf8TextDecoder) {
|
|
1586
|
+
return readUtf8TextDecoder(this.buf, pos, end);
|
|
1587
|
+
}
|
|
1588
|
+
return readUtf8(this.buf, pos, end);
|
|
1589
|
+
},
|
|
1590
|
+
readBytes: function() {
|
|
1591
|
+
var end = this.readVarint() + this.pos, buffer = this.buf.subarray(this.pos, end);
|
|
1592
|
+
this.pos = end;
|
|
1593
|
+
return buffer;
|
|
1594
|
+
},
|
|
1595
|
+
readPackedVarint: function(arr, isSigned) {
|
|
1596
|
+
if (this.type !== Pbf.Bytes)
|
|
1597
|
+
return arr.push(this.readVarint(isSigned));
|
|
1598
|
+
var end = readPackedEnd(this);
|
|
1599
|
+
arr = arr || [];
|
|
1600
|
+
while (this.pos < end)
|
|
1601
|
+
arr.push(this.readVarint(isSigned));
|
|
1602
|
+
return arr;
|
|
1603
|
+
},
|
|
1604
|
+
readPackedSVarint: function(arr) {
|
|
1605
|
+
if (this.type !== Pbf.Bytes)
|
|
1606
|
+
return arr.push(this.readSVarint());
|
|
1607
|
+
var end = readPackedEnd(this);
|
|
1608
|
+
arr = arr || [];
|
|
1609
|
+
while (this.pos < end)
|
|
1610
|
+
arr.push(this.readSVarint());
|
|
1611
|
+
return arr;
|
|
1612
|
+
},
|
|
1613
|
+
readPackedBoolean: function(arr) {
|
|
1614
|
+
if (this.type !== Pbf.Bytes)
|
|
1615
|
+
return arr.push(this.readBoolean());
|
|
1616
|
+
var end = readPackedEnd(this);
|
|
1617
|
+
arr = arr || [];
|
|
1618
|
+
while (this.pos < end)
|
|
1619
|
+
arr.push(this.readBoolean());
|
|
1620
|
+
return arr;
|
|
1621
|
+
},
|
|
1622
|
+
readPackedFloat: function(arr) {
|
|
1623
|
+
if (this.type !== Pbf.Bytes)
|
|
1624
|
+
return arr.push(this.readFloat());
|
|
1625
|
+
var end = readPackedEnd(this);
|
|
1626
|
+
arr = arr || [];
|
|
1627
|
+
while (this.pos < end)
|
|
1628
|
+
arr.push(this.readFloat());
|
|
1629
|
+
return arr;
|
|
1630
|
+
},
|
|
1631
|
+
readPackedDouble: function(arr) {
|
|
1632
|
+
if (this.type !== Pbf.Bytes)
|
|
1633
|
+
return arr.push(this.readDouble());
|
|
1634
|
+
var end = readPackedEnd(this);
|
|
1635
|
+
arr = arr || [];
|
|
1636
|
+
while (this.pos < end)
|
|
1637
|
+
arr.push(this.readDouble());
|
|
1638
|
+
return arr;
|
|
1639
|
+
},
|
|
1640
|
+
readPackedFixed32: function(arr) {
|
|
1641
|
+
if (this.type !== Pbf.Bytes)
|
|
1642
|
+
return arr.push(this.readFixed32());
|
|
1643
|
+
var end = readPackedEnd(this);
|
|
1644
|
+
arr = arr || [];
|
|
1645
|
+
while (this.pos < end)
|
|
1646
|
+
arr.push(this.readFixed32());
|
|
1647
|
+
return arr;
|
|
1648
|
+
},
|
|
1649
|
+
readPackedSFixed32: function(arr) {
|
|
1650
|
+
if (this.type !== Pbf.Bytes)
|
|
1651
|
+
return arr.push(this.readSFixed32());
|
|
1652
|
+
var end = readPackedEnd(this);
|
|
1653
|
+
arr = arr || [];
|
|
1654
|
+
while (this.pos < end)
|
|
1655
|
+
arr.push(this.readSFixed32());
|
|
1656
|
+
return arr;
|
|
1657
|
+
},
|
|
1658
|
+
readPackedFixed64: function(arr) {
|
|
1659
|
+
if (this.type !== Pbf.Bytes)
|
|
1660
|
+
return arr.push(this.readFixed64());
|
|
1661
|
+
var end = readPackedEnd(this);
|
|
1662
|
+
arr = arr || [];
|
|
1663
|
+
while (this.pos < end)
|
|
1664
|
+
arr.push(this.readFixed64());
|
|
1665
|
+
return arr;
|
|
1666
|
+
},
|
|
1667
|
+
readPackedSFixed64: function(arr) {
|
|
1668
|
+
if (this.type !== Pbf.Bytes)
|
|
1669
|
+
return arr.push(this.readSFixed64());
|
|
1670
|
+
var end = readPackedEnd(this);
|
|
1671
|
+
arr = arr || [];
|
|
1672
|
+
while (this.pos < end)
|
|
1673
|
+
arr.push(this.readSFixed64());
|
|
1674
|
+
return arr;
|
|
1675
|
+
},
|
|
1676
|
+
skip: function(val) {
|
|
1677
|
+
var type = val & 7;
|
|
1678
|
+
if (type === Pbf.Varint)
|
|
1679
|
+
while (this.buf[this.pos++] > 127) {
|
|
1680
|
+
}
|
|
1681
|
+
else if (type === Pbf.Bytes)
|
|
1682
|
+
this.pos = this.readVarint() + this.pos;
|
|
1683
|
+
else if (type === Pbf.Fixed32)
|
|
1684
|
+
this.pos += 4;
|
|
1685
|
+
else if (type === Pbf.Fixed64)
|
|
1686
|
+
this.pos += 8;
|
|
1687
|
+
else
|
|
1688
|
+
throw new Error("Unimplemented type: " + type);
|
|
1689
|
+
},
|
|
1690
|
+
writeTag: function(tag, type) {
|
|
1691
|
+
this.writeVarint(tag << 3 | type);
|
|
1692
|
+
},
|
|
1693
|
+
realloc: function(min) {
|
|
1694
|
+
var length2 = this.length || 16;
|
|
1695
|
+
while (length2 < this.pos + min)
|
|
1696
|
+
length2 *= 2;
|
|
1697
|
+
if (length2 !== this.length) {
|
|
1698
|
+
var buf = new Uint8Array(length2);
|
|
1699
|
+
buf.set(this.buf);
|
|
1700
|
+
this.buf = buf;
|
|
1701
|
+
this.length = length2;
|
|
1702
|
+
}
|
|
1703
|
+
},
|
|
1704
|
+
finish: function() {
|
|
1705
|
+
this.length = this.pos;
|
|
1706
|
+
this.pos = 0;
|
|
1707
|
+
return this.buf.subarray(0, this.length);
|
|
1708
|
+
},
|
|
1709
|
+
writeFixed32: function(val) {
|
|
1710
|
+
this.realloc(4);
|
|
1711
|
+
writeInt32(this.buf, val, this.pos);
|
|
1712
|
+
this.pos += 4;
|
|
1713
|
+
},
|
|
1714
|
+
writeSFixed32: function(val) {
|
|
1715
|
+
this.realloc(4);
|
|
1716
|
+
writeInt32(this.buf, val, this.pos);
|
|
1717
|
+
this.pos += 4;
|
|
1718
|
+
},
|
|
1719
|
+
writeFixed64: function(val) {
|
|
1720
|
+
this.realloc(8);
|
|
1721
|
+
writeInt32(this.buf, val & -1, this.pos);
|
|
1722
|
+
writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
|
|
1723
|
+
this.pos += 8;
|
|
1724
|
+
},
|
|
1725
|
+
writeSFixed64: function(val) {
|
|
1726
|
+
this.realloc(8);
|
|
1727
|
+
writeInt32(this.buf, val & -1, this.pos);
|
|
1728
|
+
writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
|
|
1729
|
+
this.pos += 8;
|
|
1730
|
+
},
|
|
1731
|
+
writeVarint: function(val) {
|
|
1732
|
+
val = +val || 0;
|
|
1733
|
+
if (val > 268435455 || val < 0) {
|
|
1734
|
+
writeBigVarint(val, this);
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1737
|
+
this.realloc(4);
|
|
1738
|
+
this.buf[this.pos++] = val & 127 | (val > 127 ? 128 : 0);
|
|
1739
|
+
if (val <= 127)
|
|
1740
|
+
return;
|
|
1741
|
+
this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0);
|
|
1742
|
+
if (val <= 127)
|
|
1743
|
+
return;
|
|
1744
|
+
this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0);
|
|
1745
|
+
if (val <= 127)
|
|
1746
|
+
return;
|
|
1747
|
+
this.buf[this.pos++] = val >>> 7 & 127;
|
|
1748
|
+
},
|
|
1749
|
+
writeSVarint: function(val) {
|
|
1750
|
+
this.writeVarint(val < 0 ? -val * 2 - 1 : val * 2);
|
|
1751
|
+
},
|
|
1752
|
+
writeBoolean: function(val) {
|
|
1753
|
+
this.writeVarint(Boolean(val));
|
|
1754
|
+
},
|
|
1755
|
+
writeString: function(str) {
|
|
1756
|
+
str = String(str);
|
|
1757
|
+
this.realloc(str.length * 4);
|
|
1758
|
+
this.pos++;
|
|
1759
|
+
var startPos = this.pos;
|
|
1760
|
+
this.pos = writeUtf8(this.buf, str, this.pos);
|
|
1761
|
+
var len = this.pos - startPos;
|
|
1762
|
+
if (len >= 128)
|
|
1763
|
+
makeRoomForExtraLength(startPos, len, this);
|
|
1764
|
+
this.pos = startPos - 1;
|
|
1765
|
+
this.writeVarint(len);
|
|
1766
|
+
this.pos += len;
|
|
1767
|
+
},
|
|
1768
|
+
writeFloat: function(val) {
|
|
1769
|
+
this.realloc(4);
|
|
1770
|
+
ieee754.write(this.buf, val, this.pos, true, 23, 4);
|
|
1771
|
+
this.pos += 4;
|
|
1772
|
+
},
|
|
1773
|
+
writeDouble: function(val) {
|
|
1774
|
+
this.realloc(8);
|
|
1775
|
+
ieee754.write(this.buf, val, this.pos, true, 52, 8);
|
|
1776
|
+
this.pos += 8;
|
|
1777
|
+
},
|
|
1778
|
+
writeBytes: function(buffer) {
|
|
1779
|
+
var len = buffer.length;
|
|
1780
|
+
this.writeVarint(len);
|
|
1781
|
+
this.realloc(len);
|
|
1782
|
+
for (var i2 = 0; i2 < len; i2++)
|
|
1783
|
+
this.buf[this.pos++] = buffer[i2];
|
|
1784
|
+
},
|
|
1785
|
+
writeRawMessage: function(fn, obj) {
|
|
1786
|
+
this.pos++;
|
|
1787
|
+
var startPos = this.pos;
|
|
1788
|
+
fn(obj, this);
|
|
1789
|
+
var len = this.pos - startPos;
|
|
1790
|
+
if (len >= 128)
|
|
1791
|
+
makeRoomForExtraLength(startPos, len, this);
|
|
1792
|
+
this.pos = startPos - 1;
|
|
1793
|
+
this.writeVarint(len);
|
|
1794
|
+
this.pos += len;
|
|
1795
|
+
},
|
|
1796
|
+
writeMessage: function(tag, fn, obj) {
|
|
1797
|
+
this.writeTag(tag, Pbf.Bytes);
|
|
1798
|
+
this.writeRawMessage(fn, obj);
|
|
1799
|
+
},
|
|
1800
|
+
writePackedVarint: function(tag, arr) {
|
|
1801
|
+
if (arr.length)
|
|
1802
|
+
this.writeMessage(tag, writePackedVarint, arr);
|
|
1803
|
+
},
|
|
1804
|
+
writePackedSVarint: function(tag, arr) {
|
|
1805
|
+
if (arr.length)
|
|
1806
|
+
this.writeMessage(tag, writePackedSVarint, arr);
|
|
1807
|
+
},
|
|
1808
|
+
writePackedBoolean: function(tag, arr) {
|
|
1809
|
+
if (arr.length)
|
|
1810
|
+
this.writeMessage(tag, writePackedBoolean, arr);
|
|
1811
|
+
},
|
|
1812
|
+
writePackedFloat: function(tag, arr) {
|
|
1813
|
+
if (arr.length)
|
|
1814
|
+
this.writeMessage(tag, writePackedFloat, arr);
|
|
1815
|
+
},
|
|
1816
|
+
writePackedDouble: function(tag, arr) {
|
|
1817
|
+
if (arr.length)
|
|
1818
|
+
this.writeMessage(tag, writePackedDouble, arr);
|
|
1819
|
+
},
|
|
1820
|
+
writePackedFixed32: function(tag, arr) {
|
|
1821
|
+
if (arr.length)
|
|
1822
|
+
this.writeMessage(tag, writePackedFixed32, arr);
|
|
1823
|
+
},
|
|
1824
|
+
writePackedSFixed32: function(tag, arr) {
|
|
1825
|
+
if (arr.length)
|
|
1826
|
+
this.writeMessage(tag, writePackedSFixed32, arr);
|
|
1827
|
+
},
|
|
1828
|
+
writePackedFixed64: function(tag, arr) {
|
|
1829
|
+
if (arr.length)
|
|
1830
|
+
this.writeMessage(tag, writePackedFixed64, arr);
|
|
1831
|
+
},
|
|
1832
|
+
writePackedSFixed64: function(tag, arr) {
|
|
1833
|
+
if (arr.length)
|
|
1834
|
+
this.writeMessage(tag, writePackedSFixed64, arr);
|
|
1835
|
+
},
|
|
1836
|
+
writeBytesField: function(tag, buffer) {
|
|
1837
|
+
this.writeTag(tag, Pbf.Bytes);
|
|
1838
|
+
this.writeBytes(buffer);
|
|
1839
|
+
},
|
|
1840
|
+
writeFixed32Field: function(tag, val) {
|
|
1841
|
+
this.writeTag(tag, Pbf.Fixed32);
|
|
1842
|
+
this.writeFixed32(val);
|
|
1843
|
+
},
|
|
1844
|
+
writeSFixed32Field: function(tag, val) {
|
|
1845
|
+
this.writeTag(tag, Pbf.Fixed32);
|
|
1846
|
+
this.writeSFixed32(val);
|
|
1847
|
+
},
|
|
1848
|
+
writeFixed64Field: function(tag, val) {
|
|
1849
|
+
this.writeTag(tag, Pbf.Fixed64);
|
|
1850
|
+
this.writeFixed64(val);
|
|
1851
|
+
},
|
|
1852
|
+
writeSFixed64Field: function(tag, val) {
|
|
1853
|
+
this.writeTag(tag, Pbf.Fixed64);
|
|
1854
|
+
this.writeSFixed64(val);
|
|
1855
|
+
},
|
|
1856
|
+
writeVarintField: function(tag, val) {
|
|
1857
|
+
this.writeTag(tag, Pbf.Varint);
|
|
1858
|
+
this.writeVarint(val);
|
|
1859
|
+
},
|
|
1860
|
+
writeSVarintField: function(tag, val) {
|
|
1861
|
+
this.writeTag(tag, Pbf.Varint);
|
|
1862
|
+
this.writeSVarint(val);
|
|
1863
|
+
},
|
|
1864
|
+
writeStringField: function(tag, str) {
|
|
1865
|
+
this.writeTag(tag, Pbf.Bytes);
|
|
1866
|
+
this.writeString(str);
|
|
1867
|
+
},
|
|
1868
|
+
writeFloatField: function(tag, val) {
|
|
1869
|
+
this.writeTag(tag, Pbf.Fixed32);
|
|
1870
|
+
this.writeFloat(val);
|
|
1871
|
+
},
|
|
1872
|
+
writeDoubleField: function(tag, val) {
|
|
1873
|
+
this.writeTag(tag, Pbf.Fixed64);
|
|
1874
|
+
this.writeDouble(val);
|
|
1875
|
+
},
|
|
1876
|
+
writeBooleanField: function(tag, val) {
|
|
1877
|
+
this.writeVarintField(tag, Boolean(val));
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
function readVarintRemainder(l, s, p) {
|
|
1881
|
+
var buf = p.buf, h, b;
|
|
1882
|
+
b = buf[p.pos++];
|
|
1883
|
+
h = (b & 112) >> 4;
|
|
1884
|
+
if (b < 128)
|
|
1885
|
+
return toNum(l, h, s);
|
|
1886
|
+
b = buf[p.pos++];
|
|
1887
|
+
h |= (b & 127) << 3;
|
|
1888
|
+
if (b < 128)
|
|
1889
|
+
return toNum(l, h, s);
|
|
1890
|
+
b = buf[p.pos++];
|
|
1891
|
+
h |= (b & 127) << 10;
|
|
1892
|
+
if (b < 128)
|
|
1893
|
+
return toNum(l, h, s);
|
|
1894
|
+
b = buf[p.pos++];
|
|
1895
|
+
h |= (b & 127) << 17;
|
|
1896
|
+
if (b < 128)
|
|
1897
|
+
return toNum(l, h, s);
|
|
1898
|
+
b = buf[p.pos++];
|
|
1899
|
+
h |= (b & 127) << 24;
|
|
1900
|
+
if (b < 128)
|
|
1901
|
+
return toNum(l, h, s);
|
|
1902
|
+
b = buf[p.pos++];
|
|
1903
|
+
h |= (b & 1) << 31;
|
|
1904
|
+
if (b < 128)
|
|
1905
|
+
return toNum(l, h, s);
|
|
1906
|
+
throw new Error("Expected varint not more than 10 bytes");
|
|
1907
|
+
}
|
|
1908
|
+
function readPackedEnd(pbf) {
|
|
1909
|
+
return pbf.type === Pbf.Bytes ? pbf.readVarint() + pbf.pos : pbf.pos + 1;
|
|
1910
|
+
}
|
|
1911
|
+
function toNum(low, high, isSigned) {
|
|
1912
|
+
if (isSigned) {
|
|
1913
|
+
return high * 4294967296 + (low >>> 0);
|
|
1914
|
+
}
|
|
1915
|
+
return (high >>> 0) * 4294967296 + (low >>> 0);
|
|
1916
|
+
}
|
|
1917
|
+
function writeBigVarint(val, pbf) {
|
|
1918
|
+
var low, high;
|
|
1919
|
+
if (val >= 0) {
|
|
1920
|
+
low = val % 4294967296 | 0;
|
|
1921
|
+
high = val / 4294967296 | 0;
|
|
1922
|
+
} else {
|
|
1923
|
+
low = ~(-val % 4294967296);
|
|
1924
|
+
high = ~(-val / 4294967296);
|
|
1925
|
+
if (low ^ 4294967295) {
|
|
1926
|
+
low = low + 1 | 0;
|
|
1927
|
+
} else {
|
|
1928
|
+
low = 0;
|
|
1929
|
+
high = high + 1 | 0;
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
if (val >= 18446744073709552e3 || val < -18446744073709552e3) {
|
|
1933
|
+
throw new Error("Given varint doesn't fit into 10 bytes");
|
|
1934
|
+
}
|
|
1935
|
+
pbf.realloc(10);
|
|
1936
|
+
writeBigVarintLow(low, high, pbf);
|
|
1937
|
+
writeBigVarintHigh(high, pbf);
|
|
1938
|
+
}
|
|
1939
|
+
function writeBigVarintLow(low, high, pbf) {
|
|
1940
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1941
|
+
low >>>= 7;
|
|
1942
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1943
|
+
low >>>= 7;
|
|
1944
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1945
|
+
low >>>= 7;
|
|
1946
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1947
|
+
low >>>= 7;
|
|
1948
|
+
pbf.buf[pbf.pos] = low & 127;
|
|
1949
|
+
}
|
|
1950
|
+
function writeBigVarintHigh(high, pbf) {
|
|
1951
|
+
var lsb = (high & 7) << 4;
|
|
1952
|
+
pbf.buf[pbf.pos++] |= lsb | ((high >>>= 3) ? 128 : 0);
|
|
1953
|
+
if (!high)
|
|
1954
|
+
return;
|
|
1955
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
1956
|
+
if (!high)
|
|
1957
|
+
return;
|
|
1958
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
1959
|
+
if (!high)
|
|
1960
|
+
return;
|
|
1961
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
1962
|
+
if (!high)
|
|
1963
|
+
return;
|
|
1964
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
1965
|
+
if (!high)
|
|
1966
|
+
return;
|
|
1967
|
+
pbf.buf[pbf.pos++] = high & 127;
|
|
1968
|
+
}
|
|
1969
|
+
function makeRoomForExtraLength(startPos, len, pbf) {
|
|
1970
|
+
var extraLen = len <= 16383 ? 1 : len <= 2097151 ? 2 : len <= 268435455 ? 3 : Math.floor(Math.log(len) / (Math.LN2 * 7));
|
|
1971
|
+
pbf.realloc(extraLen);
|
|
1972
|
+
for (var i2 = pbf.pos - 1; i2 >= startPos; i2--)
|
|
1973
|
+
pbf.buf[i2 + extraLen] = pbf.buf[i2];
|
|
1974
|
+
}
|
|
1975
|
+
function writePackedVarint(arr, pbf) {
|
|
1976
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1977
|
+
pbf.writeVarint(arr[i2]);
|
|
1978
|
+
}
|
|
1979
|
+
function writePackedSVarint(arr, pbf) {
|
|
1980
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1981
|
+
pbf.writeSVarint(arr[i2]);
|
|
1982
|
+
}
|
|
1983
|
+
function writePackedFloat(arr, pbf) {
|
|
1984
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1985
|
+
pbf.writeFloat(arr[i2]);
|
|
1986
|
+
}
|
|
1987
|
+
function writePackedDouble(arr, pbf) {
|
|
1988
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1989
|
+
pbf.writeDouble(arr[i2]);
|
|
1990
|
+
}
|
|
1991
|
+
function writePackedBoolean(arr, pbf) {
|
|
1992
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1993
|
+
pbf.writeBoolean(arr[i2]);
|
|
1994
|
+
}
|
|
1995
|
+
function writePackedFixed32(arr, pbf) {
|
|
1996
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1997
|
+
pbf.writeFixed32(arr[i2]);
|
|
1998
|
+
}
|
|
1999
|
+
function writePackedSFixed32(arr, pbf) {
|
|
2000
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
2001
|
+
pbf.writeSFixed32(arr[i2]);
|
|
2002
|
+
}
|
|
2003
|
+
function writePackedFixed64(arr, pbf) {
|
|
2004
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
2005
|
+
pbf.writeFixed64(arr[i2]);
|
|
2006
|
+
}
|
|
2007
|
+
function writePackedSFixed64(arr, pbf) {
|
|
2008
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
2009
|
+
pbf.writeSFixed64(arr[i2]);
|
|
2010
|
+
}
|
|
2011
|
+
function readUInt32(buf, pos) {
|
|
2012
|
+
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216;
|
|
2013
|
+
}
|
|
2014
|
+
function writeInt32(buf, val, pos) {
|
|
2015
|
+
buf[pos] = val;
|
|
2016
|
+
buf[pos + 1] = val >>> 8;
|
|
2017
|
+
buf[pos + 2] = val >>> 16;
|
|
2018
|
+
buf[pos + 3] = val >>> 24;
|
|
2019
|
+
}
|
|
2020
|
+
function readInt32(buf, pos) {
|
|
2021
|
+
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + (buf[pos + 3] << 24);
|
|
2022
|
+
}
|
|
2023
|
+
function readUtf8(buf, pos, end) {
|
|
2024
|
+
var str = "";
|
|
2025
|
+
var i2 = pos;
|
|
2026
|
+
while (i2 < end) {
|
|
2027
|
+
var b0 = buf[i2];
|
|
2028
|
+
var c = null;
|
|
2029
|
+
var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
|
|
2030
|
+
if (i2 + bytesPerSequence > end)
|
|
2031
|
+
break;
|
|
2032
|
+
var b1, b2, b3;
|
|
2033
|
+
if (bytesPerSequence === 1) {
|
|
2034
|
+
if (b0 < 128) {
|
|
2035
|
+
c = b0;
|
|
2036
|
+
}
|
|
2037
|
+
} else if (bytesPerSequence === 2) {
|
|
2038
|
+
b1 = buf[i2 + 1];
|
|
2039
|
+
if ((b1 & 192) === 128) {
|
|
2040
|
+
c = (b0 & 31) << 6 | b1 & 63;
|
|
2041
|
+
if (c <= 127) {
|
|
2042
|
+
c = null;
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
} else if (bytesPerSequence === 3) {
|
|
2046
|
+
b1 = buf[i2 + 1];
|
|
2047
|
+
b2 = buf[i2 + 2];
|
|
2048
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128) {
|
|
2049
|
+
c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
|
|
2050
|
+
if (c <= 2047 || c >= 55296 && c <= 57343) {
|
|
2051
|
+
c = null;
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
} else if (bytesPerSequence === 4) {
|
|
2055
|
+
b1 = buf[i2 + 1];
|
|
2056
|
+
b2 = buf[i2 + 2];
|
|
2057
|
+
b3 = buf[i2 + 3];
|
|
2058
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
|
|
2059
|
+
c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
|
|
2060
|
+
if (c <= 65535 || c >= 1114112) {
|
|
2061
|
+
c = null;
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
if (c === null) {
|
|
2066
|
+
c = 65533;
|
|
2067
|
+
bytesPerSequence = 1;
|
|
2068
|
+
} else if (c > 65535) {
|
|
2069
|
+
c -= 65536;
|
|
2070
|
+
str += String.fromCharCode(c >>> 10 & 1023 | 55296);
|
|
2071
|
+
c = 56320 | c & 1023;
|
|
2072
|
+
}
|
|
2073
|
+
str += String.fromCharCode(c);
|
|
2074
|
+
i2 += bytesPerSequence;
|
|
2075
|
+
}
|
|
2076
|
+
return str;
|
|
2077
|
+
}
|
|
2078
|
+
function readUtf8TextDecoder(buf, pos, end) {
|
|
2079
|
+
return utf8TextDecoder.decode(buf.subarray(pos, end));
|
|
2080
|
+
}
|
|
2081
|
+
function writeUtf8(buf, str, pos) {
|
|
2082
|
+
for (var i2 = 0, c, lead; i2 < str.length; i2++) {
|
|
2083
|
+
c = str.charCodeAt(i2);
|
|
2084
|
+
if (c > 55295 && c < 57344) {
|
|
2085
|
+
if (lead) {
|
|
2086
|
+
if (c < 56320) {
|
|
2087
|
+
buf[pos++] = 239;
|
|
2088
|
+
buf[pos++] = 191;
|
|
2089
|
+
buf[pos++] = 189;
|
|
2090
|
+
lead = c;
|
|
2091
|
+
continue;
|
|
2092
|
+
} else {
|
|
2093
|
+
c = lead - 55296 << 10 | c - 56320 | 65536;
|
|
2094
|
+
lead = null;
|
|
2095
|
+
}
|
|
2096
|
+
} else {
|
|
2097
|
+
if (c > 56319 || i2 + 1 === str.length) {
|
|
2098
|
+
buf[pos++] = 239;
|
|
2099
|
+
buf[pos++] = 191;
|
|
2100
|
+
buf[pos++] = 189;
|
|
2101
|
+
} else {
|
|
2102
|
+
lead = c;
|
|
2103
|
+
}
|
|
2104
|
+
continue;
|
|
2105
|
+
}
|
|
2106
|
+
} else if (lead) {
|
|
2107
|
+
buf[pos++] = 239;
|
|
2108
|
+
buf[pos++] = 191;
|
|
2109
|
+
buf[pos++] = 189;
|
|
2110
|
+
lead = null;
|
|
2111
|
+
}
|
|
2112
|
+
if (c < 128) {
|
|
2113
|
+
buf[pos++] = c;
|
|
2114
|
+
} else {
|
|
2115
|
+
if (c < 2048) {
|
|
2116
|
+
buf[pos++] = c >> 6 | 192;
|
|
2117
|
+
} else {
|
|
2118
|
+
if (c < 65536) {
|
|
2119
|
+
buf[pos++] = c >> 12 | 224;
|
|
2120
|
+
} else {
|
|
2121
|
+
buf[pos++] = c >> 18 | 240;
|
|
2122
|
+
buf[pos++] = c >> 12 & 63 | 128;
|
|
2123
|
+
}
|
|
2124
|
+
buf[pos++] = c >> 6 & 63 | 128;
|
|
2125
|
+
}
|
|
2126
|
+
buf[pos++] = c & 63 | 128;
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
return pos;
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
});
|
|
2133
|
+
|
|
2134
|
+
// src/lib/parse-mvt.ts
|
|
2135
|
+
function parseMVT(arrayBuffer, options) {
|
|
2136
|
+
options = normalizeOptions(options);
|
|
2137
|
+
const features = [];
|
|
2138
|
+
if (options) {
|
|
2139
|
+
const binary = options.gis.format === "binary";
|
|
2140
|
+
const geometryInfo = {
|
|
2141
|
+
coordLength: 2,
|
|
2142
|
+
pointPositionsCount: 0,
|
|
2143
|
+
pointFeaturesCount: 0,
|
|
2144
|
+
linePositionsCount: 0,
|
|
2145
|
+
linePathsCount: 0,
|
|
2146
|
+
lineFeaturesCount: 0,
|
|
2147
|
+
polygonPositionsCount: 0,
|
|
2148
|
+
polygonObjectsCount: 0,
|
|
2149
|
+
polygonRingsCount: 0,
|
|
2150
|
+
polygonFeaturesCount: 0
|
|
2151
|
+
};
|
|
2152
|
+
if (arrayBuffer.byteLength > 0) {
|
|
2153
|
+
const tile = binary ? new VectorTile2(new import_pbf.default(arrayBuffer)) : new VectorTile(new import_pbf.default(arrayBuffer));
|
|
2154
|
+
const loaderOptions = options.mvt;
|
|
2155
|
+
const selectedLayers = Array.isArray(loaderOptions.layers) ? loaderOptions.layers : Object.keys(tile.layers);
|
|
2156
|
+
selectedLayers.forEach((layerName) => {
|
|
2157
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
2158
|
+
const featureOptions = { ...loaderOptions, layerName };
|
|
2159
|
+
if (!vectorTileLayer) {
|
|
2160
|
+
return;
|
|
2161
|
+
}
|
|
2162
|
+
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2163
|
+
const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
|
|
2164
|
+
const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
|
|
2165
|
+
features.push(decodedFeature);
|
|
2166
|
+
}
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
2169
|
+
if (binary) {
|
|
2170
|
+
const data = flatGeojsonToBinary(features, geometryInfo);
|
|
2171
|
+
data.byteLength = arrayBuffer.byteLength;
|
|
2172
|
+
return data;
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
return features;
|
|
2176
|
+
}
|
|
2177
|
+
function normalizeOptions(options) {
|
|
2178
|
+
if (options) {
|
|
2179
|
+
options = {
|
|
2180
|
+
...options,
|
|
2181
|
+
mvt: options.mvt || {},
|
|
2182
|
+
gis: options.gis || {}
|
|
2183
|
+
};
|
|
2184
|
+
const wgs84Coordinates = options.coordinates === "wgs84";
|
|
2185
|
+
const { tileIndex } = options;
|
|
2186
|
+
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2187
|
+
if (wgs84Coordinates && !hasTileIndex) {
|
|
2188
|
+
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.");
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
return options;
|
|
2192
|
+
}
|
|
2193
|
+
function getDecodedFeature(feature, options) {
|
|
2194
|
+
const decodedFeature = feature.toGeoJSON(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates);
|
|
2195
|
+
if (options.layerProperty) {
|
|
2196
|
+
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
2197
|
+
}
|
|
2198
|
+
return decodedFeature;
|
|
2199
|
+
}
|
|
2200
|
+
function getDecodedFeatureBinary(feature, options) {
|
|
2201
|
+
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
2202
|
+
if (options.layerProperty && decodedFeature.properties) {
|
|
2203
|
+
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
2204
|
+
}
|
|
2205
|
+
return decodedFeature;
|
|
2206
|
+
}
|
|
2207
|
+
function transformToLocalCoordinates(line, feature) {
|
|
2208
|
+
const { extent } = feature;
|
|
2209
|
+
for (let i2 = 0; i2 < line.length; i2++) {
|
|
2210
|
+
const p = line[i2];
|
|
2211
|
+
p[0] /= extent;
|
|
2212
|
+
p[1] /= extent;
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
function transformToLocalCoordinatesBinary(data, feature) {
|
|
2216
|
+
const { extent } = feature;
|
|
2217
|
+
for (let i2 = 0, il = data.length; i2 < il; ++i2) {
|
|
2218
|
+
data[i2] /= extent;
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
var import_pbf;
|
|
2222
|
+
var init_parse_mvt = __esm({
|
|
2223
|
+
"src/lib/parse-mvt.ts"() {
|
|
2224
|
+
init_vector_tile();
|
|
2225
|
+
init_vector_tile2();
|
|
2226
|
+
init_src();
|
|
2227
|
+
import_pbf = __toModule(require_pbf());
|
|
2228
|
+
}
|
|
2229
|
+
});
|
|
2230
|
+
|
|
2231
|
+
// src/mvt-loader.ts
|
|
2232
|
+
var VERSION, MVTWorkerLoader, MVTLoader;
|
|
2233
|
+
var init_mvt_loader = __esm({
|
|
2234
|
+
"src/mvt-loader.ts"() {
|
|
2235
|
+
init_parse_mvt();
|
|
2236
|
+
VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2237
|
+
MVTWorkerLoader = {
|
|
2238
|
+
name: "Mapbox Vector Tile",
|
|
2239
|
+
id: "mvt",
|
|
2240
|
+
module: "mvt",
|
|
2241
|
+
version: VERSION,
|
|
2242
|
+
extensions: ["mvt", "pbf"],
|
|
2243
|
+
mimeTypes: [
|
|
2244
|
+
"application/vnd.mapbox-vector-tile",
|
|
2245
|
+
"application/x-protobuf"
|
|
2246
|
+
],
|
|
2247
|
+
worker: true,
|
|
2248
|
+
category: "geometry",
|
|
2249
|
+
options: {
|
|
2250
|
+
mvt: {
|
|
2251
|
+
coordinates: "local",
|
|
2252
|
+
layerProperty: "layerName",
|
|
2253
|
+
layers: null,
|
|
2254
|
+
tileIndex: null
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
};
|
|
2258
|
+
MVTLoader = {
|
|
2259
|
+
...MVTWorkerLoader,
|
|
2260
|
+
parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),
|
|
2261
|
+
parseSync: parseMVT,
|
|
2262
|
+
binary: true
|
|
2263
|
+
};
|
|
2264
|
+
}
|
|
2265
|
+
});
|
|
2266
|
+
|
|
2267
|
+
// src/index.ts
|
|
2268
|
+
var src_exports = {};
|
|
2269
|
+
__export(src_exports, {
|
|
2270
|
+
MVTLoader: () => MVTLoader,
|
|
2271
|
+
MVTWorkerLoader: () => MVTWorkerLoader
|
|
2272
|
+
});
|
|
2273
|
+
var init_src2 = __esm({
|
|
2274
|
+
"src/index.ts"() {
|
|
2275
|
+
init_mvt_loader();
|
|
2276
|
+
}
|
|
2277
|
+
});
|
|
2278
|
+
|
|
2279
|
+
// src/bundle.ts
|
|
2280
|
+
var require_bundle = __commonJS({
|
|
2281
|
+
"src/bundle.ts"(exports, module) {
|
|
2282
|
+
var moduleExports = (init_src2(), src_exports);
|
|
2283
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
2284
|
+
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
2285
|
+
}
|
|
2286
|
+
});
|
|
2287
|
+
require_bundle();
|
|
2288
|
+
})();
|
|
2289
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|