@loaders.gl/mvt 3.1.0-alpha.3 → 3.1.0-beta.2
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/bundle.js +2276 -4
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/helpers/binary-util-functions.js +95 -0
- package/dist/es5/helpers/binary-util-functions.js.map +1 -0
- package/dist/es5/helpers/mapbox-util-functions.js +62 -0
- package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/es5/index.js +20 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js +338 -0
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +162 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +69 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +35 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +207 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +69 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +35 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/es5/lib/parse-mvt.js +129 -0
- package/dist/es5/lib/parse-mvt.js.map +1 -0
- package/dist/es5/lib/types.js +2 -0
- package/dist/{lib → es5/lib}/types.js.map +0 -0
- package/dist/es5/mvt-loader.js +38 -0
- package/dist/es5/mvt-loader.js.map +1 -0
- package/dist/es5/workers/mvt-worker.js +8 -0
- package/dist/es5/workers/mvt-worker.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/helpers/binary-util-functions.js +81 -0
- package/dist/esm/helpers/binary-util-functions.js.map +1 -0
- package/dist/esm/helpers/mapbox-util-functions.js +49 -0
- package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js +327 -0
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +156 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +64 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile.js +23 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +202 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +64 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +23 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/esm/lib/parse-mvt.js +116 -0
- package/dist/esm/lib/parse-mvt.js.map +1 -0
- package/dist/esm/lib/types.js +2 -0
- package/dist/esm/lib/types.js.map +1 -0
- package/dist/esm/mvt-loader.js +26 -0
- package/dist/esm/mvt-loader.js.map +1 -0
- package/dist/esm/workers/mvt-worker.js +4 -0
- package/dist/esm/workers/mvt-worker.js.map +1 -0
- package/dist/helpers/binary-util-functions.d.ts +39 -0
- package/dist/helpers/binary-util-functions.d.ts.map +1 -0
- package/dist/helpers/binary-util-functions.js +109 -74
- package/dist/helpers/mapbox-util-functions.d.ts +29 -0
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
- package/dist/helpers/mapbox-util-functions.js +78 -45
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -2
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts +185 -0
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/features-to-binary.js +323 -297
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +36 -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 +145 -142
- 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 +85 -58
- 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/binary-vector-tile/vector-tile.js +25 -19
- 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-feature.js +161 -193
- 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-layer.js +83 -58
- 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/mapbox-vector-tile/vector-tile.js +25 -19
- package/dist/lib/parse-mvt.d.ts +85 -0
- package/dist/lib/parse-mvt.d.ts.map +1 -0
- package/dist/lib/parse-mvt.js +126 -100
- package/dist/lib/types.d.ts +92 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -2
- package/dist/mvt-loader.d.ts +10 -0
- package/dist/mvt-loader.d.ts.map +1 -0
- package/dist/mvt-loader.js +42 -23
- package/dist/mvt-worker.js +2286 -3
- package/dist/workers/mvt-worker.d.ts +2 -0
- package/dist/workers/mvt-worker.d.ts.map +1 -0
- package/dist/workers/mvt-worker.js +5 -4
- package/package.json +9 -9
- package/src/lib/parse-mvt.ts +1 -1
- package/dist/bundle.js.map +0 -1
- package/dist/dist.min.js +0 -4
- package/dist/dist.min.js.map +0 -1
- package/dist/helpers/binary-util-functions.js.map +0 -1
- package/dist/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/parse-mvt.js.map +0 -1
- package/dist/mvt-loader.js.map +0 -1
- package/dist/mvt-worker.js.map +0 -1
- package/dist/workers/mvt-worker.js.map +0 -1
package/dist/bundle.js
CHANGED
|
@@ -1,5 +1,2277 @@
|
|
|
1
|
-
|
|
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
|
+
};
|
|
2
31
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.lines.length;
|
|
881
|
+
if (len <= 1) {
|
|
882
|
+
return {
|
|
883
|
+
data: geom.data,
|
|
884
|
+
areas: [[getPolygonSignedArea(geom.data)]],
|
|
885
|
+
lines: [geom.lines]
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
const areas = [];
|
|
889
|
+
const polygons = [];
|
|
890
|
+
let ringAreas = [];
|
|
891
|
+
let polygon = [];
|
|
892
|
+
let ccw;
|
|
893
|
+
let offset = 0;
|
|
894
|
+
for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
|
|
895
|
+
startIndex = geom.lines[i2] - offset;
|
|
896
|
+
endIndex = geom.lines[i2 + 1] - offset || geom.data.length;
|
|
897
|
+
const shape = geom.data.slice(startIndex, endIndex);
|
|
898
|
+
const area2 = getPolygonSignedArea(shape);
|
|
899
|
+
if (area2 === 0) {
|
|
900
|
+
const before = geom.data.slice(0, startIndex);
|
|
901
|
+
const after = geom.data.slice(endIndex);
|
|
902
|
+
geom.data = before.concat(after);
|
|
903
|
+
offset += endIndex - startIndex;
|
|
904
|
+
continue;
|
|
905
|
+
}
|
|
906
|
+
if (ccw === void 0)
|
|
907
|
+
ccw = area2 < 0;
|
|
908
|
+
if (ccw === area2 < 0) {
|
|
909
|
+
if (polygon.length) {
|
|
910
|
+
areas.push(ringAreas);
|
|
911
|
+
polygons.push(polygon);
|
|
912
|
+
}
|
|
913
|
+
polygon = [startIndex];
|
|
914
|
+
ringAreas = [area2];
|
|
915
|
+
} else {
|
|
916
|
+
ringAreas.push(area2);
|
|
917
|
+
polygon.push(startIndex);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
if (ringAreas)
|
|
921
|
+
areas.push(ringAreas);
|
|
922
|
+
if (polygon.length)
|
|
923
|
+
polygons.push(polygon);
|
|
924
|
+
return { areas, lines: polygons, data: geom.data };
|
|
925
|
+
}
|
|
926
|
+
function project(data, x0, y0, size) {
|
|
927
|
+
for (let j = 0, jl = data.length; j < jl; j += 2) {
|
|
928
|
+
data[j] = (data[j] + x0) * 360 / size - 180;
|
|
929
|
+
const y2 = 180 - (data[j + 1] + y0) * 360 / size;
|
|
930
|
+
data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
function readFeature2(tag, feature, pbf) {
|
|
934
|
+
if (feature && pbf) {
|
|
935
|
+
if (tag === 1)
|
|
936
|
+
feature.id = pbf.readVarint();
|
|
937
|
+
else if (tag === 2)
|
|
938
|
+
readTag2(pbf, feature);
|
|
939
|
+
else if (tag === 3)
|
|
940
|
+
feature.type = pbf.readVarint();
|
|
941
|
+
else if (tag === 4)
|
|
942
|
+
feature._geometry = pbf.pos;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
function readTag2(pbf, feature) {
|
|
946
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
947
|
+
while (pbf.pos < end) {
|
|
948
|
+
const key = feature._keys[pbf.readVarint()];
|
|
949
|
+
const value = feature._values[pbf.readVarint()];
|
|
950
|
+
feature.properties[key] = value;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
var init_binary_util_functions = __esm({
|
|
954
|
+
"src/helpers/binary-util-functions.ts"() {
|
|
955
|
+
init_esm();
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
// src/lib/binary-vector-tile/vector-tile-feature.ts
|
|
960
|
+
var endPos, cmd, cmdLen, length, x, y, i, VectorTileFeature2;
|
|
961
|
+
var init_vector_tile_feature2 = __esm({
|
|
962
|
+
"src/lib/binary-vector-tile/vector-tile-feature.ts"() {
|
|
963
|
+
init_binary_util_functions();
|
|
964
|
+
VectorTileFeature2 = class {
|
|
965
|
+
static get types() {
|
|
966
|
+
return ["Unknown", "Point", "LineString", "Polygon"];
|
|
967
|
+
}
|
|
968
|
+
constructor(pbf, end, extent, keys, values, firstPassData) {
|
|
969
|
+
this.properties = {};
|
|
970
|
+
this.extent = extent;
|
|
971
|
+
this.type = 0;
|
|
972
|
+
this.id = null;
|
|
973
|
+
this._pbf = pbf;
|
|
974
|
+
this._geometry = -1;
|
|
975
|
+
this._keys = keys;
|
|
976
|
+
this._values = values;
|
|
977
|
+
this._firstPassData = firstPassData;
|
|
978
|
+
pbf.readFields(readFeature2, this, end);
|
|
979
|
+
}
|
|
980
|
+
loadGeometry() {
|
|
981
|
+
const pbf = this._pbf;
|
|
982
|
+
pbf.pos = this._geometry;
|
|
983
|
+
endPos = pbf.readVarint() + pbf.pos;
|
|
984
|
+
cmd = 1;
|
|
985
|
+
length = 0;
|
|
986
|
+
x = 0;
|
|
987
|
+
y = 0;
|
|
988
|
+
i = 0;
|
|
989
|
+
const lines = [];
|
|
990
|
+
const data = [];
|
|
991
|
+
while (pbf.pos < endPos) {
|
|
992
|
+
if (length <= 0) {
|
|
993
|
+
cmdLen = pbf.readVarint();
|
|
994
|
+
cmd = cmdLen & 7;
|
|
995
|
+
length = cmdLen >> 3;
|
|
996
|
+
}
|
|
997
|
+
length--;
|
|
998
|
+
if (cmd === 1 || cmd === 2) {
|
|
999
|
+
x += pbf.readSVarint();
|
|
1000
|
+
y += pbf.readSVarint();
|
|
1001
|
+
if (cmd === 1) {
|
|
1002
|
+
lines.push(i);
|
|
1003
|
+
}
|
|
1004
|
+
data.push(x, y);
|
|
1005
|
+
i += 2;
|
|
1006
|
+
} else if (cmd === 7) {
|
|
1007
|
+
if (i > 0) {
|
|
1008
|
+
const start = lines[lines.length - 1];
|
|
1009
|
+
data.push(data[start], data[start + 1]);
|
|
1010
|
+
i += 2;
|
|
1011
|
+
}
|
|
1012
|
+
} else {
|
|
1013
|
+
throw new Error(`unknown command ${cmd}`);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
return { data, lines };
|
|
1017
|
+
}
|
|
1018
|
+
_toBinaryCoordinates(transform) {
|
|
1019
|
+
let geom = this.loadGeometry();
|
|
1020
|
+
transform(geom.data, this);
|
|
1021
|
+
const coordLength = 2;
|
|
1022
|
+
switch (this.type) {
|
|
1023
|
+
case 1:
|
|
1024
|
+
this._firstPassData.pointFeaturesCount++;
|
|
1025
|
+
this._firstPassData.pointPositionsCount += geom.lines.length;
|
|
1026
|
+
break;
|
|
1027
|
+
case 2:
|
|
1028
|
+
this._firstPassData.lineFeaturesCount++;
|
|
1029
|
+
this._firstPassData.linePathsCount += geom.lines.length;
|
|
1030
|
+
this._firstPassData.linePositionsCount += geom.data.length / coordLength;
|
|
1031
|
+
break;
|
|
1032
|
+
case 3:
|
|
1033
|
+
const classified = classifyRings2(geom);
|
|
1034
|
+
this._firstPassData.polygonFeaturesCount++;
|
|
1035
|
+
this._firstPassData.polygonObjectsCount += classified.lines.length;
|
|
1036
|
+
for (const lines of classified.lines) {
|
|
1037
|
+
this._firstPassData.polygonRingsCount += lines.length;
|
|
1038
|
+
}
|
|
1039
|
+
this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;
|
|
1040
|
+
geom = classified;
|
|
1041
|
+
break;
|
|
1042
|
+
}
|
|
1043
|
+
geom.type = VectorTileFeature2.types[this.type];
|
|
1044
|
+
if (geom.lines.length > 1) {
|
|
1045
|
+
geom.type = `Multi${geom.type}`;
|
|
1046
|
+
}
|
|
1047
|
+
const result = {
|
|
1048
|
+
type: "Feature",
|
|
1049
|
+
geometry: geom,
|
|
1050
|
+
properties: this.properties
|
|
1051
|
+
};
|
|
1052
|
+
if (this.id !== null) {
|
|
1053
|
+
result.id = this.id;
|
|
1054
|
+
}
|
|
1055
|
+
return result;
|
|
1056
|
+
}
|
|
1057
|
+
toBinaryCoordinates(options) {
|
|
1058
|
+
if (typeof options === "function") {
|
|
1059
|
+
return this._toBinaryCoordinates(options);
|
|
1060
|
+
}
|
|
1061
|
+
return this._toBinaryCoordinates(project);
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
1068
|
+
function readLayer2(tag, layer, pbf) {
|
|
1069
|
+
if (layer && pbf) {
|
|
1070
|
+
if (tag === 15)
|
|
1071
|
+
layer.version = pbf.readVarint();
|
|
1072
|
+
else if (tag === 1)
|
|
1073
|
+
layer.name = pbf.readString();
|
|
1074
|
+
else if (tag === 5)
|
|
1075
|
+
layer.extent = pbf.readVarint();
|
|
1076
|
+
else if (tag === 2)
|
|
1077
|
+
layer._features.push(pbf.pos);
|
|
1078
|
+
else if (tag === 3)
|
|
1079
|
+
layer._keys.push(pbf.readString());
|
|
1080
|
+
else if (tag === 4)
|
|
1081
|
+
layer._values.push(readValueMessage2(pbf));
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
function readValueMessage2(pbf) {
|
|
1085
|
+
let value = null;
|
|
1086
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1087
|
+
while (pbf.pos < end) {
|
|
1088
|
+
const tag = pbf.readVarint() >> 3;
|
|
1089
|
+
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;
|
|
1090
|
+
}
|
|
1091
|
+
return value;
|
|
1092
|
+
}
|
|
1093
|
+
var VectorTileLayer2;
|
|
1094
|
+
var init_vector_tile_layer2 = __esm({
|
|
1095
|
+
"src/lib/binary-vector-tile/vector-tile-layer.ts"() {
|
|
1096
|
+
init_vector_tile_feature2();
|
|
1097
|
+
VectorTileLayer2 = class {
|
|
1098
|
+
constructor(pbf, end) {
|
|
1099
|
+
this.version = 1;
|
|
1100
|
+
this.name = "";
|
|
1101
|
+
this.extent = 4096;
|
|
1102
|
+
this.length = 0;
|
|
1103
|
+
this._pbf = pbf;
|
|
1104
|
+
this._keys = [];
|
|
1105
|
+
this._values = [];
|
|
1106
|
+
this._features = [];
|
|
1107
|
+
pbf.readFields(readLayer2, this, end);
|
|
1108
|
+
this.length = this._features.length;
|
|
1109
|
+
}
|
|
1110
|
+
feature(i2, firstPassData) {
|
|
1111
|
+
if (i2 < 0 || i2 >= this._features.length) {
|
|
1112
|
+
throw new Error("feature index out of bounds");
|
|
1113
|
+
}
|
|
1114
|
+
this._pbf.pos = this._features[i2];
|
|
1115
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1116
|
+
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, firstPassData);
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
});
|
|
1121
|
+
|
|
1122
|
+
// src/lib/binary-vector-tile/vector-tile.ts
|
|
1123
|
+
function readTile2(tag, layers, pbf) {
|
|
1124
|
+
if (tag === 3) {
|
|
1125
|
+
if (pbf) {
|
|
1126
|
+
const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
|
|
1127
|
+
if (layer.length && layers) {
|
|
1128
|
+
layers[layer.name] = layer;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
var VectorTile2;
|
|
1134
|
+
var init_vector_tile2 = __esm({
|
|
1135
|
+
"src/lib/binary-vector-tile/vector-tile.ts"() {
|
|
1136
|
+
init_vector_tile_layer2();
|
|
1137
|
+
VectorTile2 = class {
|
|
1138
|
+
constructor(pbf, end) {
|
|
1139
|
+
this.layers = pbf.readFields(readTile2, {}, end);
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
|
|
1145
|
+
// src/lib/binary-vector-tile/features-to-binary.ts
|
|
1146
|
+
function featuresToBinary(features, firstPassData, options) {
|
|
1147
|
+
return fillArrays(features, firstPassData, {
|
|
1148
|
+
numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),
|
|
1149
|
+
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
function extractNumericPropKeys(features) {
|
|
1153
|
+
const numericPropKeys = {};
|
|
1154
|
+
for (const feature of features) {
|
|
1155
|
+
if (feature.properties) {
|
|
1156
|
+
for (const key in feature.properties) {
|
|
1157
|
+
const numericSoFar = numericPropKeys[key];
|
|
1158
|
+
if (numericSoFar || numericSoFar === void 0) {
|
|
1159
|
+
const val = feature.properties[key];
|
|
1160
|
+
numericPropKeys[key] = isNumeric(val);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
return Object.keys(numericPropKeys).filter((k) => numericPropKeys[k]);
|
|
1166
|
+
}
|
|
1167
|
+
function fillArrays(features, firstPassData, options) {
|
|
1168
|
+
const {
|
|
1169
|
+
pointPositionsCount,
|
|
1170
|
+
pointFeaturesCount,
|
|
1171
|
+
linePositionsCount,
|
|
1172
|
+
linePathsCount,
|
|
1173
|
+
lineFeaturesCount,
|
|
1174
|
+
polygonPositionsCount,
|
|
1175
|
+
polygonObjectsCount,
|
|
1176
|
+
polygonRingsCount,
|
|
1177
|
+
polygonFeaturesCount
|
|
1178
|
+
} = firstPassData;
|
|
1179
|
+
const { numericPropKeys, PositionDataType = Float32Array } = options;
|
|
1180
|
+
const hasGlobalId = features[0] && "id" in features[0];
|
|
1181
|
+
const coordLength = 2;
|
|
1182
|
+
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1183
|
+
const points = {
|
|
1184
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1185
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1186
|
+
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1187
|
+
numericProps: {},
|
|
1188
|
+
properties: [],
|
|
1189
|
+
fields: []
|
|
1190
|
+
};
|
|
1191
|
+
const lines = {
|
|
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
|
+
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1202
|
+
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1203
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
1204
|
+
triangles: [],
|
|
1205
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1206
|
+
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1207
|
+
numericProps: {},
|
|
1208
|
+
properties: [],
|
|
1209
|
+
fields: []
|
|
1210
|
+
};
|
|
1211
|
+
for (const object of [points, lines, polygons]) {
|
|
1212
|
+
for (const propName of numericPropKeys) {
|
|
1213
|
+
object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
1217
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
1218
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
1219
|
+
const indexMap = {
|
|
1220
|
+
pointPosition: 0,
|
|
1221
|
+
pointFeature: 0,
|
|
1222
|
+
linePosition: 0,
|
|
1223
|
+
linePath: 0,
|
|
1224
|
+
lineFeature: 0,
|
|
1225
|
+
polygonPosition: 0,
|
|
1226
|
+
polygonObject: 0,
|
|
1227
|
+
polygonRing: 0,
|
|
1228
|
+
polygonFeature: 0,
|
|
1229
|
+
feature: 0
|
|
1230
|
+
};
|
|
1231
|
+
for (const feature of features) {
|
|
1232
|
+
const geometry = feature.geometry;
|
|
1233
|
+
const properties = feature.properties || {};
|
|
1234
|
+
switch (geometry.type) {
|
|
1235
|
+
case "Point":
|
|
1236
|
+
case "MultiPoint":
|
|
1237
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1238
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1239
|
+
if (hasGlobalId) {
|
|
1240
|
+
points.fields.push({ id: feature.id });
|
|
1241
|
+
}
|
|
1242
|
+
indexMap.pointFeature++;
|
|
1243
|
+
break;
|
|
1244
|
+
case "LineString":
|
|
1245
|
+
case "MultiLineString":
|
|
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
|
+
case "MultiPolygon":
|
|
1255
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1256
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1257
|
+
if (hasGlobalId) {
|
|
1258
|
+
polygons.fields.push({ id: feature.id });
|
|
1259
|
+
}
|
|
1260
|
+
indexMap.polygonFeature++;
|
|
1261
|
+
break;
|
|
1262
|
+
default:
|
|
1263
|
+
throw new Error("Invalid geometry type");
|
|
1264
|
+
}
|
|
1265
|
+
indexMap.feature++;
|
|
1266
|
+
}
|
|
1267
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
1268
|
+
}
|
|
1269
|
+
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
1270
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
1271
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1272
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
1273
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1274
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1275
|
+
indexMap.pointPosition += nPositions;
|
|
1276
|
+
}
|
|
1277
|
+
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1278
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1279
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1280
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1281
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1282
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1283
|
+
for (let i2 = 0, il = geometry.lines.length; i2 < il; ++i2) {
|
|
1284
|
+
const start = geometry.lines[i2];
|
|
1285
|
+
const end = i2 === il - 1 ? geometry.data.length : geometry.lines[i2 + 1];
|
|
1286
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1287
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
1291
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
1292
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1293
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
1294
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1295
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1296
|
+
for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {
|
|
1297
|
+
const startPosition = indexMap.polygonPosition;
|
|
1298
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
1299
|
+
const areas = geometry.areas[l];
|
|
1300
|
+
const lines = geometry.lines[l];
|
|
1301
|
+
const nextLines = geometry.lines[l + 1];
|
|
1302
|
+
for (let i2 = 0, il = lines.length; i2 < il; ++i2) {
|
|
1303
|
+
const start = lines[i2];
|
|
1304
|
+
const end = i2 === il - 1 ? nextLines === void 0 ? geometry.data.length : nextLines[0] : lines[i2 + 1];
|
|
1305
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
1306
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
1307
|
+
}
|
|
1308
|
+
const endPosition = indexMap.polygonPosition;
|
|
1309
|
+
triangulatePolygon(polygons, areas, lines, { startPosition, endPosition, coordLength });
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
function triangulatePolygon(polygons, areas, lines, {
|
|
1313
|
+
startPosition,
|
|
1314
|
+
endPosition,
|
|
1315
|
+
coordLength
|
|
1316
|
+
}) {
|
|
1317
|
+
const start = startPosition * coordLength;
|
|
1318
|
+
const end = endPosition * coordLength;
|
|
1319
|
+
const polygonPositions = polygons.positions.subarray(start, end);
|
|
1320
|
+
const offset = lines[0];
|
|
1321
|
+
const holes = lines.slice(1).map((n) => (n - offset) / coordLength);
|
|
1322
|
+
const indices = earcut(polygonPositions, holes, coordLength, areas);
|
|
1323
|
+
for (let t = 0, tl = indices.length; t < tl; ++t) {
|
|
1324
|
+
polygons.triangles.push(startPosition + indices[t]);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1328
|
+
const returnObj = {
|
|
1329
|
+
points: {
|
|
1330
|
+
...points,
|
|
1331
|
+
positions: { value: points.positions, size: coordLength },
|
|
1332
|
+
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
1333
|
+
featureIds: { value: points.featureIds, size: 1 }
|
|
1334
|
+
},
|
|
1335
|
+
lines: {
|
|
1336
|
+
...lines,
|
|
1337
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
1338
|
+
positions: { value: lines.positions, size: coordLength },
|
|
1339
|
+
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
1340
|
+
featureIds: { value: lines.featureIds, size: 1 }
|
|
1341
|
+
},
|
|
1342
|
+
polygons: {
|
|
1343
|
+
...polygons,
|
|
1344
|
+
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
1345
|
+
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
1346
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
1347
|
+
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
1348
|
+
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
1349
|
+
featureIds: { value: polygons.featureIds, size: 1 }
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
for (const geomType in returnObj) {
|
|
1353
|
+
for (const numericProp in returnObj[geomType].numericProps) {
|
|
1354
|
+
returnObj[geomType].numericProps[numericProp] = {
|
|
1355
|
+
value: returnObj[geomType].numericProps[numericProp],
|
|
1356
|
+
size: 1
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
return returnObj;
|
|
1361
|
+
}
|
|
1362
|
+
function fillNumericProperties(object, properties, index, length2) {
|
|
1363
|
+
for (const numericPropName in object.numericProps) {
|
|
1364
|
+
if (numericPropName in properties) {
|
|
1365
|
+
object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length2);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
function keepStringProperties(properties, numericKeys) {
|
|
1370
|
+
const props = {};
|
|
1371
|
+
for (const key in properties) {
|
|
1372
|
+
if (!numericKeys.includes(key)) {
|
|
1373
|
+
props[key] = properties[key];
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
return props;
|
|
1377
|
+
}
|
|
1378
|
+
function isNumeric(x2) {
|
|
1379
|
+
return Number.isFinite(x2);
|
|
1380
|
+
}
|
|
1381
|
+
var init_features_to_binary = __esm({
|
|
1382
|
+
"src/lib/binary-vector-tile/features-to-binary.ts"() {
|
|
1383
|
+
init_esm();
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
|
|
1387
|
+
// ../../node_modules/ieee754/index.js
|
|
1388
|
+
var require_ieee754 = __commonJS({
|
|
1389
|
+
"../../node_modules/ieee754/index.js"(exports) {
|
|
1390
|
+
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
1391
|
+
var e, m;
|
|
1392
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
1393
|
+
var eMax = (1 << eLen) - 1;
|
|
1394
|
+
var eBias = eMax >> 1;
|
|
1395
|
+
var nBits = -7;
|
|
1396
|
+
var i2 = isLE ? nBytes - 1 : 0;
|
|
1397
|
+
var d = isLE ? -1 : 1;
|
|
1398
|
+
var s = buffer[offset + i2];
|
|
1399
|
+
i2 += d;
|
|
1400
|
+
e = s & (1 << -nBits) - 1;
|
|
1401
|
+
s >>= -nBits;
|
|
1402
|
+
nBits += eLen;
|
|
1403
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
|
|
1404
|
+
}
|
|
1405
|
+
m = e & (1 << -nBits) - 1;
|
|
1406
|
+
e >>= -nBits;
|
|
1407
|
+
nBits += mLen;
|
|
1408
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
|
|
1409
|
+
}
|
|
1410
|
+
if (e === 0) {
|
|
1411
|
+
e = 1 - eBias;
|
|
1412
|
+
} else if (e === eMax) {
|
|
1413
|
+
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
1414
|
+
} else {
|
|
1415
|
+
m = m + Math.pow(2, mLen);
|
|
1416
|
+
e = e - eBias;
|
|
1417
|
+
}
|
|
1418
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
1419
|
+
};
|
|
1420
|
+
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
1421
|
+
var e, m, c;
|
|
1422
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
1423
|
+
var eMax = (1 << eLen) - 1;
|
|
1424
|
+
var eBias = eMax >> 1;
|
|
1425
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
1426
|
+
var i2 = isLE ? 0 : nBytes - 1;
|
|
1427
|
+
var d = isLE ? 1 : -1;
|
|
1428
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
1429
|
+
value = Math.abs(value);
|
|
1430
|
+
if (isNaN(value) || value === Infinity) {
|
|
1431
|
+
m = isNaN(value) ? 1 : 0;
|
|
1432
|
+
e = eMax;
|
|
1433
|
+
} else {
|
|
1434
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
1435
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
1436
|
+
e--;
|
|
1437
|
+
c *= 2;
|
|
1438
|
+
}
|
|
1439
|
+
if (e + eBias >= 1) {
|
|
1440
|
+
value += rt / c;
|
|
1441
|
+
} else {
|
|
1442
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
1443
|
+
}
|
|
1444
|
+
if (value * c >= 2) {
|
|
1445
|
+
e++;
|
|
1446
|
+
c /= 2;
|
|
1447
|
+
}
|
|
1448
|
+
if (e + eBias >= eMax) {
|
|
1449
|
+
m = 0;
|
|
1450
|
+
e = eMax;
|
|
1451
|
+
} else if (e + eBias >= 1) {
|
|
1452
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
1453
|
+
e = e + eBias;
|
|
1454
|
+
} else {
|
|
1455
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
1456
|
+
e = 0;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
for (; mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8) {
|
|
1460
|
+
}
|
|
1461
|
+
e = e << mLen | m;
|
|
1462
|
+
eLen += mLen;
|
|
1463
|
+
for (; eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8) {
|
|
1464
|
+
}
|
|
1465
|
+
buffer[offset + i2 - d] |= s * 128;
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
});
|
|
1469
|
+
|
|
1470
|
+
// ../../node_modules/pbf/index.js
|
|
1471
|
+
var require_pbf = __commonJS({
|
|
1472
|
+
"../../node_modules/pbf/index.js"(exports, module) {
|
|
1473
|
+
"use strict";
|
|
1474
|
+
module.exports = Pbf;
|
|
1475
|
+
var ieee754 = require_ieee754();
|
|
1476
|
+
function Pbf(buf) {
|
|
1477
|
+
this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
|
|
1478
|
+
this.pos = 0;
|
|
1479
|
+
this.type = 0;
|
|
1480
|
+
this.length = this.buf.length;
|
|
1481
|
+
}
|
|
1482
|
+
Pbf.Varint = 0;
|
|
1483
|
+
Pbf.Fixed64 = 1;
|
|
1484
|
+
Pbf.Bytes = 2;
|
|
1485
|
+
Pbf.Fixed32 = 5;
|
|
1486
|
+
var SHIFT_LEFT_32 = (1 << 16) * (1 << 16);
|
|
1487
|
+
var SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;
|
|
1488
|
+
var TEXT_DECODER_MIN_LENGTH = 12;
|
|
1489
|
+
var utf8TextDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf8");
|
|
1490
|
+
Pbf.prototype = {
|
|
1491
|
+
destroy: function() {
|
|
1492
|
+
this.buf = null;
|
|
1493
|
+
},
|
|
1494
|
+
readFields: function(readField, result, end) {
|
|
1495
|
+
end = end || this.length;
|
|
1496
|
+
while (this.pos < end) {
|
|
1497
|
+
var val = this.readVarint(), tag = val >> 3, startPos = this.pos;
|
|
1498
|
+
this.type = val & 7;
|
|
1499
|
+
readField(tag, result, this);
|
|
1500
|
+
if (this.pos === startPos)
|
|
1501
|
+
this.skip(val);
|
|
1502
|
+
}
|
|
1503
|
+
return result;
|
|
1504
|
+
},
|
|
1505
|
+
readMessage: function(readField, result) {
|
|
1506
|
+
return this.readFields(readField, result, this.readVarint() + this.pos);
|
|
1507
|
+
},
|
|
1508
|
+
readFixed32: function() {
|
|
1509
|
+
var val = readUInt32(this.buf, this.pos);
|
|
1510
|
+
this.pos += 4;
|
|
1511
|
+
return val;
|
|
1512
|
+
},
|
|
1513
|
+
readSFixed32: function() {
|
|
1514
|
+
var val = readInt32(this.buf, this.pos);
|
|
1515
|
+
this.pos += 4;
|
|
1516
|
+
return val;
|
|
1517
|
+
},
|
|
1518
|
+
readFixed64: function() {
|
|
1519
|
+
var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
|
|
1520
|
+
this.pos += 8;
|
|
1521
|
+
return val;
|
|
1522
|
+
},
|
|
1523
|
+
readSFixed64: function() {
|
|
1524
|
+
var val = readUInt32(this.buf, this.pos) + readInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
|
|
1525
|
+
this.pos += 8;
|
|
1526
|
+
return val;
|
|
1527
|
+
},
|
|
1528
|
+
readFloat: function() {
|
|
1529
|
+
var val = ieee754.read(this.buf, this.pos, true, 23, 4);
|
|
1530
|
+
this.pos += 4;
|
|
1531
|
+
return val;
|
|
1532
|
+
},
|
|
1533
|
+
readDouble: function() {
|
|
1534
|
+
var val = ieee754.read(this.buf, this.pos, true, 52, 8);
|
|
1535
|
+
this.pos += 8;
|
|
1536
|
+
return val;
|
|
1537
|
+
},
|
|
1538
|
+
readVarint: function(isSigned) {
|
|
1539
|
+
var buf = this.buf, val, b;
|
|
1540
|
+
b = buf[this.pos++];
|
|
1541
|
+
val = b & 127;
|
|
1542
|
+
if (b < 128)
|
|
1543
|
+
return val;
|
|
1544
|
+
b = buf[this.pos++];
|
|
1545
|
+
val |= (b & 127) << 7;
|
|
1546
|
+
if (b < 128)
|
|
1547
|
+
return val;
|
|
1548
|
+
b = buf[this.pos++];
|
|
1549
|
+
val |= (b & 127) << 14;
|
|
1550
|
+
if (b < 128)
|
|
1551
|
+
return val;
|
|
1552
|
+
b = buf[this.pos++];
|
|
1553
|
+
val |= (b & 127) << 21;
|
|
1554
|
+
if (b < 128)
|
|
1555
|
+
return val;
|
|
1556
|
+
b = buf[this.pos];
|
|
1557
|
+
val |= (b & 15) << 28;
|
|
1558
|
+
return readVarintRemainder(val, isSigned, this);
|
|
1559
|
+
},
|
|
1560
|
+
readVarint64: function() {
|
|
1561
|
+
return this.readVarint(true);
|
|
1562
|
+
},
|
|
1563
|
+
readSVarint: function() {
|
|
1564
|
+
var num = this.readVarint();
|
|
1565
|
+
return num % 2 === 1 ? (num + 1) / -2 : num / 2;
|
|
1566
|
+
},
|
|
1567
|
+
readBoolean: function() {
|
|
1568
|
+
return Boolean(this.readVarint());
|
|
1569
|
+
},
|
|
1570
|
+
readString: function() {
|
|
1571
|
+
var end = this.readVarint() + this.pos;
|
|
1572
|
+
var pos = this.pos;
|
|
1573
|
+
this.pos = end;
|
|
1574
|
+
if (end - pos >= TEXT_DECODER_MIN_LENGTH && utf8TextDecoder) {
|
|
1575
|
+
return readUtf8TextDecoder(this.buf, pos, end);
|
|
1576
|
+
}
|
|
1577
|
+
return readUtf8(this.buf, pos, end);
|
|
1578
|
+
},
|
|
1579
|
+
readBytes: function() {
|
|
1580
|
+
var end = this.readVarint() + this.pos, buffer = this.buf.subarray(this.pos, end);
|
|
1581
|
+
this.pos = end;
|
|
1582
|
+
return buffer;
|
|
1583
|
+
},
|
|
1584
|
+
readPackedVarint: function(arr, isSigned) {
|
|
1585
|
+
if (this.type !== Pbf.Bytes)
|
|
1586
|
+
return arr.push(this.readVarint(isSigned));
|
|
1587
|
+
var end = readPackedEnd(this);
|
|
1588
|
+
arr = arr || [];
|
|
1589
|
+
while (this.pos < end)
|
|
1590
|
+
arr.push(this.readVarint(isSigned));
|
|
1591
|
+
return arr;
|
|
1592
|
+
},
|
|
1593
|
+
readPackedSVarint: function(arr) {
|
|
1594
|
+
if (this.type !== Pbf.Bytes)
|
|
1595
|
+
return arr.push(this.readSVarint());
|
|
1596
|
+
var end = readPackedEnd(this);
|
|
1597
|
+
arr = arr || [];
|
|
1598
|
+
while (this.pos < end)
|
|
1599
|
+
arr.push(this.readSVarint());
|
|
1600
|
+
return arr;
|
|
1601
|
+
},
|
|
1602
|
+
readPackedBoolean: function(arr) {
|
|
1603
|
+
if (this.type !== Pbf.Bytes)
|
|
1604
|
+
return arr.push(this.readBoolean());
|
|
1605
|
+
var end = readPackedEnd(this);
|
|
1606
|
+
arr = arr || [];
|
|
1607
|
+
while (this.pos < end)
|
|
1608
|
+
arr.push(this.readBoolean());
|
|
1609
|
+
return arr;
|
|
1610
|
+
},
|
|
1611
|
+
readPackedFloat: function(arr) {
|
|
1612
|
+
if (this.type !== Pbf.Bytes)
|
|
1613
|
+
return arr.push(this.readFloat());
|
|
1614
|
+
var end = readPackedEnd(this);
|
|
1615
|
+
arr = arr || [];
|
|
1616
|
+
while (this.pos < end)
|
|
1617
|
+
arr.push(this.readFloat());
|
|
1618
|
+
return arr;
|
|
1619
|
+
},
|
|
1620
|
+
readPackedDouble: function(arr) {
|
|
1621
|
+
if (this.type !== Pbf.Bytes)
|
|
1622
|
+
return arr.push(this.readDouble());
|
|
1623
|
+
var end = readPackedEnd(this);
|
|
1624
|
+
arr = arr || [];
|
|
1625
|
+
while (this.pos < end)
|
|
1626
|
+
arr.push(this.readDouble());
|
|
1627
|
+
return arr;
|
|
1628
|
+
},
|
|
1629
|
+
readPackedFixed32: function(arr) {
|
|
1630
|
+
if (this.type !== Pbf.Bytes)
|
|
1631
|
+
return arr.push(this.readFixed32());
|
|
1632
|
+
var end = readPackedEnd(this);
|
|
1633
|
+
arr = arr || [];
|
|
1634
|
+
while (this.pos < end)
|
|
1635
|
+
arr.push(this.readFixed32());
|
|
1636
|
+
return arr;
|
|
1637
|
+
},
|
|
1638
|
+
readPackedSFixed32: function(arr) {
|
|
1639
|
+
if (this.type !== Pbf.Bytes)
|
|
1640
|
+
return arr.push(this.readSFixed32());
|
|
1641
|
+
var end = readPackedEnd(this);
|
|
1642
|
+
arr = arr || [];
|
|
1643
|
+
while (this.pos < end)
|
|
1644
|
+
arr.push(this.readSFixed32());
|
|
1645
|
+
return arr;
|
|
1646
|
+
},
|
|
1647
|
+
readPackedFixed64: function(arr) {
|
|
1648
|
+
if (this.type !== Pbf.Bytes)
|
|
1649
|
+
return arr.push(this.readFixed64());
|
|
1650
|
+
var end = readPackedEnd(this);
|
|
1651
|
+
arr = arr || [];
|
|
1652
|
+
while (this.pos < end)
|
|
1653
|
+
arr.push(this.readFixed64());
|
|
1654
|
+
return arr;
|
|
1655
|
+
},
|
|
1656
|
+
readPackedSFixed64: function(arr) {
|
|
1657
|
+
if (this.type !== Pbf.Bytes)
|
|
1658
|
+
return arr.push(this.readSFixed64());
|
|
1659
|
+
var end = readPackedEnd(this);
|
|
1660
|
+
arr = arr || [];
|
|
1661
|
+
while (this.pos < end)
|
|
1662
|
+
arr.push(this.readSFixed64());
|
|
1663
|
+
return arr;
|
|
1664
|
+
},
|
|
1665
|
+
skip: function(val) {
|
|
1666
|
+
var type = val & 7;
|
|
1667
|
+
if (type === Pbf.Varint)
|
|
1668
|
+
while (this.buf[this.pos++] > 127) {
|
|
1669
|
+
}
|
|
1670
|
+
else if (type === Pbf.Bytes)
|
|
1671
|
+
this.pos = this.readVarint() + this.pos;
|
|
1672
|
+
else if (type === Pbf.Fixed32)
|
|
1673
|
+
this.pos += 4;
|
|
1674
|
+
else if (type === Pbf.Fixed64)
|
|
1675
|
+
this.pos += 8;
|
|
1676
|
+
else
|
|
1677
|
+
throw new Error("Unimplemented type: " + type);
|
|
1678
|
+
},
|
|
1679
|
+
writeTag: function(tag, type) {
|
|
1680
|
+
this.writeVarint(tag << 3 | type);
|
|
1681
|
+
},
|
|
1682
|
+
realloc: function(min) {
|
|
1683
|
+
var length2 = this.length || 16;
|
|
1684
|
+
while (length2 < this.pos + min)
|
|
1685
|
+
length2 *= 2;
|
|
1686
|
+
if (length2 !== this.length) {
|
|
1687
|
+
var buf = new Uint8Array(length2);
|
|
1688
|
+
buf.set(this.buf);
|
|
1689
|
+
this.buf = buf;
|
|
1690
|
+
this.length = length2;
|
|
1691
|
+
}
|
|
1692
|
+
},
|
|
1693
|
+
finish: function() {
|
|
1694
|
+
this.length = this.pos;
|
|
1695
|
+
this.pos = 0;
|
|
1696
|
+
return this.buf.subarray(0, this.length);
|
|
1697
|
+
},
|
|
1698
|
+
writeFixed32: function(val) {
|
|
1699
|
+
this.realloc(4);
|
|
1700
|
+
writeInt32(this.buf, val, this.pos);
|
|
1701
|
+
this.pos += 4;
|
|
1702
|
+
},
|
|
1703
|
+
writeSFixed32: function(val) {
|
|
1704
|
+
this.realloc(4);
|
|
1705
|
+
writeInt32(this.buf, val, this.pos);
|
|
1706
|
+
this.pos += 4;
|
|
1707
|
+
},
|
|
1708
|
+
writeFixed64: function(val) {
|
|
1709
|
+
this.realloc(8);
|
|
1710
|
+
writeInt32(this.buf, val & -1, this.pos);
|
|
1711
|
+
writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
|
|
1712
|
+
this.pos += 8;
|
|
1713
|
+
},
|
|
1714
|
+
writeSFixed64: function(val) {
|
|
1715
|
+
this.realloc(8);
|
|
1716
|
+
writeInt32(this.buf, val & -1, this.pos);
|
|
1717
|
+
writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
|
|
1718
|
+
this.pos += 8;
|
|
1719
|
+
},
|
|
1720
|
+
writeVarint: function(val) {
|
|
1721
|
+
val = +val || 0;
|
|
1722
|
+
if (val > 268435455 || val < 0) {
|
|
1723
|
+
writeBigVarint(val, this);
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
this.realloc(4);
|
|
1727
|
+
this.buf[this.pos++] = val & 127 | (val > 127 ? 128 : 0);
|
|
1728
|
+
if (val <= 127)
|
|
1729
|
+
return;
|
|
1730
|
+
this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0);
|
|
1731
|
+
if (val <= 127)
|
|
1732
|
+
return;
|
|
1733
|
+
this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0);
|
|
1734
|
+
if (val <= 127)
|
|
1735
|
+
return;
|
|
1736
|
+
this.buf[this.pos++] = val >>> 7 & 127;
|
|
1737
|
+
},
|
|
1738
|
+
writeSVarint: function(val) {
|
|
1739
|
+
this.writeVarint(val < 0 ? -val * 2 - 1 : val * 2);
|
|
1740
|
+
},
|
|
1741
|
+
writeBoolean: function(val) {
|
|
1742
|
+
this.writeVarint(Boolean(val));
|
|
1743
|
+
},
|
|
1744
|
+
writeString: function(str) {
|
|
1745
|
+
str = String(str);
|
|
1746
|
+
this.realloc(str.length * 4);
|
|
1747
|
+
this.pos++;
|
|
1748
|
+
var startPos = this.pos;
|
|
1749
|
+
this.pos = writeUtf8(this.buf, str, this.pos);
|
|
1750
|
+
var len = this.pos - startPos;
|
|
1751
|
+
if (len >= 128)
|
|
1752
|
+
makeRoomForExtraLength(startPos, len, this);
|
|
1753
|
+
this.pos = startPos - 1;
|
|
1754
|
+
this.writeVarint(len);
|
|
1755
|
+
this.pos += len;
|
|
1756
|
+
},
|
|
1757
|
+
writeFloat: function(val) {
|
|
1758
|
+
this.realloc(4);
|
|
1759
|
+
ieee754.write(this.buf, val, this.pos, true, 23, 4);
|
|
1760
|
+
this.pos += 4;
|
|
1761
|
+
},
|
|
1762
|
+
writeDouble: function(val) {
|
|
1763
|
+
this.realloc(8);
|
|
1764
|
+
ieee754.write(this.buf, val, this.pos, true, 52, 8);
|
|
1765
|
+
this.pos += 8;
|
|
1766
|
+
},
|
|
1767
|
+
writeBytes: function(buffer) {
|
|
1768
|
+
var len = buffer.length;
|
|
1769
|
+
this.writeVarint(len);
|
|
1770
|
+
this.realloc(len);
|
|
1771
|
+
for (var i2 = 0; i2 < len; i2++)
|
|
1772
|
+
this.buf[this.pos++] = buffer[i2];
|
|
1773
|
+
},
|
|
1774
|
+
writeRawMessage: function(fn, obj) {
|
|
1775
|
+
this.pos++;
|
|
1776
|
+
var startPos = this.pos;
|
|
1777
|
+
fn(obj, this);
|
|
1778
|
+
var len = this.pos - startPos;
|
|
1779
|
+
if (len >= 128)
|
|
1780
|
+
makeRoomForExtraLength(startPos, len, this);
|
|
1781
|
+
this.pos = startPos - 1;
|
|
1782
|
+
this.writeVarint(len);
|
|
1783
|
+
this.pos += len;
|
|
1784
|
+
},
|
|
1785
|
+
writeMessage: function(tag, fn, obj) {
|
|
1786
|
+
this.writeTag(tag, Pbf.Bytes);
|
|
1787
|
+
this.writeRawMessage(fn, obj);
|
|
1788
|
+
},
|
|
1789
|
+
writePackedVarint: function(tag, arr) {
|
|
1790
|
+
if (arr.length)
|
|
1791
|
+
this.writeMessage(tag, writePackedVarint, arr);
|
|
1792
|
+
},
|
|
1793
|
+
writePackedSVarint: function(tag, arr) {
|
|
1794
|
+
if (arr.length)
|
|
1795
|
+
this.writeMessage(tag, writePackedSVarint, arr);
|
|
1796
|
+
},
|
|
1797
|
+
writePackedBoolean: function(tag, arr) {
|
|
1798
|
+
if (arr.length)
|
|
1799
|
+
this.writeMessage(tag, writePackedBoolean, arr);
|
|
1800
|
+
},
|
|
1801
|
+
writePackedFloat: function(tag, arr) {
|
|
1802
|
+
if (arr.length)
|
|
1803
|
+
this.writeMessage(tag, writePackedFloat, arr);
|
|
1804
|
+
},
|
|
1805
|
+
writePackedDouble: function(tag, arr) {
|
|
1806
|
+
if (arr.length)
|
|
1807
|
+
this.writeMessage(tag, writePackedDouble, arr);
|
|
1808
|
+
},
|
|
1809
|
+
writePackedFixed32: function(tag, arr) {
|
|
1810
|
+
if (arr.length)
|
|
1811
|
+
this.writeMessage(tag, writePackedFixed32, arr);
|
|
1812
|
+
},
|
|
1813
|
+
writePackedSFixed32: function(tag, arr) {
|
|
1814
|
+
if (arr.length)
|
|
1815
|
+
this.writeMessage(tag, writePackedSFixed32, arr);
|
|
1816
|
+
},
|
|
1817
|
+
writePackedFixed64: function(tag, arr) {
|
|
1818
|
+
if (arr.length)
|
|
1819
|
+
this.writeMessage(tag, writePackedFixed64, arr);
|
|
1820
|
+
},
|
|
1821
|
+
writePackedSFixed64: function(tag, arr) {
|
|
1822
|
+
if (arr.length)
|
|
1823
|
+
this.writeMessage(tag, writePackedSFixed64, arr);
|
|
1824
|
+
},
|
|
1825
|
+
writeBytesField: function(tag, buffer) {
|
|
1826
|
+
this.writeTag(tag, Pbf.Bytes);
|
|
1827
|
+
this.writeBytes(buffer);
|
|
1828
|
+
},
|
|
1829
|
+
writeFixed32Field: function(tag, val) {
|
|
1830
|
+
this.writeTag(tag, Pbf.Fixed32);
|
|
1831
|
+
this.writeFixed32(val);
|
|
1832
|
+
},
|
|
1833
|
+
writeSFixed32Field: function(tag, val) {
|
|
1834
|
+
this.writeTag(tag, Pbf.Fixed32);
|
|
1835
|
+
this.writeSFixed32(val);
|
|
1836
|
+
},
|
|
1837
|
+
writeFixed64Field: function(tag, val) {
|
|
1838
|
+
this.writeTag(tag, Pbf.Fixed64);
|
|
1839
|
+
this.writeFixed64(val);
|
|
1840
|
+
},
|
|
1841
|
+
writeSFixed64Field: function(tag, val) {
|
|
1842
|
+
this.writeTag(tag, Pbf.Fixed64);
|
|
1843
|
+
this.writeSFixed64(val);
|
|
1844
|
+
},
|
|
1845
|
+
writeVarintField: function(tag, val) {
|
|
1846
|
+
this.writeTag(tag, Pbf.Varint);
|
|
1847
|
+
this.writeVarint(val);
|
|
1848
|
+
},
|
|
1849
|
+
writeSVarintField: function(tag, val) {
|
|
1850
|
+
this.writeTag(tag, Pbf.Varint);
|
|
1851
|
+
this.writeSVarint(val);
|
|
1852
|
+
},
|
|
1853
|
+
writeStringField: function(tag, str) {
|
|
1854
|
+
this.writeTag(tag, Pbf.Bytes);
|
|
1855
|
+
this.writeString(str);
|
|
1856
|
+
},
|
|
1857
|
+
writeFloatField: function(tag, val) {
|
|
1858
|
+
this.writeTag(tag, Pbf.Fixed32);
|
|
1859
|
+
this.writeFloat(val);
|
|
1860
|
+
},
|
|
1861
|
+
writeDoubleField: function(tag, val) {
|
|
1862
|
+
this.writeTag(tag, Pbf.Fixed64);
|
|
1863
|
+
this.writeDouble(val);
|
|
1864
|
+
},
|
|
1865
|
+
writeBooleanField: function(tag, val) {
|
|
1866
|
+
this.writeVarintField(tag, Boolean(val));
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1869
|
+
function readVarintRemainder(l, s, p) {
|
|
1870
|
+
var buf = p.buf, h, b;
|
|
1871
|
+
b = buf[p.pos++];
|
|
1872
|
+
h = (b & 112) >> 4;
|
|
1873
|
+
if (b < 128)
|
|
1874
|
+
return toNum(l, h, s);
|
|
1875
|
+
b = buf[p.pos++];
|
|
1876
|
+
h |= (b & 127) << 3;
|
|
1877
|
+
if (b < 128)
|
|
1878
|
+
return toNum(l, h, s);
|
|
1879
|
+
b = buf[p.pos++];
|
|
1880
|
+
h |= (b & 127) << 10;
|
|
1881
|
+
if (b < 128)
|
|
1882
|
+
return toNum(l, h, s);
|
|
1883
|
+
b = buf[p.pos++];
|
|
1884
|
+
h |= (b & 127) << 17;
|
|
1885
|
+
if (b < 128)
|
|
1886
|
+
return toNum(l, h, s);
|
|
1887
|
+
b = buf[p.pos++];
|
|
1888
|
+
h |= (b & 127) << 24;
|
|
1889
|
+
if (b < 128)
|
|
1890
|
+
return toNum(l, h, s);
|
|
1891
|
+
b = buf[p.pos++];
|
|
1892
|
+
h |= (b & 1) << 31;
|
|
1893
|
+
if (b < 128)
|
|
1894
|
+
return toNum(l, h, s);
|
|
1895
|
+
throw new Error("Expected varint not more than 10 bytes");
|
|
1896
|
+
}
|
|
1897
|
+
function readPackedEnd(pbf) {
|
|
1898
|
+
return pbf.type === Pbf.Bytes ? pbf.readVarint() + pbf.pos : pbf.pos + 1;
|
|
1899
|
+
}
|
|
1900
|
+
function toNum(low, high, isSigned) {
|
|
1901
|
+
if (isSigned) {
|
|
1902
|
+
return high * 4294967296 + (low >>> 0);
|
|
1903
|
+
}
|
|
1904
|
+
return (high >>> 0) * 4294967296 + (low >>> 0);
|
|
1905
|
+
}
|
|
1906
|
+
function writeBigVarint(val, pbf) {
|
|
1907
|
+
var low, high;
|
|
1908
|
+
if (val >= 0) {
|
|
1909
|
+
low = val % 4294967296 | 0;
|
|
1910
|
+
high = val / 4294967296 | 0;
|
|
1911
|
+
} else {
|
|
1912
|
+
low = ~(-val % 4294967296);
|
|
1913
|
+
high = ~(-val / 4294967296);
|
|
1914
|
+
if (low ^ 4294967295) {
|
|
1915
|
+
low = low + 1 | 0;
|
|
1916
|
+
} else {
|
|
1917
|
+
low = 0;
|
|
1918
|
+
high = high + 1 | 0;
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
if (val >= 18446744073709552e3 || val < -18446744073709552e3) {
|
|
1922
|
+
throw new Error("Given varint doesn't fit into 10 bytes");
|
|
1923
|
+
}
|
|
1924
|
+
pbf.realloc(10);
|
|
1925
|
+
writeBigVarintLow(low, high, pbf);
|
|
1926
|
+
writeBigVarintHigh(high, pbf);
|
|
1927
|
+
}
|
|
1928
|
+
function writeBigVarintLow(low, high, pbf) {
|
|
1929
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1930
|
+
low >>>= 7;
|
|
1931
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1932
|
+
low >>>= 7;
|
|
1933
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1934
|
+
low >>>= 7;
|
|
1935
|
+
pbf.buf[pbf.pos++] = low & 127 | 128;
|
|
1936
|
+
low >>>= 7;
|
|
1937
|
+
pbf.buf[pbf.pos] = low & 127;
|
|
1938
|
+
}
|
|
1939
|
+
function writeBigVarintHigh(high, pbf) {
|
|
1940
|
+
var lsb = (high & 7) << 4;
|
|
1941
|
+
pbf.buf[pbf.pos++] |= lsb | ((high >>>= 3) ? 128 : 0);
|
|
1942
|
+
if (!high)
|
|
1943
|
+
return;
|
|
1944
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
1945
|
+
if (!high)
|
|
1946
|
+
return;
|
|
1947
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
1948
|
+
if (!high)
|
|
1949
|
+
return;
|
|
1950
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
1951
|
+
if (!high)
|
|
1952
|
+
return;
|
|
1953
|
+
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
|
|
1954
|
+
if (!high)
|
|
1955
|
+
return;
|
|
1956
|
+
pbf.buf[pbf.pos++] = high & 127;
|
|
1957
|
+
}
|
|
1958
|
+
function makeRoomForExtraLength(startPos, len, pbf) {
|
|
1959
|
+
var extraLen = len <= 16383 ? 1 : len <= 2097151 ? 2 : len <= 268435455 ? 3 : Math.floor(Math.log(len) / (Math.LN2 * 7));
|
|
1960
|
+
pbf.realloc(extraLen);
|
|
1961
|
+
for (var i2 = pbf.pos - 1; i2 >= startPos; i2--)
|
|
1962
|
+
pbf.buf[i2 + extraLen] = pbf.buf[i2];
|
|
1963
|
+
}
|
|
1964
|
+
function writePackedVarint(arr, pbf) {
|
|
1965
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1966
|
+
pbf.writeVarint(arr[i2]);
|
|
1967
|
+
}
|
|
1968
|
+
function writePackedSVarint(arr, pbf) {
|
|
1969
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1970
|
+
pbf.writeSVarint(arr[i2]);
|
|
1971
|
+
}
|
|
1972
|
+
function writePackedFloat(arr, pbf) {
|
|
1973
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1974
|
+
pbf.writeFloat(arr[i2]);
|
|
1975
|
+
}
|
|
1976
|
+
function writePackedDouble(arr, pbf) {
|
|
1977
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1978
|
+
pbf.writeDouble(arr[i2]);
|
|
1979
|
+
}
|
|
1980
|
+
function writePackedBoolean(arr, pbf) {
|
|
1981
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1982
|
+
pbf.writeBoolean(arr[i2]);
|
|
1983
|
+
}
|
|
1984
|
+
function writePackedFixed32(arr, pbf) {
|
|
1985
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1986
|
+
pbf.writeFixed32(arr[i2]);
|
|
1987
|
+
}
|
|
1988
|
+
function writePackedSFixed32(arr, pbf) {
|
|
1989
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1990
|
+
pbf.writeSFixed32(arr[i2]);
|
|
1991
|
+
}
|
|
1992
|
+
function writePackedFixed64(arr, pbf) {
|
|
1993
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1994
|
+
pbf.writeFixed64(arr[i2]);
|
|
1995
|
+
}
|
|
1996
|
+
function writePackedSFixed64(arr, pbf) {
|
|
1997
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1998
|
+
pbf.writeSFixed64(arr[i2]);
|
|
1999
|
+
}
|
|
2000
|
+
function readUInt32(buf, pos) {
|
|
2001
|
+
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216;
|
|
2002
|
+
}
|
|
2003
|
+
function writeInt32(buf, val, pos) {
|
|
2004
|
+
buf[pos] = val;
|
|
2005
|
+
buf[pos + 1] = val >>> 8;
|
|
2006
|
+
buf[pos + 2] = val >>> 16;
|
|
2007
|
+
buf[pos + 3] = val >>> 24;
|
|
2008
|
+
}
|
|
2009
|
+
function readInt32(buf, pos) {
|
|
2010
|
+
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + (buf[pos + 3] << 24);
|
|
2011
|
+
}
|
|
2012
|
+
function readUtf8(buf, pos, end) {
|
|
2013
|
+
var str = "";
|
|
2014
|
+
var i2 = pos;
|
|
2015
|
+
while (i2 < end) {
|
|
2016
|
+
var b0 = buf[i2];
|
|
2017
|
+
var c = null;
|
|
2018
|
+
var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
|
|
2019
|
+
if (i2 + bytesPerSequence > end)
|
|
2020
|
+
break;
|
|
2021
|
+
var b1, b2, b3;
|
|
2022
|
+
if (bytesPerSequence === 1) {
|
|
2023
|
+
if (b0 < 128) {
|
|
2024
|
+
c = b0;
|
|
2025
|
+
}
|
|
2026
|
+
} else if (bytesPerSequence === 2) {
|
|
2027
|
+
b1 = buf[i2 + 1];
|
|
2028
|
+
if ((b1 & 192) === 128) {
|
|
2029
|
+
c = (b0 & 31) << 6 | b1 & 63;
|
|
2030
|
+
if (c <= 127) {
|
|
2031
|
+
c = null;
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
} else if (bytesPerSequence === 3) {
|
|
2035
|
+
b1 = buf[i2 + 1];
|
|
2036
|
+
b2 = buf[i2 + 2];
|
|
2037
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128) {
|
|
2038
|
+
c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
|
|
2039
|
+
if (c <= 2047 || c >= 55296 && c <= 57343) {
|
|
2040
|
+
c = null;
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
} else if (bytesPerSequence === 4) {
|
|
2044
|
+
b1 = buf[i2 + 1];
|
|
2045
|
+
b2 = buf[i2 + 2];
|
|
2046
|
+
b3 = buf[i2 + 3];
|
|
2047
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
|
|
2048
|
+
c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
|
|
2049
|
+
if (c <= 65535 || c >= 1114112) {
|
|
2050
|
+
c = null;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
if (c === null) {
|
|
2055
|
+
c = 65533;
|
|
2056
|
+
bytesPerSequence = 1;
|
|
2057
|
+
} else if (c > 65535) {
|
|
2058
|
+
c -= 65536;
|
|
2059
|
+
str += String.fromCharCode(c >>> 10 & 1023 | 55296);
|
|
2060
|
+
c = 56320 | c & 1023;
|
|
2061
|
+
}
|
|
2062
|
+
str += String.fromCharCode(c);
|
|
2063
|
+
i2 += bytesPerSequence;
|
|
2064
|
+
}
|
|
2065
|
+
return str;
|
|
2066
|
+
}
|
|
2067
|
+
function readUtf8TextDecoder(buf, pos, end) {
|
|
2068
|
+
return utf8TextDecoder.decode(buf.subarray(pos, end));
|
|
2069
|
+
}
|
|
2070
|
+
function writeUtf8(buf, str, pos) {
|
|
2071
|
+
for (var i2 = 0, c, lead; i2 < str.length; i2++) {
|
|
2072
|
+
c = str.charCodeAt(i2);
|
|
2073
|
+
if (c > 55295 && c < 57344) {
|
|
2074
|
+
if (lead) {
|
|
2075
|
+
if (c < 56320) {
|
|
2076
|
+
buf[pos++] = 239;
|
|
2077
|
+
buf[pos++] = 191;
|
|
2078
|
+
buf[pos++] = 189;
|
|
2079
|
+
lead = c;
|
|
2080
|
+
continue;
|
|
2081
|
+
} else {
|
|
2082
|
+
c = lead - 55296 << 10 | c - 56320 | 65536;
|
|
2083
|
+
lead = null;
|
|
2084
|
+
}
|
|
2085
|
+
} else {
|
|
2086
|
+
if (c > 56319 || i2 + 1 === str.length) {
|
|
2087
|
+
buf[pos++] = 239;
|
|
2088
|
+
buf[pos++] = 191;
|
|
2089
|
+
buf[pos++] = 189;
|
|
2090
|
+
} else {
|
|
2091
|
+
lead = c;
|
|
2092
|
+
}
|
|
2093
|
+
continue;
|
|
2094
|
+
}
|
|
2095
|
+
} else if (lead) {
|
|
2096
|
+
buf[pos++] = 239;
|
|
2097
|
+
buf[pos++] = 191;
|
|
2098
|
+
buf[pos++] = 189;
|
|
2099
|
+
lead = null;
|
|
2100
|
+
}
|
|
2101
|
+
if (c < 128) {
|
|
2102
|
+
buf[pos++] = c;
|
|
2103
|
+
} else {
|
|
2104
|
+
if (c < 2048) {
|
|
2105
|
+
buf[pos++] = c >> 6 | 192;
|
|
2106
|
+
} else {
|
|
2107
|
+
if (c < 65536) {
|
|
2108
|
+
buf[pos++] = c >> 12 | 224;
|
|
2109
|
+
} else {
|
|
2110
|
+
buf[pos++] = c >> 18 | 240;
|
|
2111
|
+
buf[pos++] = c >> 12 & 63 | 128;
|
|
2112
|
+
}
|
|
2113
|
+
buf[pos++] = c >> 6 & 63 | 128;
|
|
2114
|
+
}
|
|
2115
|
+
buf[pos++] = c & 63 | 128;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
return pos;
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
});
|
|
2122
|
+
|
|
2123
|
+
// src/lib/parse-mvt.ts
|
|
2124
|
+
function parseMVT(arrayBuffer, options) {
|
|
2125
|
+
options = normalizeOptions(options);
|
|
2126
|
+
const features = [];
|
|
2127
|
+
if (options) {
|
|
2128
|
+
const binary = options.gis.format === "binary";
|
|
2129
|
+
const firstPassData = {
|
|
2130
|
+
pointPositionsCount: 0,
|
|
2131
|
+
pointFeaturesCount: 0,
|
|
2132
|
+
linePositionsCount: 0,
|
|
2133
|
+
linePathsCount: 0,
|
|
2134
|
+
lineFeaturesCount: 0,
|
|
2135
|
+
polygonPositionsCount: 0,
|
|
2136
|
+
polygonObjectsCount: 0,
|
|
2137
|
+
polygonRingsCount: 0,
|
|
2138
|
+
polygonFeaturesCount: 0
|
|
2139
|
+
};
|
|
2140
|
+
if (arrayBuffer.byteLength > 0) {
|
|
2141
|
+
const tile = binary ? new VectorTile2(new import_pbf.default(arrayBuffer)) : new VectorTile(new import_pbf.default(arrayBuffer));
|
|
2142
|
+
const loaderOptions = options.mvt;
|
|
2143
|
+
const selectedLayers = Array.isArray(loaderOptions.layers) ? loaderOptions.layers : Object.keys(tile.layers);
|
|
2144
|
+
selectedLayers.forEach((layerName) => {
|
|
2145
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
2146
|
+
const featureOptions = { ...loaderOptions, layerName };
|
|
2147
|
+
if (!vectorTileLayer) {
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2150
|
+
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2151
|
+
const vectorTileFeature = vectorTileLayer.feature(i2, firstPassData);
|
|
2152
|
+
const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
|
|
2153
|
+
features.push(decodedFeature);
|
|
2154
|
+
}
|
|
2155
|
+
});
|
|
2156
|
+
}
|
|
2157
|
+
if (binary) {
|
|
2158
|
+
const data = featuresToBinary(features, firstPassData);
|
|
2159
|
+
data.byteLength = arrayBuffer.byteLength;
|
|
2160
|
+
return data;
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
return features;
|
|
2164
|
+
}
|
|
2165
|
+
function normalizeOptions(options) {
|
|
2166
|
+
if (options) {
|
|
2167
|
+
options = {
|
|
2168
|
+
...options,
|
|
2169
|
+
mvt: options.mvt || {},
|
|
2170
|
+
gis: options.gis || {}
|
|
2171
|
+
};
|
|
2172
|
+
const wgs84Coordinates = options.coordinates === "wgs84";
|
|
2173
|
+
const { tileIndex } = options;
|
|
2174
|
+
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2175
|
+
if (wgs84Coordinates && !hasTileIndex) {
|
|
2176
|
+
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.");
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
return options;
|
|
2180
|
+
}
|
|
2181
|
+
function getDecodedFeature(feature, options) {
|
|
2182
|
+
const decodedFeature = feature.toGeoJSON(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates);
|
|
2183
|
+
if (options.layerProperty) {
|
|
2184
|
+
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
2185
|
+
}
|
|
2186
|
+
return decodedFeature;
|
|
2187
|
+
}
|
|
2188
|
+
function getDecodedFeatureBinary(feature, options) {
|
|
2189
|
+
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
2190
|
+
if (options.layerProperty) {
|
|
2191
|
+
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
2192
|
+
}
|
|
2193
|
+
return decodedFeature;
|
|
2194
|
+
}
|
|
2195
|
+
function transformToLocalCoordinates(line, feature) {
|
|
2196
|
+
const { extent } = feature;
|
|
2197
|
+
for (let i2 = 0; i2 < line.length; i2++) {
|
|
2198
|
+
const p = line[i2];
|
|
2199
|
+
p[0] /= extent;
|
|
2200
|
+
p[1] /= extent;
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
function transformToLocalCoordinatesBinary(data, feature) {
|
|
2204
|
+
const { extent } = feature;
|
|
2205
|
+
for (let i2 = 0, il = data.length; i2 < il; ++i2) {
|
|
2206
|
+
data[i2] /= extent;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
var import_pbf;
|
|
2210
|
+
var init_parse_mvt = __esm({
|
|
2211
|
+
"src/lib/parse-mvt.ts"() {
|
|
2212
|
+
init_vector_tile();
|
|
2213
|
+
init_vector_tile2();
|
|
2214
|
+
init_features_to_binary();
|
|
2215
|
+
import_pbf = __toModule(require_pbf());
|
|
2216
|
+
}
|
|
2217
|
+
});
|
|
2218
|
+
|
|
2219
|
+
// src/mvt-loader.ts
|
|
2220
|
+
var VERSION, MVTWorkerLoader, MVTLoader;
|
|
2221
|
+
var init_mvt_loader = __esm({
|
|
2222
|
+
"src/mvt-loader.ts"() {
|
|
2223
|
+
init_parse_mvt();
|
|
2224
|
+
VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2225
|
+
MVTWorkerLoader = {
|
|
2226
|
+
name: "Mapbox Vector Tile",
|
|
2227
|
+
id: "mvt",
|
|
2228
|
+
module: "mvt",
|
|
2229
|
+
version: VERSION,
|
|
2230
|
+
extensions: ["mvt", "pbf"],
|
|
2231
|
+
mimeTypes: [
|
|
2232
|
+
"application/vnd.mapbox-vector-tile",
|
|
2233
|
+
"application/x-protobuf"
|
|
2234
|
+
],
|
|
2235
|
+
worker: true,
|
|
2236
|
+
category: "geometry",
|
|
2237
|
+
options: {
|
|
2238
|
+
mvt: {
|
|
2239
|
+
coordinates: "local",
|
|
2240
|
+
layerProperty: "layerName",
|
|
2241
|
+
layers: null,
|
|
2242
|
+
tileIndex: null
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
};
|
|
2246
|
+
MVTLoader = {
|
|
2247
|
+
...MVTWorkerLoader,
|
|
2248
|
+
parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),
|
|
2249
|
+
parseSync: parseMVT,
|
|
2250
|
+
binary: true
|
|
2251
|
+
};
|
|
2252
|
+
}
|
|
2253
|
+
});
|
|
2254
|
+
|
|
2255
|
+
// src/index.ts
|
|
2256
|
+
var src_exports = {};
|
|
2257
|
+
__export(src_exports, {
|
|
2258
|
+
MVTLoader: () => MVTLoader,
|
|
2259
|
+
MVTWorkerLoader: () => MVTWorkerLoader
|
|
2260
|
+
});
|
|
2261
|
+
var init_src = __esm({
|
|
2262
|
+
"src/index.ts"() {
|
|
2263
|
+
init_mvt_loader();
|
|
2264
|
+
}
|
|
2265
|
+
});
|
|
2266
|
+
|
|
2267
|
+
// src/bundle.ts
|
|
2268
|
+
var require_bundle = __commonJS({
|
|
2269
|
+
"src/bundle.ts"(exports, module) {
|
|
2270
|
+
var moduleExports = (init_src(), src_exports);
|
|
2271
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
2272
|
+
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
2273
|
+
}
|
|
2274
|
+
});
|
|
2275
|
+
require_bundle();
|
|
2276
|
+
})();
|
|
2277
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|