@loaders.gl/mvt 4.0.0-alpha.5 → 4.0.0-alpha.7
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.js +2 -2
- package/dist/dist.min.js +1748 -913
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/helpers/binary-util-functions.js +82 -0
- package/dist/es5/helpers/binary-util-functions.js.map +1 -0
- package/dist/es5/helpers/mapbox-util-functions.js +50 -0
- package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/es5/index.js +26 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +168 -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 +62 -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 +28 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
- package/dist/es5/lib/geojson-tiler/clip.js +237 -0
- package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/convert.js +161 -0
- package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/feature.js +62 -0
- package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js +186 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/simplify.js +52 -0
- package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/tile.js +121 -0
- package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/transform.js +50 -0
- package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/wrap.js +122 -0
- package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +184 -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 +62 -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 +28 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/es5/lib/parse-mvt.js +143 -0
- package/dist/es5/lib/parse-mvt.js.map +1 -0
- package/dist/es5/lib/types.js +2 -0
- package/dist/es5/lib/types.js.map +1 -0
- package/dist/es5/mvt-loader.js +58 -0
- package/dist/es5/mvt-loader.js.map +1 -0
- package/dist/es5/workers/mvt-worker.js +6 -0
- package/dist/es5/workers/mvt-worker.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/helpers/binary-util-functions.js +73 -0
- package/dist/esm/helpers/binary-util-functions.js.map +1 -0
- package/dist/esm/helpers/mapbox-util-functions.js +41 -0
- package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/esm/index.js +3 -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/vector-tile-feature.js +136 -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 +47 -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 +19 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
- package/dist/esm/lib/geojson-tiler/clip.js +173 -0
- package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/convert.js +116 -0
- package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/feature.js +35 -0
- package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js +171 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/simplify.js +46 -0
- package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/tile.js +103 -0
- package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/transform.js +32 -0
- package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/wrap.js +67 -0
- package/dist/esm/lib/geojson-tiler/wrap.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 +163 -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 +47 -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 +19 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/esm/lib/parse-mvt.js +138 -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 +29 -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.js +111 -77
- package/dist/helpers/mapbox-util-functions.d.ts +2 -2
- package/dist/helpers/mapbox-util-functions.js +78 -45
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -143
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
- package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
- package/dist/lib/geojson-tiler/clip.d.ts +16 -0
- package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/clip.js +209 -0
- package/dist/lib/geojson-tiler/convert.d.ts +10 -0
- package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/convert.js +134 -0
- package/dist/lib/geojson-tiler/feature.d.ts +3 -0
- package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/feature.js +46 -0
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
- package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
- package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/simplify.js +68 -0
- package/dist/lib/geojson-tiler/tile.d.ts +38 -0
- package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/tile.js +125 -0
- package/dist/lib/geojson-tiler/transform.d.ts +7 -0
- package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/transform.js +43 -0
- package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
- package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/wrap.js +86 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +4 -4
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
- package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
- package/dist/lib/parse-mvt.d.ts +6 -9
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +148 -98
- package/dist/lib/types.d.ts +48 -7
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +2 -2
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +43 -22
- package/dist/mvt-worker.js +903 -829
- package/dist/workers/mvt-worker.js +5 -4
- package/package.json +7 -7
- package/src/helpers/mapbox-util-functions.ts +2 -2
- package/src/index.ts +7 -0
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +6 -1
- package/src/lib/geojson-tiler/LICENSE +19 -0
- package/src/lib/geojson-tiler/clip.ts +248 -0
- package/src/lib/geojson-tiler/convert.ts +158 -0
- package/src/lib/geojson-tiler/feature.ts +45 -0
- package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
- package/src/lib/geojson-tiler/simplify.ts +77 -0
- package/src/lib/geojson-tiler/tile.ts +185 -0
- package/src/lib/geojson-tiler/transform.ts +55 -0
- package/src/lib/geojson-tiler/wrap.ts +108 -0
- package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +4 -4
- package/src/lib/parse-mvt.ts +136 -93
- package/src/lib/types.ts +53 -7
- package/src/mvt-loader.ts +13 -9
- package/dist/bundle.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/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/lib/types.js.map +0 -1
- package/dist/mvt-loader.js.map +0 -1
- package/dist/workers/mvt-worker.js.map +0 -1
- /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
- /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
package/dist/dist.min.js
CHANGED
|
@@ -29,338 +29,66 @@
|
|
|
29
29
|
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
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;
|
|
32
|
+
// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
33
|
+
var init_typeof = __esm({
|
|
34
|
+
"../../node_modules/@babel/runtime/helpers/esm/typeof.js"() {
|
|
76
35
|
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
feature.properties[key] = value;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
|
|
39
|
+
var init_toPrimitive = __esm({
|
|
40
|
+
"../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js"() {
|
|
41
|
+
init_typeof();
|
|
84
42
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
|
|
46
|
+
var init_toPropertyKey = __esm({
|
|
47
|
+
"../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js"() {
|
|
48
|
+
init_typeof();
|
|
49
|
+
init_toPrimitive();
|
|
88
50
|
}
|
|
89
51
|
});
|
|
90
52
|
|
|
91
|
-
//
|
|
92
|
-
var
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
};
|
|
53
|
+
// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
|
|
54
|
+
var init_defineProperty = __esm({
|
|
55
|
+
"../../node_modules/@babel/runtime/helpers/esm/defineProperty.js"() {
|
|
56
|
+
init_toPropertyKey();
|
|
251
57
|
}
|
|
252
58
|
});
|
|
253
59
|
|
|
254
|
-
//
|
|
255
|
-
function
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
else if (tag === 3)
|
|
266
|
-
layer._keys.push(pbf.readString());
|
|
267
|
-
else if (tag === 4)
|
|
268
|
-
layer._values.push(readValueMessage(pbf));
|
|
60
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
|
|
61
|
+
function getPolygonSignedArea(points, options = {}) {
|
|
62
|
+
const {
|
|
63
|
+
start = 0,
|
|
64
|
+
end = points.length
|
|
65
|
+
} = options;
|
|
66
|
+
const dim = options.size || 2;
|
|
67
|
+
let area2 = 0;
|
|
68
|
+
for (let i2 = start, j = end - dim; i2 < end; i2 += dim) {
|
|
69
|
+
area2 += (points[i2] - points[j]) * (points[i2 + 1] + points[j + 1]);
|
|
70
|
+
j = i2;
|
|
269
71
|
}
|
|
72
|
+
return area2 / 2;
|
|
270
73
|
}
|
|
271
|
-
|
|
272
|
-
|
|
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"() {
|
|
74
|
+
var init_polygon_utils = __esm({
|
|
75
|
+
"../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
|
|
348
76
|
}
|
|
349
77
|
});
|
|
350
78
|
|
|
351
79
|
// ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
|
|
352
80
|
var init_polygon = __esm({
|
|
353
81
|
"../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
|
|
82
|
+
init_defineProperty();
|
|
354
83
|
init_polygon_utils();
|
|
355
84
|
}
|
|
356
85
|
});
|
|
357
86
|
|
|
358
87
|
// ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
|
|
359
|
-
function earcut(
|
|
360
|
-
dim = dim || 2;
|
|
88
|
+
function earcut(positions, holeIndices, dim = 2, areas) {
|
|
361
89
|
const hasHoles = holeIndices && holeIndices.length;
|
|
362
|
-
const outerLen = hasHoles ? holeIndices[0] * dim :
|
|
363
|
-
let outerNode = linkedList(
|
|
90
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
|
|
91
|
+
let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0]);
|
|
364
92
|
const triangles = [];
|
|
365
93
|
if (!outerNode || outerNode.next === outerNode.prev)
|
|
366
94
|
return triangles;
|
|
@@ -372,13 +100,13 @@
|
|
|
372
100
|
let x2;
|
|
373
101
|
let y2;
|
|
374
102
|
if (hasHoles)
|
|
375
|
-
outerNode = eliminateHoles(
|
|
376
|
-
if (
|
|
377
|
-
minX = maxX =
|
|
378
|
-
minY = maxY =
|
|
103
|
+
outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
|
|
104
|
+
if (positions.length > 80 * dim) {
|
|
105
|
+
minX = maxX = positions[0];
|
|
106
|
+
minY = maxY = positions[1];
|
|
379
107
|
for (let i2 = dim; i2 < outerLen; i2 += dim) {
|
|
380
|
-
x2 =
|
|
381
|
-
y2 =
|
|
108
|
+
x2 = positions[i2];
|
|
109
|
+
y2 = positions[i2 + 1];
|
|
382
110
|
if (x2 < minX)
|
|
383
111
|
minX = x2;
|
|
384
112
|
if (y2 < minY)
|
|
@@ -875,460 +603,198 @@
|
|
|
875
603
|
}
|
|
876
604
|
});
|
|
877
605
|
|
|
878
|
-
// src/
|
|
879
|
-
function
|
|
880
|
-
const
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
const
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
startIndex = geom.indices[i2] - offset;
|
|
898
|
-
endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
|
|
899
|
-
const shape = geom.data.slice(startIndex, endIndex);
|
|
900
|
-
const area2 = getPolygonSignedArea(shape);
|
|
901
|
-
if (area2 === 0) {
|
|
902
|
-
const before = geom.data.slice(0, startIndex);
|
|
903
|
-
const after = geom.data.slice(endIndex);
|
|
904
|
-
geom.data = before.concat(after);
|
|
905
|
-
offset += endIndex - startIndex;
|
|
906
|
-
continue;
|
|
907
|
-
}
|
|
908
|
-
if (ccw === void 0)
|
|
909
|
-
ccw = area2 < 0;
|
|
910
|
-
if (ccw === area2 < 0) {
|
|
911
|
-
if (polygon.length) {
|
|
912
|
-
areas.push(ringAreas);
|
|
913
|
-
polygons.push(polygon);
|
|
606
|
+
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
607
|
+
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
608
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
609
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
610
|
+
return fillArrays(features, {
|
|
611
|
+
propArrayTypes,
|
|
612
|
+
...geometryInfo
|
|
613
|
+
}, {
|
|
614
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
615
|
+
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
function extractNumericPropTypes(features) {
|
|
619
|
+
const propArrayTypes = {};
|
|
620
|
+
for (const feature of features) {
|
|
621
|
+
if (feature.properties) {
|
|
622
|
+
for (const key in feature.properties) {
|
|
623
|
+
const val = feature.properties[key];
|
|
624
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
914
625
|
}
|
|
915
|
-
polygon = [startIndex];
|
|
916
|
-
ringAreas = [area2];
|
|
917
|
-
} else {
|
|
918
|
-
ringAreas.push(area2);
|
|
919
|
-
polygon.push(startIndex);
|
|
920
626
|
}
|
|
921
627
|
}
|
|
922
|
-
|
|
923
|
-
areas.push(ringAreas);
|
|
924
|
-
if (polygon.length)
|
|
925
|
-
polygons.push(polygon);
|
|
926
|
-
return { type, areas, indices: polygons, data: geom.data };
|
|
628
|
+
return propArrayTypes;
|
|
927
629
|
}
|
|
928
|
-
function
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
630
|
+
function fillArrays(features, geometryInfo, options) {
|
|
631
|
+
const {
|
|
632
|
+
pointPositionsCount,
|
|
633
|
+
pointFeaturesCount,
|
|
634
|
+
linePositionsCount,
|
|
635
|
+
linePathsCount,
|
|
636
|
+
lineFeaturesCount,
|
|
637
|
+
polygonPositionsCount,
|
|
638
|
+
polygonObjectsCount,
|
|
639
|
+
polygonRingsCount,
|
|
640
|
+
polygonFeaturesCount,
|
|
641
|
+
propArrayTypes,
|
|
642
|
+
coordLength
|
|
643
|
+
} = geometryInfo;
|
|
644
|
+
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
645
|
+
const hasGlobalId = features[0] && "id" in features[0];
|
|
646
|
+
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
647
|
+
const points = {
|
|
648
|
+
type: "Point",
|
|
649
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
650
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
651
|
+
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
652
|
+
numericProps: {},
|
|
653
|
+
properties: [],
|
|
654
|
+
fields: []
|
|
655
|
+
};
|
|
656
|
+
const lines = {
|
|
657
|
+
type: "LineString",
|
|
658
|
+
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
659
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
660
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
661
|
+
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
662
|
+
numericProps: {},
|
|
663
|
+
properties: [],
|
|
664
|
+
fields: []
|
|
665
|
+
};
|
|
666
|
+
const polygons = {
|
|
667
|
+
type: "Polygon",
|
|
668
|
+
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
669
|
+
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
670
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
671
|
+
triangles: [],
|
|
672
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
673
|
+
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
674
|
+
numericProps: {},
|
|
675
|
+
properties: [],
|
|
676
|
+
fields: []
|
|
677
|
+
};
|
|
678
|
+
for (const object of [points, lines, polygons]) {
|
|
679
|
+
for (const propName of numericPropKeys) {
|
|
680
|
+
const T = propArrayTypes[propName];
|
|
681
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
682
|
+
}
|
|
933
683
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
684
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
685
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
686
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
687
|
+
const indexMap = {
|
|
688
|
+
pointPosition: 0,
|
|
689
|
+
pointFeature: 0,
|
|
690
|
+
linePosition: 0,
|
|
691
|
+
linePath: 0,
|
|
692
|
+
lineFeature: 0,
|
|
693
|
+
polygonPosition: 0,
|
|
694
|
+
polygonObject: 0,
|
|
695
|
+
polygonRing: 0,
|
|
696
|
+
polygonFeature: 0,
|
|
697
|
+
feature: 0
|
|
698
|
+
};
|
|
699
|
+
for (const feature of features) {
|
|
700
|
+
const geometry = feature.geometry;
|
|
701
|
+
const properties = feature.properties || {};
|
|
702
|
+
switch (geometry.type) {
|
|
703
|
+
case "Point":
|
|
704
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
705
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
706
|
+
if (hasGlobalId) {
|
|
707
|
+
points.fields.push({ id: feature.id });
|
|
708
|
+
}
|
|
709
|
+
indexMap.pointFeature++;
|
|
710
|
+
break;
|
|
711
|
+
case "LineString":
|
|
712
|
+
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
713
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
714
|
+
if (hasGlobalId) {
|
|
715
|
+
lines.fields.push({ id: feature.id });
|
|
716
|
+
}
|
|
717
|
+
indexMap.lineFeature++;
|
|
718
|
+
break;
|
|
719
|
+
case "Polygon":
|
|
720
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
721
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
722
|
+
if (hasGlobalId) {
|
|
723
|
+
polygons.fields.push({ id: feature.id });
|
|
724
|
+
}
|
|
725
|
+
indexMap.polygonFeature++;
|
|
726
|
+
break;
|
|
727
|
+
default:
|
|
728
|
+
throw new Error("Invalid geometry type");
|
|
729
|
+
}
|
|
730
|
+
indexMap.feature++;
|
|
945
731
|
}
|
|
732
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
946
733
|
}
|
|
947
|
-
function
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
}
|
|
955
|
-
var init_binary_util_functions = __esm({
|
|
956
|
-
"src/helpers/binary-util-functions.ts"() {
|
|
957
|
-
init_esm();
|
|
958
|
-
}
|
|
959
|
-
});
|
|
960
|
-
|
|
961
|
-
// src/lib/binary-vector-tile/vector-tile-feature.ts
|
|
962
|
-
var endPos, cmd, cmdLen, length, x, y, i, VectorTileFeature2;
|
|
963
|
-
var init_vector_tile_feature2 = __esm({
|
|
964
|
-
"src/lib/binary-vector-tile/vector-tile-feature.ts"() {
|
|
965
|
-
init_binary_util_functions();
|
|
966
|
-
VectorTileFeature2 = class {
|
|
967
|
-
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
968
|
-
this.properties = {};
|
|
969
|
-
this.extent = extent;
|
|
970
|
-
this.type = 0;
|
|
971
|
-
this.id = null;
|
|
972
|
-
this._pbf = pbf;
|
|
973
|
-
this._geometry = -1;
|
|
974
|
-
this._keys = keys;
|
|
975
|
-
this._values = values;
|
|
976
|
-
this._geometryInfo = geometryInfo;
|
|
977
|
-
pbf.readFields(readFeature2, this, end);
|
|
978
|
-
}
|
|
979
|
-
loadGeometry() {
|
|
980
|
-
const pbf = this._pbf;
|
|
981
|
-
pbf.pos = this._geometry;
|
|
982
|
-
endPos = pbf.readVarint() + pbf.pos;
|
|
983
|
-
cmd = 1;
|
|
984
|
-
length = 0;
|
|
985
|
-
x = 0;
|
|
986
|
-
y = 0;
|
|
987
|
-
i = 0;
|
|
988
|
-
const indices = [];
|
|
989
|
-
const data = [];
|
|
990
|
-
while (pbf.pos < endPos) {
|
|
991
|
-
if (length <= 0) {
|
|
992
|
-
cmdLen = pbf.readVarint();
|
|
993
|
-
cmd = cmdLen & 7;
|
|
994
|
-
length = cmdLen >> 3;
|
|
995
|
-
}
|
|
996
|
-
length--;
|
|
997
|
-
if (cmd === 1 || cmd === 2) {
|
|
998
|
-
x += pbf.readSVarint();
|
|
999
|
-
y += pbf.readSVarint();
|
|
1000
|
-
if (cmd === 1) {
|
|
1001
|
-
indices.push(i);
|
|
1002
|
-
}
|
|
1003
|
-
data.push(x, y);
|
|
1004
|
-
i += 2;
|
|
1005
|
-
} else if (cmd === 7) {
|
|
1006
|
-
if (i > 0) {
|
|
1007
|
-
const start = indices[indices.length - 1];
|
|
1008
|
-
data.push(data[start], data[start + 1]);
|
|
1009
|
-
i += 2;
|
|
1010
|
-
}
|
|
1011
|
-
} else {
|
|
1012
|
-
throw new Error(`unknown command ${cmd}`);
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
return { data, indices };
|
|
1016
|
-
}
|
|
1017
|
-
_toBinaryCoordinates(transform) {
|
|
1018
|
-
const geom = this.loadGeometry();
|
|
1019
|
-
let geometry;
|
|
1020
|
-
transform(geom.data, this);
|
|
1021
|
-
const coordLength = 2;
|
|
1022
|
-
switch (this.type) {
|
|
1023
|
-
case 1:
|
|
1024
|
-
this._geometryInfo.pointFeaturesCount++;
|
|
1025
|
-
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
1026
|
-
geometry = { type: "Point", ...geom };
|
|
1027
|
-
break;
|
|
1028
|
-
case 2:
|
|
1029
|
-
this._geometryInfo.lineFeaturesCount++;
|
|
1030
|
-
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
1031
|
-
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
1032
|
-
geometry = { type: "LineString", ...geom };
|
|
1033
|
-
break;
|
|
1034
|
-
case 3:
|
|
1035
|
-
geometry = classifyRings2(geom);
|
|
1036
|
-
this._geometryInfo.polygonFeaturesCount++;
|
|
1037
|
-
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
1038
|
-
for (const indices of geometry.indices) {
|
|
1039
|
-
this._geometryInfo.polygonRingsCount += indices.length;
|
|
1040
|
-
}
|
|
1041
|
-
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
1042
|
-
break;
|
|
1043
|
-
default:
|
|
1044
|
-
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
1045
|
-
}
|
|
1046
|
-
const result = { type: "Feature", geometry, properties: this.properties };
|
|
1047
|
-
if (this.id !== null) {
|
|
1048
|
-
result.id = this.id;
|
|
1049
|
-
}
|
|
1050
|
-
return result;
|
|
1051
|
-
}
|
|
1052
|
-
toBinaryCoordinates(options) {
|
|
1053
|
-
if (typeof options === "function") {
|
|
1054
|
-
return this._toBinaryCoordinates(options);
|
|
1055
|
-
}
|
|
1056
|
-
return this._toBinaryCoordinates(project);
|
|
1057
|
-
}
|
|
1058
|
-
};
|
|
1059
|
-
}
|
|
1060
|
-
});
|
|
1061
|
-
|
|
1062
|
-
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
1063
|
-
function readLayer2(tag, layer, pbf) {
|
|
1064
|
-
if (layer && pbf) {
|
|
1065
|
-
if (tag === 15)
|
|
1066
|
-
layer.version = pbf.readVarint();
|
|
1067
|
-
else if (tag === 1)
|
|
1068
|
-
layer.name = pbf.readString();
|
|
1069
|
-
else if (tag === 5)
|
|
1070
|
-
layer.extent = pbf.readVarint();
|
|
1071
|
-
else if (tag === 2)
|
|
1072
|
-
layer._features.push(pbf.pos);
|
|
1073
|
-
else if (tag === 3)
|
|
1074
|
-
layer._keys.push(pbf.readString());
|
|
1075
|
-
else if (tag === 4)
|
|
1076
|
-
layer._values.push(readValueMessage2(pbf));
|
|
1077
|
-
}
|
|
734
|
+
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
735
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
736
|
+
const nPositions = geometry.data.length / coordLength;
|
|
737
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
738
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
739
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
740
|
+
indexMap.pointPosition += nPositions;
|
|
1078
741
|
}
|
|
1079
|
-
function
|
|
1080
|
-
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
742
|
+
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
743
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
744
|
+
const nPositions = geometry.data.length / coordLength;
|
|
745
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
746
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
747
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
748
|
+
for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
|
|
749
|
+
const start = geometry.indices[i2];
|
|
750
|
+
const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
|
|
751
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
752
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
1085
753
|
}
|
|
1086
|
-
return value;
|
|
1087
754
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
feature(i2, geometryInfo) {
|
|
1106
|
-
if (i2 < 0 || i2 >= this._features.length) {
|
|
1107
|
-
throw new Error("feature index out of bounds");
|
|
1108
|
-
}
|
|
1109
|
-
this._pbf.pos = this._features[i2];
|
|
1110
|
-
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1111
|
-
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
1112
|
-
}
|
|
1113
|
-
};
|
|
1114
|
-
}
|
|
1115
|
-
});
|
|
1116
|
-
|
|
1117
|
-
// src/lib/binary-vector-tile/vector-tile.ts
|
|
1118
|
-
function readTile2(tag, layers, pbf) {
|
|
1119
|
-
if (tag === 3) {
|
|
1120
|
-
if (pbf) {
|
|
1121
|
-
const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
|
|
1122
|
-
if (layer.length && layers) {
|
|
1123
|
-
layers[layer.name] = layer;
|
|
1124
|
-
}
|
|
755
|
+
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
756
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
757
|
+
const nPositions = geometry.data.length / coordLength;
|
|
758
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
759
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
760
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
761
|
+
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
762
|
+
const startPosition = indexMap.polygonPosition;
|
|
763
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
764
|
+
const areas = geometry.areas[l];
|
|
765
|
+
const indices = geometry.indices[l];
|
|
766
|
+
const nextIndices = geometry.indices[l + 1];
|
|
767
|
+
for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
|
|
768
|
+
const start = indices[i2];
|
|
769
|
+
const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
|
|
770
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
771
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
1125
772
|
}
|
|
773
|
+
const endPosition = indexMap.polygonPosition;
|
|
774
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
1126
775
|
}
|
|
1127
776
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
777
|
+
function triangulatePolygon(polygons, areas, indices, {
|
|
778
|
+
startPosition,
|
|
779
|
+
endPosition,
|
|
780
|
+
coordLength
|
|
781
|
+
}) {
|
|
782
|
+
const start = startPosition * coordLength;
|
|
783
|
+
const end = endPosition * coordLength;
|
|
784
|
+
const polygonPositions = polygons.positions.subarray(start, end);
|
|
785
|
+
const offset = indices[0];
|
|
786
|
+
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
787
|
+
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
788
|
+
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
789
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
1137
790
|
}
|
|
1138
|
-
});
|
|
1139
|
-
|
|
1140
|
-
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1141
|
-
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1142
|
-
const propArrayTypes = extractNumericPropTypes(features);
|
|
1143
|
-
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1144
|
-
return fillArrays(features, {
|
|
1145
|
-
propArrayTypes,
|
|
1146
|
-
...geometryInfo
|
|
1147
|
-
}, {
|
|
1148
|
-
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1149
|
-
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1150
|
-
});
|
|
1151
791
|
}
|
|
1152
|
-
function
|
|
1153
|
-
const
|
|
1154
|
-
for (const
|
|
1155
|
-
|
|
1156
|
-
for (const key in feature.properties) {
|
|
1157
|
-
const val = feature.properties[key];
|
|
1158
|
-
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
792
|
+
function wrapProps(obj, size) {
|
|
793
|
+
const returnObj = {};
|
|
794
|
+
for (const key in obj) {
|
|
795
|
+
returnObj[key] = { value: obj[key], size };
|
|
1161
796
|
}
|
|
1162
|
-
return
|
|
1163
|
-
}
|
|
1164
|
-
function fillArrays(features, geometryInfo, options) {
|
|
1165
|
-
const {
|
|
1166
|
-
pointPositionsCount,
|
|
1167
|
-
pointFeaturesCount,
|
|
1168
|
-
linePositionsCount,
|
|
1169
|
-
linePathsCount,
|
|
1170
|
-
lineFeaturesCount,
|
|
1171
|
-
polygonPositionsCount,
|
|
1172
|
-
polygonObjectsCount,
|
|
1173
|
-
polygonRingsCount,
|
|
1174
|
-
polygonFeaturesCount,
|
|
1175
|
-
propArrayTypes,
|
|
1176
|
-
coordLength
|
|
1177
|
-
} = geometryInfo;
|
|
1178
|
-
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
1179
|
-
const hasGlobalId = features[0] && "id" in features[0];
|
|
1180
|
-
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1181
|
-
const points = {
|
|
1182
|
-
type: "Point",
|
|
1183
|
-
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1184
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1185
|
-
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1186
|
-
numericProps: {},
|
|
1187
|
-
properties: [],
|
|
1188
|
-
fields: []
|
|
1189
|
-
};
|
|
1190
|
-
const lines = {
|
|
1191
|
-
type: "LineString",
|
|
1192
|
-
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
1193
|
-
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
1194
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
1195
|
-
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
1196
|
-
numericProps: {},
|
|
1197
|
-
properties: [],
|
|
1198
|
-
fields: []
|
|
1199
|
-
};
|
|
1200
|
-
const polygons = {
|
|
1201
|
-
type: "Polygon",
|
|
1202
|
-
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1203
|
-
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1204
|
-
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
1205
|
-
triangles: [],
|
|
1206
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1207
|
-
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1208
|
-
numericProps: {},
|
|
1209
|
-
properties: [],
|
|
1210
|
-
fields: []
|
|
1211
|
-
};
|
|
1212
|
-
for (const object of [points, lines, polygons]) {
|
|
1213
|
-
for (const propName of numericPropKeys) {
|
|
1214
|
-
const T = propArrayTypes[propName];
|
|
1215
|
-
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
1219
|
-
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
1220
|
-
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
1221
|
-
const indexMap = {
|
|
1222
|
-
pointPosition: 0,
|
|
1223
|
-
pointFeature: 0,
|
|
1224
|
-
linePosition: 0,
|
|
1225
|
-
linePath: 0,
|
|
1226
|
-
lineFeature: 0,
|
|
1227
|
-
polygonPosition: 0,
|
|
1228
|
-
polygonObject: 0,
|
|
1229
|
-
polygonRing: 0,
|
|
1230
|
-
polygonFeature: 0,
|
|
1231
|
-
feature: 0
|
|
1232
|
-
};
|
|
1233
|
-
for (const feature of features) {
|
|
1234
|
-
const geometry = feature.geometry;
|
|
1235
|
-
const properties = feature.properties || {};
|
|
1236
|
-
switch (geometry.type) {
|
|
1237
|
-
case "Point":
|
|
1238
|
-
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1239
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1240
|
-
if (hasGlobalId) {
|
|
1241
|
-
points.fields.push({ id: feature.id });
|
|
1242
|
-
}
|
|
1243
|
-
indexMap.pointFeature++;
|
|
1244
|
-
break;
|
|
1245
|
-
case "LineString":
|
|
1246
|
-
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1247
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1248
|
-
if (hasGlobalId) {
|
|
1249
|
-
lines.fields.push({ id: feature.id });
|
|
1250
|
-
}
|
|
1251
|
-
indexMap.lineFeature++;
|
|
1252
|
-
break;
|
|
1253
|
-
case "Polygon":
|
|
1254
|
-
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1255
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1256
|
-
if (hasGlobalId) {
|
|
1257
|
-
polygons.fields.push({ id: feature.id });
|
|
1258
|
-
}
|
|
1259
|
-
indexMap.polygonFeature++;
|
|
1260
|
-
break;
|
|
1261
|
-
default:
|
|
1262
|
-
throw new Error("Invalid geometry type");
|
|
1263
|
-
}
|
|
1264
|
-
indexMap.feature++;
|
|
1265
|
-
}
|
|
1266
|
-
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
1267
|
-
}
|
|
1268
|
-
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
1269
|
-
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
1270
|
-
const nPositions = geometry.data.length / coordLength;
|
|
1271
|
-
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
1272
|
-
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1273
|
-
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1274
|
-
indexMap.pointPosition += nPositions;
|
|
1275
|
-
}
|
|
1276
|
-
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1277
|
-
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1278
|
-
const nPositions = geometry.data.length / coordLength;
|
|
1279
|
-
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1280
|
-
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1281
|
-
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1282
|
-
for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
|
|
1283
|
-
const start = geometry.indices[i2];
|
|
1284
|
-
const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
|
|
1285
|
-
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1286
|
-
indexMap.linePosition += (end - start) / coordLength;
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
1290
|
-
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
1291
|
-
const nPositions = geometry.data.length / coordLength;
|
|
1292
|
-
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
1293
|
-
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1294
|
-
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1295
|
-
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
1296
|
-
const startPosition = indexMap.polygonPosition;
|
|
1297
|
-
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
1298
|
-
const areas = geometry.areas[l];
|
|
1299
|
-
const indices = geometry.indices[l];
|
|
1300
|
-
const nextIndices = geometry.indices[l + 1];
|
|
1301
|
-
for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
|
|
1302
|
-
const start = indices[i2];
|
|
1303
|
-
const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
|
|
1304
|
-
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
1305
|
-
indexMap.polygonPosition += (end - start) / coordLength;
|
|
1306
|
-
}
|
|
1307
|
-
const endPosition = indexMap.polygonPosition;
|
|
1308
|
-
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
function triangulatePolygon(polygons, areas, indices, {
|
|
1312
|
-
startPosition,
|
|
1313
|
-
endPosition,
|
|
1314
|
-
coordLength
|
|
1315
|
-
}) {
|
|
1316
|
-
const start = startPosition * coordLength;
|
|
1317
|
-
const end = endPosition * coordLength;
|
|
1318
|
-
const polygonPositions = polygons.positions.subarray(start, end);
|
|
1319
|
-
const offset = indices[0];
|
|
1320
|
-
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
1321
|
-
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
1322
|
-
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
1323
|
-
polygons.triangles.push(startPosition + triangles[t]);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
function wrapProps(obj, size) {
|
|
1327
|
-
const returnObj = {};
|
|
1328
|
-
for (const key in obj) {
|
|
1329
|
-
returnObj[key] = { value: obj[key], size };
|
|
1330
|
-
}
|
|
1331
|
-
return returnObj;
|
|
797
|
+
return returnObj;
|
|
1332
798
|
}
|
|
1333
799
|
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1334
800
|
return {
|
|
@@ -2020,187 +1486,788 @@
|
|
|
2020
1486
|
function readInt32(buf, pos) {
|
|
2021
1487
|
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + (buf[pos + 3] << 24);
|
|
2022
1488
|
}
|
|
2023
|
-
function readUtf8(buf, pos, end) {
|
|
2024
|
-
var str = "";
|
|
2025
|
-
var i2 = pos;
|
|
2026
|
-
while (i2 < end) {
|
|
2027
|
-
var b0 = buf[i2];
|
|
2028
|
-
var c = null;
|
|
2029
|
-
var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
|
|
2030
|
-
if (i2 + bytesPerSequence > end)
|
|
2031
|
-
break;
|
|
2032
|
-
var b1, b2, b3;
|
|
2033
|
-
if (bytesPerSequence === 1) {
|
|
2034
|
-
if (b0 < 128) {
|
|
2035
|
-
c = b0;
|
|
1489
|
+
function readUtf8(buf, pos, end) {
|
|
1490
|
+
var str = "";
|
|
1491
|
+
var i2 = pos;
|
|
1492
|
+
while (i2 < end) {
|
|
1493
|
+
var b0 = buf[i2];
|
|
1494
|
+
var c = null;
|
|
1495
|
+
var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
|
|
1496
|
+
if (i2 + bytesPerSequence > end)
|
|
1497
|
+
break;
|
|
1498
|
+
var b1, b2, b3;
|
|
1499
|
+
if (bytesPerSequence === 1) {
|
|
1500
|
+
if (b0 < 128) {
|
|
1501
|
+
c = b0;
|
|
1502
|
+
}
|
|
1503
|
+
} else if (bytesPerSequence === 2) {
|
|
1504
|
+
b1 = buf[i2 + 1];
|
|
1505
|
+
if ((b1 & 192) === 128) {
|
|
1506
|
+
c = (b0 & 31) << 6 | b1 & 63;
|
|
1507
|
+
if (c <= 127) {
|
|
1508
|
+
c = null;
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
} else if (bytesPerSequence === 3) {
|
|
1512
|
+
b1 = buf[i2 + 1];
|
|
1513
|
+
b2 = buf[i2 + 2];
|
|
1514
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128) {
|
|
1515
|
+
c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
|
|
1516
|
+
if (c <= 2047 || c >= 55296 && c <= 57343) {
|
|
1517
|
+
c = null;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
} else if (bytesPerSequence === 4) {
|
|
1521
|
+
b1 = buf[i2 + 1];
|
|
1522
|
+
b2 = buf[i2 + 2];
|
|
1523
|
+
b3 = buf[i2 + 3];
|
|
1524
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
|
|
1525
|
+
c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
|
|
1526
|
+
if (c <= 65535 || c >= 1114112) {
|
|
1527
|
+
c = null;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
if (c === null) {
|
|
1532
|
+
c = 65533;
|
|
1533
|
+
bytesPerSequence = 1;
|
|
1534
|
+
} else if (c > 65535) {
|
|
1535
|
+
c -= 65536;
|
|
1536
|
+
str += String.fromCharCode(c >>> 10 & 1023 | 55296);
|
|
1537
|
+
c = 56320 | c & 1023;
|
|
1538
|
+
}
|
|
1539
|
+
str += String.fromCharCode(c);
|
|
1540
|
+
i2 += bytesPerSequence;
|
|
1541
|
+
}
|
|
1542
|
+
return str;
|
|
1543
|
+
}
|
|
1544
|
+
function readUtf8TextDecoder(buf, pos, end) {
|
|
1545
|
+
return utf8TextDecoder.decode(buf.subarray(pos, end));
|
|
1546
|
+
}
|
|
1547
|
+
function writeUtf8(buf, str, pos) {
|
|
1548
|
+
for (var i2 = 0, c, lead; i2 < str.length; i2++) {
|
|
1549
|
+
c = str.charCodeAt(i2);
|
|
1550
|
+
if (c > 55295 && c < 57344) {
|
|
1551
|
+
if (lead) {
|
|
1552
|
+
if (c < 56320) {
|
|
1553
|
+
buf[pos++] = 239;
|
|
1554
|
+
buf[pos++] = 191;
|
|
1555
|
+
buf[pos++] = 189;
|
|
1556
|
+
lead = c;
|
|
1557
|
+
continue;
|
|
1558
|
+
} else {
|
|
1559
|
+
c = lead - 55296 << 10 | c - 56320 | 65536;
|
|
1560
|
+
lead = null;
|
|
1561
|
+
}
|
|
1562
|
+
} else {
|
|
1563
|
+
if (c > 56319 || i2 + 1 === str.length) {
|
|
1564
|
+
buf[pos++] = 239;
|
|
1565
|
+
buf[pos++] = 191;
|
|
1566
|
+
buf[pos++] = 189;
|
|
1567
|
+
} else {
|
|
1568
|
+
lead = c;
|
|
1569
|
+
}
|
|
1570
|
+
continue;
|
|
1571
|
+
}
|
|
1572
|
+
} else if (lead) {
|
|
1573
|
+
buf[pos++] = 239;
|
|
1574
|
+
buf[pos++] = 191;
|
|
1575
|
+
buf[pos++] = 189;
|
|
1576
|
+
lead = null;
|
|
1577
|
+
}
|
|
1578
|
+
if (c < 128) {
|
|
1579
|
+
buf[pos++] = c;
|
|
1580
|
+
} else {
|
|
1581
|
+
if (c < 2048) {
|
|
1582
|
+
buf[pos++] = c >> 6 | 192;
|
|
1583
|
+
} else {
|
|
1584
|
+
if (c < 65536) {
|
|
1585
|
+
buf[pos++] = c >> 12 | 224;
|
|
1586
|
+
} else {
|
|
1587
|
+
buf[pos++] = c >> 18 | 240;
|
|
1588
|
+
buf[pos++] = c >> 12 & 63 | 128;
|
|
1589
|
+
}
|
|
1590
|
+
buf[pos++] = c >> 6 & 63 | 128;
|
|
1591
|
+
}
|
|
1592
|
+
buf[pos++] = c & 63 | 128;
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
return pos;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
});
|
|
1599
|
+
|
|
1600
|
+
// src/helpers/mapbox-util-functions.ts
|
|
1601
|
+
function classifyRings(rings) {
|
|
1602
|
+
const len = rings.length;
|
|
1603
|
+
if (len <= 1)
|
|
1604
|
+
return [rings];
|
|
1605
|
+
const polygons = [];
|
|
1606
|
+
let polygon;
|
|
1607
|
+
let ccw;
|
|
1608
|
+
for (let i2 = 0; i2 < len; i2++) {
|
|
1609
|
+
const area2 = signedArea(rings[i2]);
|
|
1610
|
+
if (area2 === 0)
|
|
1611
|
+
continue;
|
|
1612
|
+
if (ccw === void 0)
|
|
1613
|
+
ccw = area2 < 0;
|
|
1614
|
+
if (ccw === area2 < 0) {
|
|
1615
|
+
if (polygon)
|
|
1616
|
+
polygons.push(polygon);
|
|
1617
|
+
polygon = [rings[i2]];
|
|
1618
|
+
} else if (polygon)
|
|
1619
|
+
polygon.push(rings[i2]);
|
|
1620
|
+
}
|
|
1621
|
+
if (polygon)
|
|
1622
|
+
polygons.push(polygon);
|
|
1623
|
+
return polygons;
|
|
1624
|
+
}
|
|
1625
|
+
function signedArea(ring) {
|
|
1626
|
+
let sum = 0;
|
|
1627
|
+
for (let i2 = 0, j = ring.length - 1, p1, p2; i2 < ring.length; j = i2++) {
|
|
1628
|
+
p1 = ring[i2];
|
|
1629
|
+
p2 = ring[j];
|
|
1630
|
+
sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
|
|
1631
|
+
}
|
|
1632
|
+
return sum;
|
|
1633
|
+
}
|
|
1634
|
+
function readFeature(tag, feature, pbf) {
|
|
1635
|
+
if (feature && pbf) {
|
|
1636
|
+
if (tag === 1)
|
|
1637
|
+
feature.id = pbf.readVarint();
|
|
1638
|
+
else if (tag === 2)
|
|
1639
|
+
readTag(pbf, feature);
|
|
1640
|
+
else if (tag === 3)
|
|
1641
|
+
feature.type = pbf.readVarint();
|
|
1642
|
+
else if (tag === 4)
|
|
1643
|
+
feature._geometry = pbf.pos;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
function readTag(pbf, feature) {
|
|
1647
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1648
|
+
while (pbf.pos < end) {
|
|
1649
|
+
const key = feature._keys[pbf.readVarint()];
|
|
1650
|
+
const value = feature._values[pbf.readVarint()];
|
|
1651
|
+
feature.properties[key] = value;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
var init_mapbox_util_functions = __esm({
|
|
1655
|
+
"src/helpers/mapbox-util-functions.ts"() {
|
|
1656
|
+
}
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1659
|
+
// src/lib/mapbox-vector-tile/vector-tile-feature.ts
|
|
1660
|
+
var VectorTileFeature;
|
|
1661
|
+
var init_vector_tile_feature = __esm({
|
|
1662
|
+
"src/lib/mapbox-vector-tile/vector-tile-feature.ts"() {
|
|
1663
|
+
init_mapbox_util_functions();
|
|
1664
|
+
VectorTileFeature = class {
|
|
1665
|
+
static get types() {
|
|
1666
|
+
return ["Unknown", "Point", "LineString", "Polygon"];
|
|
1667
|
+
}
|
|
1668
|
+
constructor(pbf, end, extent, keys, values) {
|
|
1669
|
+
this.properties = {};
|
|
1670
|
+
this.extent = extent;
|
|
1671
|
+
this.type = 0;
|
|
1672
|
+
this.id = null;
|
|
1673
|
+
this._pbf = pbf;
|
|
1674
|
+
this._geometry = -1;
|
|
1675
|
+
this._keys = keys;
|
|
1676
|
+
this._values = values;
|
|
1677
|
+
pbf.readFields(readFeature, this, end);
|
|
1678
|
+
}
|
|
1679
|
+
loadGeometry() {
|
|
1680
|
+
const pbf = this._pbf;
|
|
1681
|
+
pbf.pos = this._geometry;
|
|
1682
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1683
|
+
let cmd2 = 1;
|
|
1684
|
+
let length2 = 0;
|
|
1685
|
+
let x2 = 0;
|
|
1686
|
+
let y2 = 0;
|
|
1687
|
+
const lines = [];
|
|
1688
|
+
let line;
|
|
1689
|
+
while (pbf.pos < end) {
|
|
1690
|
+
if (length2 <= 0) {
|
|
1691
|
+
const cmdLen2 = pbf.readVarint();
|
|
1692
|
+
cmd2 = cmdLen2 & 7;
|
|
1693
|
+
length2 = cmdLen2 >> 3;
|
|
1694
|
+
}
|
|
1695
|
+
length2--;
|
|
1696
|
+
if (cmd2 === 1 || cmd2 === 2) {
|
|
1697
|
+
x2 += pbf.readSVarint();
|
|
1698
|
+
y2 += pbf.readSVarint();
|
|
1699
|
+
if (cmd2 === 1) {
|
|
1700
|
+
if (line)
|
|
1701
|
+
lines.push(line);
|
|
1702
|
+
line = [];
|
|
1703
|
+
}
|
|
1704
|
+
if (line)
|
|
1705
|
+
line.push([x2, y2]);
|
|
1706
|
+
} else if (cmd2 === 7) {
|
|
1707
|
+
if (line) {
|
|
1708
|
+
line.push(line[0].slice());
|
|
1709
|
+
}
|
|
1710
|
+
} else {
|
|
1711
|
+
throw new Error(`unknown command ${cmd2}`);
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
if (line)
|
|
1715
|
+
lines.push(line);
|
|
1716
|
+
return lines;
|
|
1717
|
+
}
|
|
1718
|
+
bbox() {
|
|
1719
|
+
const pbf = this._pbf;
|
|
1720
|
+
pbf.pos = this._geometry;
|
|
1721
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1722
|
+
let cmd2 = 1;
|
|
1723
|
+
let length2 = 0;
|
|
1724
|
+
let x2 = 0;
|
|
1725
|
+
let y2 = 0;
|
|
1726
|
+
let x1 = Infinity;
|
|
1727
|
+
let x22 = -Infinity;
|
|
1728
|
+
let y1 = Infinity;
|
|
1729
|
+
let y22 = -Infinity;
|
|
1730
|
+
while (pbf.pos < end) {
|
|
1731
|
+
if (length2 <= 0) {
|
|
1732
|
+
const cmdLen2 = pbf.readVarint();
|
|
1733
|
+
cmd2 = cmdLen2 & 7;
|
|
1734
|
+
length2 = cmdLen2 >> 3;
|
|
1735
|
+
}
|
|
1736
|
+
length2--;
|
|
1737
|
+
if (cmd2 === 1 || cmd2 === 2) {
|
|
1738
|
+
x2 += pbf.readSVarint();
|
|
1739
|
+
y2 += pbf.readSVarint();
|
|
1740
|
+
if (x2 < x1)
|
|
1741
|
+
x1 = x2;
|
|
1742
|
+
if (x2 > x22)
|
|
1743
|
+
x22 = x2;
|
|
1744
|
+
if (y2 < y1)
|
|
1745
|
+
y1 = y2;
|
|
1746
|
+
if (y2 > y22)
|
|
1747
|
+
y22 = y2;
|
|
1748
|
+
} else if (cmd2 !== 7) {
|
|
1749
|
+
throw new Error(`unknown command ${cmd2}`);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
return [x1, y1, x22, y22];
|
|
1753
|
+
}
|
|
1754
|
+
_toGeoJSON(transform) {
|
|
1755
|
+
let coords = this.loadGeometry();
|
|
1756
|
+
let type = VectorTileFeature.types[this.type];
|
|
1757
|
+
let i2;
|
|
1758
|
+
let j;
|
|
1759
|
+
switch (this.type) {
|
|
1760
|
+
case 1:
|
|
1761
|
+
const points = [];
|
|
1762
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1763
|
+
points[i2] = coords[i2][0];
|
|
1764
|
+
}
|
|
1765
|
+
coords = points;
|
|
1766
|
+
transform(coords, this);
|
|
1767
|
+
break;
|
|
1768
|
+
case 2:
|
|
1769
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1770
|
+
transform(coords[i2], this);
|
|
1771
|
+
}
|
|
1772
|
+
break;
|
|
1773
|
+
case 3:
|
|
1774
|
+
coords = classifyRings(coords);
|
|
1775
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1776
|
+
for (j = 0; j < coords[i2].length; j++) {
|
|
1777
|
+
transform(coords[i2][j], this);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
break;
|
|
1781
|
+
}
|
|
1782
|
+
if (coords.length === 1) {
|
|
1783
|
+
coords = coords[0];
|
|
1784
|
+
} else {
|
|
1785
|
+
type = `Multi${type}`;
|
|
1786
|
+
}
|
|
1787
|
+
const result = {
|
|
1788
|
+
type: "Feature",
|
|
1789
|
+
geometry: {
|
|
1790
|
+
type,
|
|
1791
|
+
coordinates: coords
|
|
1792
|
+
},
|
|
1793
|
+
properties: this.properties
|
|
1794
|
+
};
|
|
1795
|
+
if (this.id !== null) {
|
|
1796
|
+
result.id = this.id;
|
|
1797
|
+
}
|
|
1798
|
+
return result;
|
|
1799
|
+
}
|
|
1800
|
+
toGeoJSON(options) {
|
|
1801
|
+
if (typeof options === "function") {
|
|
1802
|
+
return this._toGeoJSON(options);
|
|
1803
|
+
}
|
|
1804
|
+
const { x: x2, y: y2, z } = options;
|
|
1805
|
+
const size = this.extent * Math.pow(2, z);
|
|
1806
|
+
const x0 = this.extent * x2;
|
|
1807
|
+
const y0 = this.extent * y2;
|
|
1808
|
+
function project2(line) {
|
|
1809
|
+
for (let j = 0; j < line.length; j++) {
|
|
1810
|
+
const p = line[j];
|
|
1811
|
+
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
1812
|
+
const y22 = 180 - (p[1] + y0) * 360 / size;
|
|
1813
|
+
p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
return this._toGeoJSON(project2);
|
|
1817
|
+
}
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
});
|
|
1821
|
+
|
|
1822
|
+
// src/lib/mapbox-vector-tile/vector-tile-layer.ts
|
|
1823
|
+
function readLayer(tag, layer, pbf) {
|
|
1824
|
+
if (layer && pbf) {
|
|
1825
|
+
if (tag === 15)
|
|
1826
|
+
layer.version = pbf.readVarint();
|
|
1827
|
+
else if (tag === 1)
|
|
1828
|
+
layer.name = pbf.readString();
|
|
1829
|
+
else if (tag === 5)
|
|
1830
|
+
layer.extent = pbf.readVarint();
|
|
1831
|
+
else if (tag === 2)
|
|
1832
|
+
layer._features.push(pbf.pos);
|
|
1833
|
+
else if (tag === 3)
|
|
1834
|
+
layer._keys.push(pbf.readString());
|
|
1835
|
+
else if (tag === 4)
|
|
1836
|
+
layer._values.push(readValueMessage(pbf));
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
function readValueMessage(pbf) {
|
|
1840
|
+
let value = null;
|
|
1841
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1842
|
+
while (pbf.pos < end) {
|
|
1843
|
+
const tag = pbf.readVarint() >> 3;
|
|
1844
|
+
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;
|
|
1845
|
+
}
|
|
1846
|
+
return value;
|
|
1847
|
+
}
|
|
1848
|
+
var VectorTileLayer;
|
|
1849
|
+
var init_vector_tile_layer = __esm({
|
|
1850
|
+
"src/lib/mapbox-vector-tile/vector-tile-layer.ts"() {
|
|
1851
|
+
init_vector_tile_feature();
|
|
1852
|
+
VectorTileLayer = class {
|
|
1853
|
+
constructor(pbf, end) {
|
|
1854
|
+
this.version = 1;
|
|
1855
|
+
this.name = "";
|
|
1856
|
+
this.extent = 4096;
|
|
1857
|
+
this.length = 0;
|
|
1858
|
+
this._pbf = pbf;
|
|
1859
|
+
this._keys = [];
|
|
1860
|
+
this._values = [];
|
|
1861
|
+
this._features = [];
|
|
1862
|
+
pbf.readFields(readLayer, this, end);
|
|
1863
|
+
this.length = this._features.length;
|
|
1864
|
+
}
|
|
1865
|
+
feature(i2) {
|
|
1866
|
+
if (i2 < 0 || i2 >= this._features.length) {
|
|
1867
|
+
throw new Error("feature index out of bounds");
|
|
1868
|
+
}
|
|
1869
|
+
this._pbf.pos = this._features[i2];
|
|
1870
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1871
|
+
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
}
|
|
1875
|
+
});
|
|
1876
|
+
|
|
1877
|
+
// src/lib/mapbox-vector-tile/vector-tile.ts
|
|
1878
|
+
function readTile(tag, layers, pbf) {
|
|
1879
|
+
if (tag === 3) {
|
|
1880
|
+
if (pbf) {
|
|
1881
|
+
const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
|
|
1882
|
+
if (layer.length && layers) {
|
|
1883
|
+
layers[layer.name] = layer;
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
var VectorTile;
|
|
1889
|
+
var init_vector_tile = __esm({
|
|
1890
|
+
"src/lib/mapbox-vector-tile/vector-tile.ts"() {
|
|
1891
|
+
init_vector_tile_layer();
|
|
1892
|
+
VectorTile = class {
|
|
1893
|
+
constructor(pbf, end) {
|
|
1894
|
+
this.layers = pbf.readFields(readTile, {}, end);
|
|
1895
|
+
}
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
});
|
|
1899
|
+
|
|
1900
|
+
// src/helpers/binary-util-functions.ts
|
|
1901
|
+
function classifyRings2(geom) {
|
|
1902
|
+
const len = geom.indices.length;
|
|
1903
|
+
const type = "Polygon";
|
|
1904
|
+
if (len <= 1) {
|
|
1905
|
+
return {
|
|
1906
|
+
type,
|
|
1907
|
+
data: geom.data,
|
|
1908
|
+
areas: [[getPolygonSignedArea(geom.data)]],
|
|
1909
|
+
indices: [geom.indices]
|
|
1910
|
+
};
|
|
1911
|
+
}
|
|
1912
|
+
const areas = [];
|
|
1913
|
+
const polygons = [];
|
|
1914
|
+
let ringAreas = [];
|
|
1915
|
+
let polygon = [];
|
|
1916
|
+
let ccw;
|
|
1917
|
+
let offset = 0;
|
|
1918
|
+
for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
|
|
1919
|
+
startIndex = geom.indices[i2] - offset;
|
|
1920
|
+
endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
|
|
1921
|
+
const shape = geom.data.slice(startIndex, endIndex);
|
|
1922
|
+
const area2 = getPolygonSignedArea(shape);
|
|
1923
|
+
if (area2 === 0) {
|
|
1924
|
+
const before = geom.data.slice(0, startIndex);
|
|
1925
|
+
const after = geom.data.slice(endIndex);
|
|
1926
|
+
geom.data = before.concat(after);
|
|
1927
|
+
offset += endIndex - startIndex;
|
|
1928
|
+
continue;
|
|
1929
|
+
}
|
|
1930
|
+
if (ccw === void 0)
|
|
1931
|
+
ccw = area2 < 0;
|
|
1932
|
+
if (ccw === area2 < 0) {
|
|
1933
|
+
if (polygon.length) {
|
|
1934
|
+
areas.push(ringAreas);
|
|
1935
|
+
polygons.push(polygon);
|
|
1936
|
+
}
|
|
1937
|
+
polygon = [startIndex];
|
|
1938
|
+
ringAreas = [area2];
|
|
1939
|
+
} else {
|
|
1940
|
+
ringAreas.push(area2);
|
|
1941
|
+
polygon.push(startIndex);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
if (ringAreas)
|
|
1945
|
+
areas.push(ringAreas);
|
|
1946
|
+
if (polygon.length)
|
|
1947
|
+
polygons.push(polygon);
|
|
1948
|
+
return { type, areas, indices: polygons, data: geom.data };
|
|
1949
|
+
}
|
|
1950
|
+
function project(data, x0, y0, size) {
|
|
1951
|
+
for (let j = 0, jl = data.length; j < jl; j += 2) {
|
|
1952
|
+
data[j] = (data[j] + x0) * 360 / size - 180;
|
|
1953
|
+
const y2 = 180 - (data[j + 1] + y0) * 360 / size;
|
|
1954
|
+
data[j + 1] = 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
function readFeature2(tag, feature, pbf) {
|
|
1958
|
+
if (feature && pbf) {
|
|
1959
|
+
if (tag === 1)
|
|
1960
|
+
feature.id = pbf.readVarint();
|
|
1961
|
+
else if (tag === 2)
|
|
1962
|
+
readTag2(pbf, feature);
|
|
1963
|
+
else if (tag === 3)
|
|
1964
|
+
feature.type = pbf.readVarint();
|
|
1965
|
+
else if (tag === 4)
|
|
1966
|
+
feature._geometry = pbf.pos;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
function readTag2(pbf, feature) {
|
|
1970
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1971
|
+
while (pbf.pos < end) {
|
|
1972
|
+
const key = feature._keys[pbf.readVarint()];
|
|
1973
|
+
const value = feature._values[pbf.readVarint()];
|
|
1974
|
+
feature.properties[key] = value;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
var init_binary_util_functions = __esm({
|
|
1978
|
+
"src/helpers/binary-util-functions.ts"() {
|
|
1979
|
+
init_esm();
|
|
1980
|
+
}
|
|
1981
|
+
});
|
|
1982
|
+
|
|
1983
|
+
// src/lib/binary-vector-tile/vector-tile-feature.ts
|
|
1984
|
+
var endPos, cmd, cmdLen, length, x, y, i, VectorTileFeature2;
|
|
1985
|
+
var init_vector_tile_feature2 = __esm({
|
|
1986
|
+
"src/lib/binary-vector-tile/vector-tile-feature.ts"() {
|
|
1987
|
+
init_binary_util_functions();
|
|
1988
|
+
VectorTileFeature2 = class {
|
|
1989
|
+
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
1990
|
+
this.properties = {};
|
|
1991
|
+
this.extent = extent;
|
|
1992
|
+
this.type = 0;
|
|
1993
|
+
this.id = null;
|
|
1994
|
+
this._pbf = pbf;
|
|
1995
|
+
this._geometry = -1;
|
|
1996
|
+
this._keys = keys;
|
|
1997
|
+
this._values = values;
|
|
1998
|
+
this._geometryInfo = geometryInfo;
|
|
1999
|
+
pbf.readFields(readFeature2, this, end);
|
|
2000
|
+
}
|
|
2001
|
+
loadGeometry() {
|
|
2002
|
+
const pbf = this._pbf;
|
|
2003
|
+
pbf.pos = this._geometry;
|
|
2004
|
+
endPos = pbf.readVarint() + pbf.pos;
|
|
2005
|
+
cmd = 1;
|
|
2006
|
+
length = 0;
|
|
2007
|
+
x = 0;
|
|
2008
|
+
y = 0;
|
|
2009
|
+
i = 0;
|
|
2010
|
+
const indices = [];
|
|
2011
|
+
const data = [];
|
|
2012
|
+
while (pbf.pos < endPos) {
|
|
2013
|
+
if (length <= 0) {
|
|
2014
|
+
cmdLen = pbf.readVarint();
|
|
2015
|
+
cmd = cmdLen & 7;
|
|
2016
|
+
length = cmdLen >> 3;
|
|
2036
2017
|
}
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
if (
|
|
2042
|
-
|
|
2018
|
+
length--;
|
|
2019
|
+
if (cmd === 1 || cmd === 2) {
|
|
2020
|
+
x += pbf.readSVarint();
|
|
2021
|
+
y += pbf.readSVarint();
|
|
2022
|
+
if (cmd === 1) {
|
|
2023
|
+
indices.push(i);
|
|
2043
2024
|
}
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
c = null;
|
|
2025
|
+
data.push(x, y);
|
|
2026
|
+
i += 2;
|
|
2027
|
+
} else if (cmd === 7) {
|
|
2028
|
+
if (i > 0) {
|
|
2029
|
+
const start = indices[indices.length - 1];
|
|
2030
|
+
data.push(data[start], data[start + 1]);
|
|
2031
|
+
i += 2;
|
|
2052
2032
|
}
|
|
2033
|
+
} else {
|
|
2034
|
+
throw new Error(`unknown command ${cmd}`);
|
|
2053
2035
|
}
|
|
2054
|
-
}
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2036
|
+
}
|
|
2037
|
+
return { data, indices };
|
|
2038
|
+
}
|
|
2039
|
+
_toBinaryCoordinates(transform) {
|
|
2040
|
+
const geom = this.loadGeometry();
|
|
2041
|
+
let geometry;
|
|
2042
|
+
transform(geom.data, this);
|
|
2043
|
+
const coordLength = 2;
|
|
2044
|
+
switch (this.type) {
|
|
2045
|
+
case 1:
|
|
2046
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
2047
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
2048
|
+
geometry = { type: "Point", ...geom };
|
|
2049
|
+
break;
|
|
2050
|
+
case 2:
|
|
2051
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
2052
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
2053
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
2054
|
+
geometry = { type: "LineString", ...geom };
|
|
2055
|
+
break;
|
|
2056
|
+
case 3:
|
|
2057
|
+
geometry = classifyRings2(geom);
|
|
2058
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
2059
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
2060
|
+
for (const indices of geometry.indices) {
|
|
2061
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
2062
2062
|
}
|
|
2063
|
-
|
|
2063
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
2064
|
+
break;
|
|
2065
|
+
default:
|
|
2066
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
2064
2067
|
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
} else if (c > 65535) {
|
|
2069
|
-
c -= 65536;
|
|
2070
|
-
str += String.fromCharCode(c >>> 10 & 1023 | 55296);
|
|
2071
|
-
c = 56320 | c & 1023;
|
|
2068
|
+
const result = { type: "Feature", geometry, properties: this.properties };
|
|
2069
|
+
if (this.id !== null) {
|
|
2070
|
+
result.id = this.id;
|
|
2072
2071
|
}
|
|
2073
|
-
|
|
2074
|
-
i2 += bytesPerSequence;
|
|
2072
|
+
return result;
|
|
2075
2073
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
return utf8TextDecoder.decode(buf.subarray(pos, end));
|
|
2080
|
-
}
|
|
2081
|
-
function writeUtf8(buf, str, pos) {
|
|
2082
|
-
for (var i2 = 0, c, lead; i2 < str.length; i2++) {
|
|
2083
|
-
c = str.charCodeAt(i2);
|
|
2084
|
-
if (c > 55295 && c < 57344) {
|
|
2085
|
-
if (lead) {
|
|
2086
|
-
if (c < 56320) {
|
|
2087
|
-
buf[pos++] = 239;
|
|
2088
|
-
buf[pos++] = 191;
|
|
2089
|
-
buf[pos++] = 189;
|
|
2090
|
-
lead = c;
|
|
2091
|
-
continue;
|
|
2092
|
-
} else {
|
|
2093
|
-
c = lead - 55296 << 10 | c - 56320 | 65536;
|
|
2094
|
-
lead = null;
|
|
2095
|
-
}
|
|
2096
|
-
} else {
|
|
2097
|
-
if (c > 56319 || i2 + 1 === str.length) {
|
|
2098
|
-
buf[pos++] = 239;
|
|
2099
|
-
buf[pos++] = 191;
|
|
2100
|
-
buf[pos++] = 189;
|
|
2101
|
-
} else {
|
|
2102
|
-
lead = c;
|
|
2103
|
-
}
|
|
2104
|
-
continue;
|
|
2105
|
-
}
|
|
2106
|
-
} else if (lead) {
|
|
2107
|
-
buf[pos++] = 239;
|
|
2108
|
-
buf[pos++] = 191;
|
|
2109
|
-
buf[pos++] = 189;
|
|
2110
|
-
lead = null;
|
|
2074
|
+
toBinaryCoordinates(options) {
|
|
2075
|
+
if (typeof options === "function") {
|
|
2076
|
+
return this._toBinaryCoordinates(options);
|
|
2111
2077
|
}
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2078
|
+
const { x: x2, y: y2, z } = options;
|
|
2079
|
+
const size = this.extent * Math.pow(2, z);
|
|
2080
|
+
const x0 = this.extent * x2;
|
|
2081
|
+
const y0 = this.extent * y2;
|
|
2082
|
+
return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
});
|
|
2087
|
+
|
|
2088
|
+
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
2089
|
+
function readLayer2(tag, layer, pbf) {
|
|
2090
|
+
if (layer && pbf) {
|
|
2091
|
+
if (tag === 15)
|
|
2092
|
+
layer.version = pbf.readVarint();
|
|
2093
|
+
else if (tag === 1)
|
|
2094
|
+
layer.name = pbf.readString();
|
|
2095
|
+
else if (tag === 5)
|
|
2096
|
+
layer.extent = pbf.readVarint();
|
|
2097
|
+
else if (tag === 2)
|
|
2098
|
+
layer._features.push(pbf.pos);
|
|
2099
|
+
else if (tag === 3)
|
|
2100
|
+
layer._keys.push(pbf.readString());
|
|
2101
|
+
else if (tag === 4)
|
|
2102
|
+
layer._values.push(readValueMessage2(pbf));
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
function readValueMessage2(pbf) {
|
|
2106
|
+
let value = null;
|
|
2107
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
2108
|
+
while (pbf.pos < end) {
|
|
2109
|
+
const tag = pbf.readVarint() >> 3;
|
|
2110
|
+
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;
|
|
2111
|
+
}
|
|
2112
|
+
return value;
|
|
2113
|
+
}
|
|
2114
|
+
var VectorTileLayer2;
|
|
2115
|
+
var init_vector_tile_layer2 = __esm({
|
|
2116
|
+
"src/lib/binary-vector-tile/vector-tile-layer.ts"() {
|
|
2117
|
+
init_vector_tile_feature2();
|
|
2118
|
+
VectorTileLayer2 = class {
|
|
2119
|
+
constructor(pbf, end) {
|
|
2120
|
+
this.version = 1;
|
|
2121
|
+
this.name = "";
|
|
2122
|
+
this.extent = 4096;
|
|
2123
|
+
this.length = 0;
|
|
2124
|
+
this._pbf = pbf;
|
|
2125
|
+
this._keys = [];
|
|
2126
|
+
this._values = [];
|
|
2127
|
+
this._features = [];
|
|
2128
|
+
pbf.readFields(readLayer2, this, end);
|
|
2129
|
+
this.length = this._features.length;
|
|
2130
|
+
}
|
|
2131
|
+
feature(i2, geometryInfo) {
|
|
2132
|
+
if (i2 < 0 || i2 >= this._features.length) {
|
|
2133
|
+
throw new Error("feature index out of bounds");
|
|
2127
2134
|
}
|
|
2135
|
+
this._pbf.pos = this._features[i2];
|
|
2136
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
2137
|
+
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
2138
|
+
}
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2142
|
+
|
|
2143
|
+
// src/lib/binary-vector-tile/vector-tile.ts
|
|
2144
|
+
function readTile2(tag, layers, pbf) {
|
|
2145
|
+
if (tag === 3) {
|
|
2146
|
+
if (pbf) {
|
|
2147
|
+
const layer = new VectorTileLayer2(pbf, pbf.readVarint() + pbf.pos);
|
|
2148
|
+
if (layer.length && layers) {
|
|
2149
|
+
layers[layer.name] = layer;
|
|
2128
2150
|
}
|
|
2129
|
-
return pos;
|
|
2130
2151
|
}
|
|
2131
2152
|
}
|
|
2153
|
+
}
|
|
2154
|
+
var VectorTile2;
|
|
2155
|
+
var init_vector_tile2 = __esm({
|
|
2156
|
+
"src/lib/binary-vector-tile/vector-tile.ts"() {
|
|
2157
|
+
init_vector_tile_layer2();
|
|
2158
|
+
VectorTile2 = class {
|
|
2159
|
+
constructor(pbf, end) {
|
|
2160
|
+
this.layers = pbf.readFields(readTile2, {}, end);
|
|
2161
|
+
}
|
|
2162
|
+
};
|
|
2163
|
+
}
|
|
2132
2164
|
});
|
|
2133
2165
|
|
|
2134
2166
|
// src/lib/parse-mvt.ts
|
|
2135
2167
|
function parseMVT(arrayBuffer, options) {
|
|
2136
|
-
|
|
2168
|
+
const mvtOptions = normalizeOptions(options);
|
|
2169
|
+
const shape = options?.gis?.format || options?.mvt?.shape;
|
|
2170
|
+
switch (shape) {
|
|
2171
|
+
case "columnar-table":
|
|
2172
|
+
return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
|
|
2173
|
+
case "geojson-row-table": {
|
|
2174
|
+
const table = {
|
|
2175
|
+
shape: "geojson-row-table",
|
|
2176
|
+
data: parseToGeojson(arrayBuffer, mvtOptions)
|
|
2177
|
+
};
|
|
2178
|
+
return table;
|
|
2179
|
+
}
|
|
2180
|
+
case "geojson":
|
|
2181
|
+
return parseToGeojson(arrayBuffer, mvtOptions);
|
|
2182
|
+
case "binary-geometry":
|
|
2183
|
+
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2184
|
+
case "binary":
|
|
2185
|
+
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2186
|
+
default:
|
|
2187
|
+
throw new Error(shape);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
function parseToBinary(arrayBuffer, options) {
|
|
2191
|
+
const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);
|
|
2192
|
+
const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, geometryInfo);
|
|
2193
|
+
binaryData.byteLength = arrayBuffer.byteLength;
|
|
2194
|
+
return binaryData;
|
|
2195
|
+
}
|
|
2196
|
+
function parseToFlatGeoJson(arrayBuffer, options) {
|
|
2137
2197
|
const features = [];
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
if (!vectorTileLayer) {
|
|
2160
|
-
return;
|
|
2161
|
-
}
|
|
2162
|
-
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2163
|
-
const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
|
|
2164
|
-
const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
|
|
2165
|
-
features.push(decodedFeature);
|
|
2166
|
-
}
|
|
2167
|
-
});
|
|
2198
|
+
const geometryInfo = {
|
|
2199
|
+
coordLength: 2,
|
|
2200
|
+
pointPositionsCount: 0,
|
|
2201
|
+
pointFeaturesCount: 0,
|
|
2202
|
+
linePositionsCount: 0,
|
|
2203
|
+
linePathsCount: 0,
|
|
2204
|
+
lineFeaturesCount: 0,
|
|
2205
|
+
polygonPositionsCount: 0,
|
|
2206
|
+
polygonObjectsCount: 0,
|
|
2207
|
+
polygonRingsCount: 0,
|
|
2208
|
+
polygonFeaturesCount: 0
|
|
2209
|
+
};
|
|
2210
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
2211
|
+
return [features, geometryInfo];
|
|
2212
|
+
}
|
|
2213
|
+
const tile = new VectorTile2(new import_pbf.default(arrayBuffer));
|
|
2214
|
+
const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
2215
|
+
selectedLayers.forEach((layerName) => {
|
|
2216
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
2217
|
+
if (!vectorTileLayer) {
|
|
2218
|
+
return;
|
|
2168
2219
|
}
|
|
2169
|
-
|
|
2170
|
-
const
|
|
2171
|
-
|
|
2172
|
-
|
|
2220
|
+
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2221
|
+
const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
|
|
2222
|
+
const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
|
|
2223
|
+
features.push(decodedFeature);
|
|
2173
2224
|
}
|
|
2225
|
+
});
|
|
2226
|
+
return [features, geometryInfo];
|
|
2227
|
+
}
|
|
2228
|
+
function parseToGeojson(arrayBuffer, options) {
|
|
2229
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
2230
|
+
return [];
|
|
2174
2231
|
}
|
|
2232
|
+
const features = [];
|
|
2233
|
+
const tile = new VectorTile(new import_pbf.default(arrayBuffer));
|
|
2234
|
+
const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
2235
|
+
selectedLayers.forEach((layerName) => {
|
|
2236
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
2237
|
+
if (!vectorTileLayer) {
|
|
2238
|
+
return;
|
|
2239
|
+
}
|
|
2240
|
+
for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
|
|
2241
|
+
const vectorTileFeature = vectorTileLayer.feature(i2);
|
|
2242
|
+
const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
|
|
2243
|
+
features.push(decodedFeature);
|
|
2244
|
+
}
|
|
2245
|
+
});
|
|
2175
2246
|
return features;
|
|
2176
2247
|
}
|
|
2177
2248
|
function normalizeOptions(options) {
|
|
2178
|
-
if (options) {
|
|
2179
|
-
options
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2187
|
-
if (wgs84Coordinates && !hasTileIndex) {
|
|
2188
|
-
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.");
|
|
2189
|
-
}
|
|
2249
|
+
if (!options?.mvt) {
|
|
2250
|
+
throw new Error("mvt options required");
|
|
2251
|
+
}
|
|
2252
|
+
const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
|
|
2253
|
+
const { tileIndex } = options.mvt;
|
|
2254
|
+
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2255
|
+
if (wgs84Coordinates && !hasTileIndex) {
|
|
2256
|
+
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
|
|
2190
2257
|
}
|
|
2191
|
-
return options;
|
|
2258
|
+
return options.mvt;
|
|
2192
2259
|
}
|
|
2193
|
-
function getDecodedFeature(feature, options) {
|
|
2260
|
+
function getDecodedFeature(feature, options, layerName) {
|
|
2194
2261
|
const decodedFeature = feature.toGeoJSON(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates);
|
|
2195
2262
|
if (options.layerProperty) {
|
|
2196
|
-
decodedFeature.properties[options.layerProperty] =
|
|
2263
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2197
2264
|
}
|
|
2198
2265
|
return decodedFeature;
|
|
2199
2266
|
}
|
|
2200
|
-
function getDecodedFeatureBinary(feature, options) {
|
|
2267
|
+
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
2201
2268
|
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
2202
2269
|
if (options.layerProperty && decodedFeature.properties) {
|
|
2203
|
-
decodedFeature.properties[options.layerProperty] =
|
|
2270
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2204
2271
|
}
|
|
2205
2272
|
return decodedFeature;
|
|
2206
2273
|
}
|
|
@@ -2221,19 +2288,28 @@
|
|
|
2221
2288
|
var import_pbf;
|
|
2222
2289
|
var init_parse_mvt = __esm({
|
|
2223
2290
|
"src/lib/parse-mvt.ts"() {
|
|
2224
|
-
init_vector_tile();
|
|
2225
|
-
init_vector_tile2();
|
|
2226
2291
|
init_src();
|
|
2227
2292
|
import_pbf = __toModule(require_pbf());
|
|
2293
|
+
init_vector_tile();
|
|
2294
|
+
init_vector_tile2();
|
|
2228
2295
|
}
|
|
2229
2296
|
});
|
|
2230
2297
|
|
|
2231
2298
|
// src/mvt-loader.ts
|
|
2232
|
-
var VERSION, MVTWorkerLoader, MVTLoader;
|
|
2299
|
+
var VERSION, DEFAULT_MVT_LOADER_OPTIONS, MVTWorkerLoader, MVTLoader;
|
|
2233
2300
|
var init_mvt_loader = __esm({
|
|
2234
2301
|
"src/mvt-loader.ts"() {
|
|
2235
2302
|
init_parse_mvt();
|
|
2236
2303
|
VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2304
|
+
DEFAULT_MVT_LOADER_OPTIONS = {
|
|
2305
|
+
mvt: {
|
|
2306
|
+
shape: "geojson",
|
|
2307
|
+
coordinates: "local",
|
|
2308
|
+
layerProperty: "layerName",
|
|
2309
|
+
layers: void 0,
|
|
2310
|
+
tileIndex: null
|
|
2311
|
+
}
|
|
2312
|
+
};
|
|
2237
2313
|
MVTWorkerLoader = {
|
|
2238
2314
|
name: "Mapbox Vector Tile",
|
|
2239
2315
|
id: "mvt",
|
|
@@ -2246,14 +2322,7 @@
|
|
|
2246
2322
|
],
|
|
2247
2323
|
worker: true,
|
|
2248
2324
|
category: "geometry",
|
|
2249
|
-
options:
|
|
2250
|
-
mvt: {
|
|
2251
|
-
coordinates: "local",
|
|
2252
|
-
layerProperty: "layerName",
|
|
2253
|
-
layers: null,
|
|
2254
|
-
tileIndex: null
|
|
2255
|
-
}
|
|
2256
|
-
}
|
|
2325
|
+
options: DEFAULT_MVT_LOADER_OPTIONS
|
|
2257
2326
|
};
|
|
2258
2327
|
MVTLoader = {
|
|
2259
2328
|
...MVTWorkerLoader,
|
|
@@ -2264,15 +2333,781 @@
|
|
|
2264
2333
|
}
|
|
2265
2334
|
});
|
|
2266
2335
|
|
|
2336
|
+
// src/lib/geojson-tiler/simplify.ts
|
|
2337
|
+
function simplify(coords, first, last, sqTolerance) {
|
|
2338
|
+
let maxSqDist = sqTolerance;
|
|
2339
|
+
const mid = last - first >> 1;
|
|
2340
|
+
let minPosToMid = last - first;
|
|
2341
|
+
let index;
|
|
2342
|
+
const ax = coords[first];
|
|
2343
|
+
const ay = coords[first + 1];
|
|
2344
|
+
const bx = coords[last];
|
|
2345
|
+
const by = coords[last + 1];
|
|
2346
|
+
for (let i2 = first + 3; i2 < last; i2 += 3) {
|
|
2347
|
+
const d = getSqSegDist(coords[i2], coords[i2 + 1], ax, ay, bx, by);
|
|
2348
|
+
if (d > maxSqDist) {
|
|
2349
|
+
index = i2;
|
|
2350
|
+
maxSqDist = d;
|
|
2351
|
+
} else if (d === maxSqDist) {
|
|
2352
|
+
const posToMid = Math.abs(i2 - mid);
|
|
2353
|
+
if (posToMid < minPosToMid) {
|
|
2354
|
+
index = i2;
|
|
2355
|
+
minPosToMid = posToMid;
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
if (maxSqDist > sqTolerance) {
|
|
2360
|
+
if (index - first > 3)
|
|
2361
|
+
simplify(coords, first, index, sqTolerance);
|
|
2362
|
+
coords[index + 2] = maxSqDist;
|
|
2363
|
+
if (last - index > 3)
|
|
2364
|
+
simplify(coords, index, last, sqTolerance);
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
function getSqSegDist(px, py, x2, y2, bx, by) {
|
|
2368
|
+
let dx = bx - x2;
|
|
2369
|
+
let dy = by - y2;
|
|
2370
|
+
if (dx !== 0 || dy !== 0) {
|
|
2371
|
+
const t = ((px - x2) * dx + (py - y2) * dy) / (dx * dx + dy * dy);
|
|
2372
|
+
if (t > 1) {
|
|
2373
|
+
x2 = bx;
|
|
2374
|
+
y2 = by;
|
|
2375
|
+
} else if (t > 0) {
|
|
2376
|
+
x2 += dx * t;
|
|
2377
|
+
y2 += dy * t;
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
dx = px - x2;
|
|
2381
|
+
dy = py - y2;
|
|
2382
|
+
return dx * dx + dy * dy;
|
|
2383
|
+
}
|
|
2384
|
+
var init_simplify = __esm({
|
|
2385
|
+
"src/lib/geojson-tiler/simplify.ts"() {
|
|
2386
|
+
}
|
|
2387
|
+
});
|
|
2388
|
+
|
|
2389
|
+
// src/lib/geojson-tiler/feature.ts
|
|
2390
|
+
function createFeature(id, type, geom, tags) {
|
|
2391
|
+
const feature = {
|
|
2392
|
+
id: id == null ? null : id,
|
|
2393
|
+
type,
|
|
2394
|
+
geometry: geom,
|
|
2395
|
+
tags,
|
|
2396
|
+
minX: Infinity,
|
|
2397
|
+
minY: Infinity,
|
|
2398
|
+
maxX: -Infinity,
|
|
2399
|
+
maxY: -Infinity
|
|
2400
|
+
};
|
|
2401
|
+
if (type === "Point" || type === "MultiPoint" || type === "LineString") {
|
|
2402
|
+
calcLineBBox(feature, geom);
|
|
2403
|
+
} else if (type === "Polygon") {
|
|
2404
|
+
calcLineBBox(feature, geom[0]);
|
|
2405
|
+
} else if (type === "MultiLineString") {
|
|
2406
|
+
for (const line of geom) {
|
|
2407
|
+
calcLineBBox(feature, line);
|
|
2408
|
+
}
|
|
2409
|
+
} else if (type === "MultiPolygon") {
|
|
2410
|
+
for (const polygon of geom) {
|
|
2411
|
+
calcLineBBox(feature, polygon[0]);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
return feature;
|
|
2415
|
+
}
|
|
2416
|
+
function calcLineBBox(feature, geom) {
|
|
2417
|
+
for (let i2 = 0; i2 < geom.length; i2 += 3) {
|
|
2418
|
+
feature.minX = Math.min(feature.minX, geom[i2]);
|
|
2419
|
+
feature.minY = Math.min(feature.minY, geom[i2 + 1]);
|
|
2420
|
+
feature.maxX = Math.max(feature.maxX, geom[i2]);
|
|
2421
|
+
feature.maxY = Math.max(feature.maxY, geom[i2 + 1]);
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
var init_feature = __esm({
|
|
2425
|
+
"src/lib/geojson-tiler/feature.ts"() {
|
|
2426
|
+
}
|
|
2427
|
+
});
|
|
2428
|
+
|
|
2429
|
+
// src/lib/geojson-tiler/convert.ts
|
|
2430
|
+
function convert(data, options) {
|
|
2431
|
+
const features = [];
|
|
2432
|
+
if (data.type === "FeatureCollection") {
|
|
2433
|
+
for (let i2 = 0; i2 < data.features.length; i2++) {
|
|
2434
|
+
convertFeature(features, data.features[i2], options, i2);
|
|
2435
|
+
}
|
|
2436
|
+
} else if (data.type === "Feature") {
|
|
2437
|
+
convertFeature(features, data, options);
|
|
2438
|
+
} else {
|
|
2439
|
+
convertFeature(features, { geometry: data }, options);
|
|
2440
|
+
}
|
|
2441
|
+
return features;
|
|
2442
|
+
}
|
|
2443
|
+
function convertFeature(features, geojson, options, index) {
|
|
2444
|
+
if (!geojson.geometry) {
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2447
|
+
const coords = geojson.geometry.coordinates;
|
|
2448
|
+
const type = geojson.geometry.type;
|
|
2449
|
+
const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
|
|
2450
|
+
let geometry = [];
|
|
2451
|
+
let id = geojson.id;
|
|
2452
|
+
if (options.promoteId) {
|
|
2453
|
+
id = geojson.properties[options.promoteId];
|
|
2454
|
+
} else if (options.generateId) {
|
|
2455
|
+
id = index || 0;
|
|
2456
|
+
}
|
|
2457
|
+
if (type === "Point") {
|
|
2458
|
+
convertPoint(coords, geometry);
|
|
2459
|
+
} else if (type === "MultiPoint") {
|
|
2460
|
+
for (const p of coords) {
|
|
2461
|
+
convertPoint(p, geometry);
|
|
2462
|
+
}
|
|
2463
|
+
} else if (type === "LineString") {
|
|
2464
|
+
convertLine(coords, geometry, tolerance, false);
|
|
2465
|
+
} else if (type === "MultiLineString") {
|
|
2466
|
+
if (options.lineMetrics) {
|
|
2467
|
+
for (const line of coords) {
|
|
2468
|
+
geometry = [];
|
|
2469
|
+
convertLine(line, geometry, tolerance, false);
|
|
2470
|
+
features.push(createFeature(id, "LineString", geometry, geojson.properties));
|
|
2471
|
+
}
|
|
2472
|
+
return;
|
|
2473
|
+
} else {
|
|
2474
|
+
convertLines(coords, geometry, tolerance, false);
|
|
2475
|
+
}
|
|
2476
|
+
} else if (type === "Polygon") {
|
|
2477
|
+
convertLines(coords, geometry, tolerance, true);
|
|
2478
|
+
} else if (type === "MultiPolygon") {
|
|
2479
|
+
for (const polygon of coords) {
|
|
2480
|
+
const newPolygon = [];
|
|
2481
|
+
convertLines(polygon, newPolygon, tolerance, true);
|
|
2482
|
+
geometry.push(newPolygon);
|
|
2483
|
+
}
|
|
2484
|
+
} else if (type === "GeometryCollection") {
|
|
2485
|
+
for (const singleGeometry of geojson.geometry.geometries) {
|
|
2486
|
+
convertFeature(features, {
|
|
2487
|
+
id,
|
|
2488
|
+
geometry: singleGeometry,
|
|
2489
|
+
properties: geojson.properties
|
|
2490
|
+
}, options, index);
|
|
2491
|
+
}
|
|
2492
|
+
return;
|
|
2493
|
+
} else {
|
|
2494
|
+
throw new Error("Input data is not a valid GeoJSON object.");
|
|
2495
|
+
}
|
|
2496
|
+
features.push(createFeature(id, type, geometry, geojson.properties));
|
|
2497
|
+
}
|
|
2498
|
+
function convertPoint(coords, out) {
|
|
2499
|
+
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
2500
|
+
}
|
|
2501
|
+
function convertLine(ring, out, tolerance, isPolygon) {
|
|
2502
|
+
let x0, y0;
|
|
2503
|
+
let size = 0;
|
|
2504
|
+
for (let j = 0; j < ring.length; j++) {
|
|
2505
|
+
const x2 = projectX(ring[j][0]);
|
|
2506
|
+
const y2 = projectY(ring[j][1]);
|
|
2507
|
+
out.push(x2, y2, 0);
|
|
2508
|
+
if (j > 0) {
|
|
2509
|
+
if (isPolygon) {
|
|
2510
|
+
size += (x0 * y2 - x2 * y0) / 2;
|
|
2511
|
+
} else {
|
|
2512
|
+
size += Math.sqrt(Math.pow(x2 - x0, 2) + Math.pow(y2 - y0, 2));
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
x0 = x2;
|
|
2516
|
+
y0 = y2;
|
|
2517
|
+
}
|
|
2518
|
+
const last = out.length - 3;
|
|
2519
|
+
out[2] = 1;
|
|
2520
|
+
simplify(out, 0, last, tolerance);
|
|
2521
|
+
out[last + 2] = 1;
|
|
2522
|
+
out.size = Math.abs(size);
|
|
2523
|
+
out.start = 0;
|
|
2524
|
+
out.end = out.size;
|
|
2525
|
+
}
|
|
2526
|
+
function convertLines(rings, out, tolerance, isPolygon) {
|
|
2527
|
+
for (let i2 = 0; i2 < rings.length; i2++) {
|
|
2528
|
+
const geom = [];
|
|
2529
|
+
convertLine(rings[i2], geom, tolerance, isPolygon);
|
|
2530
|
+
out.push(geom);
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
function projectX(x2) {
|
|
2534
|
+
return x2 / 360 + 0.5;
|
|
2535
|
+
}
|
|
2536
|
+
function projectY(y2) {
|
|
2537
|
+
const sin = Math.sin(y2 * Math.PI / 180);
|
|
2538
|
+
const y22 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
|
|
2539
|
+
return y22 < 0 ? 0 : y22 > 1 ? 1 : y22;
|
|
2540
|
+
}
|
|
2541
|
+
var init_convert = __esm({
|
|
2542
|
+
"src/lib/geojson-tiler/convert.ts"() {
|
|
2543
|
+
init_simplify();
|
|
2544
|
+
init_feature();
|
|
2545
|
+
}
|
|
2546
|
+
});
|
|
2547
|
+
|
|
2548
|
+
// src/lib/geojson-tiler/clip.ts
|
|
2549
|
+
function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
2550
|
+
k1 /= scale;
|
|
2551
|
+
k2 /= scale;
|
|
2552
|
+
if (minAll >= k1 && maxAll < k2) {
|
|
2553
|
+
return features;
|
|
2554
|
+
} else if (maxAll < k1 || minAll >= k2) {
|
|
2555
|
+
return null;
|
|
2556
|
+
}
|
|
2557
|
+
const clipped = [];
|
|
2558
|
+
for (const feature of features) {
|
|
2559
|
+
const geometry = feature.geometry;
|
|
2560
|
+
let type = feature.type;
|
|
2561
|
+
const min = axis === 0 ? feature.minX : feature.minY;
|
|
2562
|
+
const max = axis === 0 ? feature.maxX : feature.maxY;
|
|
2563
|
+
if (min >= k1 && max < k2) {
|
|
2564
|
+
clipped.push(feature);
|
|
2565
|
+
continue;
|
|
2566
|
+
} else if (max < k1 || min >= k2) {
|
|
2567
|
+
continue;
|
|
2568
|
+
}
|
|
2569
|
+
let newGeometry = [];
|
|
2570
|
+
if (type === "Point" || type === "MultiPoint") {
|
|
2571
|
+
clipPoints(geometry, newGeometry, k1, k2, axis);
|
|
2572
|
+
} else if (type === "LineString") {
|
|
2573
|
+
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
|
|
2574
|
+
} else if (type === "MultiLineString") {
|
|
2575
|
+
clipLines(geometry, newGeometry, k1, k2, axis, false);
|
|
2576
|
+
} else if (type === "Polygon") {
|
|
2577
|
+
clipLines(geometry, newGeometry, k1, k2, axis, true);
|
|
2578
|
+
} else if (type === "MultiPolygon") {
|
|
2579
|
+
for (const polygon of geometry) {
|
|
2580
|
+
const newPolygon = [];
|
|
2581
|
+
clipLines(polygon, newPolygon, k1, k2, axis, true);
|
|
2582
|
+
if (newPolygon.length) {
|
|
2583
|
+
newGeometry.push(newPolygon);
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
if (newGeometry.length) {
|
|
2588
|
+
if (options.lineMetrics && type === "LineString") {
|
|
2589
|
+
for (const line of newGeometry) {
|
|
2590
|
+
clipped.push(createFeature(feature.id, type, line, feature.tags));
|
|
2591
|
+
}
|
|
2592
|
+
continue;
|
|
2593
|
+
}
|
|
2594
|
+
if (type === "LineString" || type === "MultiLineString") {
|
|
2595
|
+
if (newGeometry.length === 1) {
|
|
2596
|
+
type = "LineString";
|
|
2597
|
+
newGeometry = newGeometry[0];
|
|
2598
|
+
} else {
|
|
2599
|
+
type = "MultiLineString";
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
if (type === "Point" || type === "MultiPoint") {
|
|
2603
|
+
type = newGeometry.length === 3 ? "Point" : "MultiPoint";
|
|
2604
|
+
}
|
|
2605
|
+
clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
return clipped.length ? clipped : null;
|
|
2609
|
+
}
|
|
2610
|
+
function clipPoints(geom, newGeom, k1, k2, axis) {
|
|
2611
|
+
for (let i2 = 0; i2 < geom.length; i2 += 3) {
|
|
2612
|
+
const a = geom[i2 + axis];
|
|
2613
|
+
if (a >= k1 && a <= k2) {
|
|
2614
|
+
addPoint(newGeom, geom[i2], geom[i2 + 1], geom[i2 + 2]);
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
|
|
2619
|
+
let slice = newSlice(geom);
|
|
2620
|
+
const intersect2 = axis === 0 ? intersectX : intersectY;
|
|
2621
|
+
let len = geom.start;
|
|
2622
|
+
let segLen;
|
|
2623
|
+
let t;
|
|
2624
|
+
for (let i2 = 0; i2 < geom.length - 3; i2 += 3) {
|
|
2625
|
+
const ax2 = geom[i2];
|
|
2626
|
+
const ay2 = geom[i2 + 1];
|
|
2627
|
+
const az2 = geom[i2 + 2];
|
|
2628
|
+
const bx = geom[i2 + 3];
|
|
2629
|
+
const by = geom[i2 + 4];
|
|
2630
|
+
const a2 = axis === 0 ? ax2 : ay2;
|
|
2631
|
+
const b = axis === 0 ? bx : by;
|
|
2632
|
+
let exited = false;
|
|
2633
|
+
if (trackMetrics) {
|
|
2634
|
+
segLen = Math.sqrt(Math.pow(ax2 - bx, 2) + Math.pow(ay2 - by, 2));
|
|
2635
|
+
}
|
|
2636
|
+
if (a2 < k1) {
|
|
2637
|
+
if (b > k1) {
|
|
2638
|
+
t = intersect2(slice, ax2, ay2, bx, by, k1);
|
|
2639
|
+
if (trackMetrics) {
|
|
2640
|
+
slice.start = len + segLen * t;
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
} else if (a2 > k2) {
|
|
2644
|
+
if (b < k2) {
|
|
2645
|
+
t = intersect2(slice, ax2, ay2, bx, by, k2);
|
|
2646
|
+
if (trackMetrics) {
|
|
2647
|
+
slice.start = len + segLen * t;
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
} else {
|
|
2651
|
+
addPoint(slice, ax2, ay2, az2);
|
|
2652
|
+
}
|
|
2653
|
+
if (b < k1 && a2 >= k1) {
|
|
2654
|
+
t = intersect2(slice, ax2, ay2, bx, by, k1);
|
|
2655
|
+
exited = true;
|
|
2656
|
+
}
|
|
2657
|
+
if (b > k2 && a2 <= k2) {
|
|
2658
|
+
t = intersect2(slice, ax2, ay2, bx, by, k2);
|
|
2659
|
+
exited = true;
|
|
2660
|
+
}
|
|
2661
|
+
if (!isPolygon && exited) {
|
|
2662
|
+
if (trackMetrics) {
|
|
2663
|
+
slice.end = len + segLen * t;
|
|
2664
|
+
}
|
|
2665
|
+
newGeom.push(slice);
|
|
2666
|
+
slice = newSlice(geom);
|
|
2667
|
+
}
|
|
2668
|
+
if (trackMetrics) {
|
|
2669
|
+
len += segLen;
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
let last = geom.length - 3;
|
|
2673
|
+
const ax = geom[last];
|
|
2674
|
+
const ay = geom[last + 1];
|
|
2675
|
+
const az = geom[last + 2];
|
|
2676
|
+
const a = axis === 0 ? ax : ay;
|
|
2677
|
+
if (a >= k1 && a <= k2)
|
|
2678
|
+
addPoint(slice, ax, ay, az);
|
|
2679
|
+
last = slice.length - 3;
|
|
2680
|
+
if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
|
|
2681
|
+
addPoint(slice, slice[0], slice[1], slice[2]);
|
|
2682
|
+
}
|
|
2683
|
+
if (slice.length) {
|
|
2684
|
+
newGeom.push(slice);
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
function newSlice(line) {
|
|
2688
|
+
const slice = [];
|
|
2689
|
+
slice.size = line.size;
|
|
2690
|
+
slice.start = line.start;
|
|
2691
|
+
slice.end = line.end;
|
|
2692
|
+
return slice;
|
|
2693
|
+
}
|
|
2694
|
+
function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
|
|
2695
|
+
for (const line of geom) {
|
|
2696
|
+
clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
function addPoint(out, x2, y2, z) {
|
|
2700
|
+
out.push(x2, y2, z);
|
|
2701
|
+
}
|
|
2702
|
+
function intersectX(out, ax, ay, bx, by, x2) {
|
|
2703
|
+
const t = (x2 - ax) / (bx - ax);
|
|
2704
|
+
addPoint(out, x2, ay + (by - ay) * t, 1);
|
|
2705
|
+
return t;
|
|
2706
|
+
}
|
|
2707
|
+
function intersectY(out, ax, ay, bx, by, y2) {
|
|
2708
|
+
const t = (y2 - ay) / (by - ay);
|
|
2709
|
+
addPoint(out, ax + (bx - ax) * t, y2, 1);
|
|
2710
|
+
return t;
|
|
2711
|
+
}
|
|
2712
|
+
var init_clip = __esm({
|
|
2713
|
+
"src/lib/geojson-tiler/clip.ts"() {
|
|
2714
|
+
init_feature();
|
|
2715
|
+
}
|
|
2716
|
+
});
|
|
2717
|
+
|
|
2718
|
+
// src/lib/geojson-tiler/wrap.ts
|
|
2719
|
+
function wrap(features, options) {
|
|
2720
|
+
const buffer = options.buffer / options.extent;
|
|
2721
|
+
let merged = features;
|
|
2722
|
+
const left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options);
|
|
2723
|
+
const right = clip(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
|
|
2724
|
+
if (left || right) {
|
|
2725
|
+
merged = clip(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
|
|
2726
|
+
if (left) {
|
|
2727
|
+
merged = shiftFeatureCoords(left, 1).concat(merged);
|
|
2728
|
+
}
|
|
2729
|
+
if (right) {
|
|
2730
|
+
merged = merged.concat(shiftFeatureCoords(right, -1));
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
return merged;
|
|
2734
|
+
}
|
|
2735
|
+
function shiftFeatureCoords(features, offset) {
|
|
2736
|
+
const newFeatures = [];
|
|
2737
|
+
for (let i2 = 0; i2 < features.length; i2++) {
|
|
2738
|
+
const feature = features[i2];
|
|
2739
|
+
const type = feature.type;
|
|
2740
|
+
let newGeometry;
|
|
2741
|
+
if (type === "Point" || type === "MultiPoint" || type === "LineString") {
|
|
2742
|
+
newGeometry = shiftCoords(feature.geometry, offset);
|
|
2743
|
+
} else if (type === "MultiLineString" || type === "Polygon") {
|
|
2744
|
+
newGeometry = [];
|
|
2745
|
+
for (const line of feature.geometry) {
|
|
2746
|
+
newGeometry.push(shiftCoords(line, offset));
|
|
2747
|
+
}
|
|
2748
|
+
} else if (type === "MultiPolygon") {
|
|
2749
|
+
newGeometry = [];
|
|
2750
|
+
for (const polygon of feature.geometry) {
|
|
2751
|
+
const newPolygon = [];
|
|
2752
|
+
for (const line of polygon) {
|
|
2753
|
+
newPolygon.push(shiftCoords(line, offset));
|
|
2754
|
+
}
|
|
2755
|
+
newGeometry.push(newPolygon);
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags));
|
|
2759
|
+
}
|
|
2760
|
+
return newFeatures;
|
|
2761
|
+
}
|
|
2762
|
+
function shiftCoords(points, offset) {
|
|
2763
|
+
const newPoints = [];
|
|
2764
|
+
newPoints.size = points.size;
|
|
2765
|
+
if (points.start !== void 0) {
|
|
2766
|
+
newPoints.start = points.start;
|
|
2767
|
+
newPoints.end = points.end;
|
|
2768
|
+
}
|
|
2769
|
+
for (let i2 = 0; i2 < points.length; i2 += 3) {
|
|
2770
|
+
newPoints.push(points[i2] + offset, points[i2 + 1], points[i2 + 2]);
|
|
2771
|
+
}
|
|
2772
|
+
return newPoints;
|
|
2773
|
+
}
|
|
2774
|
+
var init_wrap = __esm({
|
|
2775
|
+
"src/lib/geojson-tiler/wrap.ts"() {
|
|
2776
|
+
init_clip();
|
|
2777
|
+
init_feature();
|
|
2778
|
+
}
|
|
2779
|
+
});
|
|
2780
|
+
|
|
2781
|
+
// src/lib/geojson-tiler/transform.ts
|
|
2782
|
+
function transformTile(tile, extent) {
|
|
2783
|
+
if (tile.transformed) {
|
|
2784
|
+
return tile;
|
|
2785
|
+
}
|
|
2786
|
+
const z2 = 1 << tile.z;
|
|
2787
|
+
const tx = tile.x;
|
|
2788
|
+
const ty = tile.y;
|
|
2789
|
+
for (const feature of tile.features) {
|
|
2790
|
+
const geom = feature.geometry;
|
|
2791
|
+
const type = feature.type;
|
|
2792
|
+
feature.geometry = [];
|
|
2793
|
+
if (type === 1) {
|
|
2794
|
+
for (let j = 0; j < geom.length; j += 2) {
|
|
2795
|
+
feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
|
|
2796
|
+
}
|
|
2797
|
+
} else {
|
|
2798
|
+
for (let j = 0; j < geom.length; j++) {
|
|
2799
|
+
const ring = [];
|
|
2800
|
+
for (let k = 0; k < geom[j].length; k += 2) {
|
|
2801
|
+
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
|
|
2802
|
+
}
|
|
2803
|
+
feature.geometry.push(ring);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
tile.transformed = true;
|
|
2808
|
+
return tile;
|
|
2809
|
+
}
|
|
2810
|
+
function transformPoint(x2, y2, extent, z2, tx, ty) {
|
|
2811
|
+
return [Math.round(extent * (x2 * z2 - tx)), Math.round(extent * (y2 * z2 - ty))];
|
|
2812
|
+
}
|
|
2813
|
+
var init_transform = __esm({
|
|
2814
|
+
"src/lib/geojson-tiler/transform.ts"() {
|
|
2815
|
+
}
|
|
2816
|
+
});
|
|
2817
|
+
|
|
2818
|
+
// src/lib/geojson-tiler/tile.ts
|
|
2819
|
+
function createTile(features, z, tx, ty, options) {
|
|
2820
|
+
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
2821
|
+
const tile = {
|
|
2822
|
+
features: [],
|
|
2823
|
+
numPoints: 0,
|
|
2824
|
+
numSimplified: 0,
|
|
2825
|
+
numFeatures: features.length,
|
|
2826
|
+
source: null,
|
|
2827
|
+
x: tx,
|
|
2828
|
+
y: ty,
|
|
2829
|
+
z,
|
|
2830
|
+
transformed: false,
|
|
2831
|
+
minX: 2,
|
|
2832
|
+
minY: 1,
|
|
2833
|
+
maxX: -1,
|
|
2834
|
+
maxY: 0
|
|
2835
|
+
};
|
|
2836
|
+
for (const feature of features) {
|
|
2837
|
+
addFeature(tile, feature, tolerance, options);
|
|
2838
|
+
}
|
|
2839
|
+
return tile;
|
|
2840
|
+
}
|
|
2841
|
+
function addFeature(tile, feature, tolerance, options) {
|
|
2842
|
+
const geom = feature.geometry;
|
|
2843
|
+
const type = feature.type;
|
|
2844
|
+
const simplified = [];
|
|
2845
|
+
tile.minX = Math.min(tile.minX, feature.minX);
|
|
2846
|
+
tile.minY = Math.min(tile.minY, feature.minY);
|
|
2847
|
+
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
2848
|
+
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
2849
|
+
if (type === "Point" || type === "MultiPoint") {
|
|
2850
|
+
for (let i2 = 0; i2 < geom.length; i2 += 3) {
|
|
2851
|
+
simplified.push(geom[i2], geom[i2 + 1]);
|
|
2852
|
+
tile.numPoints++;
|
|
2853
|
+
tile.numSimplified++;
|
|
2854
|
+
}
|
|
2855
|
+
} else if (type === "LineString") {
|
|
2856
|
+
addLine(simplified, geom, tile, tolerance, false, false);
|
|
2857
|
+
} else if (type === "MultiLineString" || type === "Polygon") {
|
|
2858
|
+
for (let i2 = 0; i2 < geom.length; i2++) {
|
|
2859
|
+
addLine(simplified, geom[i2], tile, tolerance, type === "Polygon", i2 === 0);
|
|
2860
|
+
}
|
|
2861
|
+
} else if (type === "MultiPolygon") {
|
|
2862
|
+
for (let k = 0; k < geom.length; k++) {
|
|
2863
|
+
const polygon = geom[k];
|
|
2864
|
+
for (let i2 = 0; i2 < polygon.length; i2++) {
|
|
2865
|
+
addLine(simplified, polygon[i2], tile, tolerance, true, i2 === 0);
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
if (simplified.length) {
|
|
2870
|
+
let tags = feature.tags || null;
|
|
2871
|
+
if (type === "LineString" && options.lineMetrics) {
|
|
2872
|
+
tags = {};
|
|
2873
|
+
for (const key in feature.tags)
|
|
2874
|
+
tags[key] = feature.tags[key];
|
|
2875
|
+
tags.mapbox_clip_start = geom.start / geom.size;
|
|
2876
|
+
tags.mapbox_clip_end = geom.end / geom.size;
|
|
2877
|
+
}
|
|
2878
|
+
const tileFeature = {
|
|
2879
|
+
geometry: simplified,
|
|
2880
|
+
type: type === "Polygon" || type === "MultiPolygon" ? 3 : type === "LineString" || type === "MultiLineString" ? 2 : 1,
|
|
2881
|
+
tags
|
|
2882
|
+
};
|
|
2883
|
+
if (feature.id !== null) {
|
|
2884
|
+
tileFeature.id = feature.id;
|
|
2885
|
+
}
|
|
2886
|
+
tile.features.push(tileFeature);
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
|
|
2890
|
+
const sqTolerance = tolerance * tolerance;
|
|
2891
|
+
if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
2892
|
+
tile.numPoints += geom.length / 3;
|
|
2893
|
+
return;
|
|
2894
|
+
}
|
|
2895
|
+
const ring = [];
|
|
2896
|
+
for (let i2 = 0; i2 < geom.length; i2 += 3) {
|
|
2897
|
+
if (tolerance === 0 || geom[i2 + 2] > sqTolerance) {
|
|
2898
|
+
tile.numSimplified++;
|
|
2899
|
+
ring.push(geom[i2], geom[i2 + 1]);
|
|
2900
|
+
}
|
|
2901
|
+
tile.numPoints++;
|
|
2902
|
+
}
|
|
2903
|
+
if (isPolygon)
|
|
2904
|
+
rewind(ring, isOuter);
|
|
2905
|
+
result.push(ring);
|
|
2906
|
+
}
|
|
2907
|
+
function rewind(ring, clockwise) {
|
|
2908
|
+
let area2 = 0;
|
|
2909
|
+
for (let i2 = 0, j = ring.length - 2; i2 < ring.length; j = i2, i2 += 2) {
|
|
2910
|
+
area2 += (ring[i2] - ring[j]) * (ring[i2 + 1] + ring[j + 1]);
|
|
2911
|
+
}
|
|
2912
|
+
if (area2 > 0 === clockwise) {
|
|
2913
|
+
for (let i2 = 0, len = ring.length; i2 < len / 2; i2 += 2) {
|
|
2914
|
+
const x2 = ring[i2];
|
|
2915
|
+
const y2 = ring[i2 + 1];
|
|
2916
|
+
ring[i2] = ring[len - 2 - i2];
|
|
2917
|
+
ring[i2 + 1] = ring[len - 1 - i2];
|
|
2918
|
+
ring[len - 2 - i2] = x2;
|
|
2919
|
+
ring[len - 1 - i2] = y2;
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
var init_tile = __esm({
|
|
2924
|
+
"src/lib/geojson-tiler/tile.ts"() {
|
|
2925
|
+
}
|
|
2926
|
+
});
|
|
2927
|
+
|
|
2928
|
+
// src/lib/geojson-tiler/geojson-tiler.ts
|
|
2929
|
+
function toID(z, x2, y2) {
|
|
2930
|
+
return ((1 << z) * y2 + x2) * 32 + z;
|
|
2931
|
+
}
|
|
2932
|
+
var DEFAULT_OPTIONS, GeoJSONTiler;
|
|
2933
|
+
var init_geojson_tiler = __esm({
|
|
2934
|
+
"src/lib/geojson-tiler/geojson-tiler.ts"() {
|
|
2935
|
+
init_convert();
|
|
2936
|
+
init_clip();
|
|
2937
|
+
init_wrap();
|
|
2938
|
+
init_transform();
|
|
2939
|
+
init_tile();
|
|
2940
|
+
DEFAULT_OPTIONS = {
|
|
2941
|
+
maxZoom: 14,
|
|
2942
|
+
indexMaxZoom: 5,
|
|
2943
|
+
indexMaxPoints: 1e5,
|
|
2944
|
+
tolerance: 3,
|
|
2945
|
+
extent: 4096,
|
|
2946
|
+
buffer: 64,
|
|
2947
|
+
lineMetrics: false,
|
|
2948
|
+
promoteId: void 0,
|
|
2949
|
+
generateId: false,
|
|
2950
|
+
debug: 0
|
|
2951
|
+
};
|
|
2952
|
+
GeoJSONTiler = class {
|
|
2953
|
+
constructor(data, options) {
|
|
2954
|
+
this.tiles = {};
|
|
2955
|
+
this.tileCoords = [];
|
|
2956
|
+
this.stats = {};
|
|
2957
|
+
this.total = 0;
|
|
2958
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
2959
|
+
options = this.options;
|
|
2960
|
+
const debug = options.debug;
|
|
2961
|
+
if (debug)
|
|
2962
|
+
console.time("preprocess data");
|
|
2963
|
+
if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
|
|
2964
|
+
throw new Error("maxZoom should be in the 0-24 range");
|
|
2965
|
+
}
|
|
2966
|
+
if (options.promoteId && this.options.generateId) {
|
|
2967
|
+
throw new Error("promoteId and generateId cannot be used together.");
|
|
2968
|
+
}
|
|
2969
|
+
let features = convert(data, options);
|
|
2970
|
+
if (debug) {
|
|
2971
|
+
console.timeEnd("preprocess data");
|
|
2972
|
+
console.log("index: maxZoom: %d, maxPoints: %d", options.indexMaxZoom, options.indexMaxPoints);
|
|
2973
|
+
console.time("generate tiles");
|
|
2974
|
+
}
|
|
2975
|
+
features = wrap(features, this.options);
|
|
2976
|
+
if (features.length) {
|
|
2977
|
+
this.splitTile(features, 0, 0, 0);
|
|
2978
|
+
}
|
|
2979
|
+
if (debug) {
|
|
2980
|
+
if (features.length) {
|
|
2981
|
+
console.log("features: %d, points: %d", this.tiles[0].numFeatures, this.tiles[0].numPoints);
|
|
2982
|
+
}
|
|
2983
|
+
console.timeEnd("generate tiles");
|
|
2984
|
+
console.log("tiles generated:", this.total, JSON.stringify(this.stats));
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
getTile(z, x2, y2) {
|
|
2988
|
+
const { extent, debug } = this.options;
|
|
2989
|
+
if (z < 0 || z > 24) {
|
|
2990
|
+
return null;
|
|
2991
|
+
}
|
|
2992
|
+
const z2 = 1 << z;
|
|
2993
|
+
x2 = x2 + z2 & z2 - 1;
|
|
2994
|
+
const id = toID(z, x2, y2);
|
|
2995
|
+
if (this.tiles[id]) {
|
|
2996
|
+
return transformTile(this.tiles[id], extent);
|
|
2997
|
+
}
|
|
2998
|
+
if (debug > 1)
|
|
2999
|
+
console.log("drilling down to z%d-%d-%d", z, x2, y2);
|
|
3000
|
+
let z0 = z;
|
|
3001
|
+
let x0 = x2;
|
|
3002
|
+
let y0 = y2;
|
|
3003
|
+
let parent;
|
|
3004
|
+
while (!parent && z0 > 0) {
|
|
3005
|
+
z0--;
|
|
3006
|
+
x0 = x0 >> 1;
|
|
3007
|
+
y0 = y0 >> 1;
|
|
3008
|
+
parent = this.tiles[toID(z0, x0, y0)];
|
|
3009
|
+
}
|
|
3010
|
+
if (!parent || !parent.source) {
|
|
3011
|
+
return null;
|
|
3012
|
+
}
|
|
3013
|
+
if (debug > 1) {
|
|
3014
|
+
console.log("found parent tile z%d-%d-%d", z0, x0, y0);
|
|
3015
|
+
console.time("drilling down");
|
|
3016
|
+
}
|
|
3017
|
+
this.splitTile(parent.source, z0, x0, y0, z, x2, y2);
|
|
3018
|
+
if (debug > 1) {
|
|
3019
|
+
console.timeEnd("drilling down");
|
|
3020
|
+
}
|
|
3021
|
+
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
|
|
3022
|
+
}
|
|
3023
|
+
splitTile(features, z, x2, y2, cz, cx, cy) {
|
|
3024
|
+
const stack = [features, z, x2, y2];
|
|
3025
|
+
const options = this.options;
|
|
3026
|
+
const debug = options.debug;
|
|
3027
|
+
while (stack.length) {
|
|
3028
|
+
y2 = stack.pop();
|
|
3029
|
+
x2 = stack.pop();
|
|
3030
|
+
z = stack.pop();
|
|
3031
|
+
features = stack.pop();
|
|
3032
|
+
const z2 = 1 << z;
|
|
3033
|
+
const id = toID(z, x2, y2);
|
|
3034
|
+
let tile = this.tiles[id];
|
|
3035
|
+
if (!tile) {
|
|
3036
|
+
if (debug > 1) {
|
|
3037
|
+
console.time("creation");
|
|
3038
|
+
}
|
|
3039
|
+
tile = this.tiles[id] = createTile(features, z, x2, y2, options);
|
|
3040
|
+
this.tileCoords.push({ z, x: x2, y: y2 });
|
|
3041
|
+
if (debug) {
|
|
3042
|
+
if (debug > 1) {
|
|
3043
|
+
console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x2, y2, tile.numFeatures, tile.numPoints, tile.numSimplified);
|
|
3044
|
+
console.timeEnd("creation");
|
|
3045
|
+
}
|
|
3046
|
+
const key = `z${z}`;
|
|
3047
|
+
this.stats[key] = (this.stats[key] || 0) + 1;
|
|
3048
|
+
this.total++;
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
tile.source = features;
|
|
3052
|
+
if (cz === void 0) {
|
|
3053
|
+
if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
|
|
3054
|
+
continue;
|
|
3055
|
+
} else if (z === options.maxZoom || z === cz) {
|
|
3056
|
+
continue;
|
|
3057
|
+
} else if (cz !== void 0) {
|
|
3058
|
+
const zoomSteps = cz - z;
|
|
3059
|
+
if (x2 !== cx >> zoomSteps || y2 !== cy >> zoomSteps)
|
|
3060
|
+
continue;
|
|
3061
|
+
}
|
|
3062
|
+
tile.source = null;
|
|
3063
|
+
if (features.length === 0)
|
|
3064
|
+
continue;
|
|
3065
|
+
if (debug > 1)
|
|
3066
|
+
console.time("clipping");
|
|
3067
|
+
const k1 = 0.5 * options.buffer / options.extent;
|
|
3068
|
+
const k2 = 0.5 - k1;
|
|
3069
|
+
const k3 = 0.5 + k1;
|
|
3070
|
+
const k4 = 1 + k1;
|
|
3071
|
+
let tl = null;
|
|
3072
|
+
let bl = null;
|
|
3073
|
+
let tr = null;
|
|
3074
|
+
let br = null;
|
|
3075
|
+
let left = clip(features, z2, x2 - k1, x2 + k3, 0, tile.minX, tile.maxX, options);
|
|
3076
|
+
let right = clip(features, z2, x2 + k2, x2 + k4, 0, tile.minX, tile.maxX, options);
|
|
3077
|
+
features = null;
|
|
3078
|
+
if (left) {
|
|
3079
|
+
tl = clip(left, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
|
|
3080
|
+
bl = clip(left, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
|
|
3081
|
+
left = null;
|
|
3082
|
+
}
|
|
3083
|
+
if (right) {
|
|
3084
|
+
tr = clip(right, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
|
|
3085
|
+
br = clip(right, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
|
|
3086
|
+
right = null;
|
|
3087
|
+
}
|
|
3088
|
+
if (debug > 1)
|
|
3089
|
+
console.timeEnd("clipping");
|
|
3090
|
+
stack.push(tl || [], z + 1, x2 * 2, y2 * 2);
|
|
3091
|
+
stack.push(bl || [], z + 1, x2 * 2, y2 * 2 + 1);
|
|
3092
|
+
stack.push(tr || [], z + 1, x2 * 2 + 1, y2 * 2);
|
|
3093
|
+
stack.push(br || [], z + 1, x2 * 2 + 1, y2 * 2 + 1);
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
};
|
|
3097
|
+
}
|
|
3098
|
+
});
|
|
3099
|
+
|
|
2267
3100
|
// src/index.ts
|
|
2268
3101
|
var src_exports = {};
|
|
2269
3102
|
__export(src_exports, {
|
|
3103
|
+
GeoJSONTiler: () => GeoJSONTiler,
|
|
2270
3104
|
MVTLoader: () => MVTLoader,
|
|
2271
3105
|
MVTWorkerLoader: () => MVTWorkerLoader
|
|
2272
3106
|
});
|
|
2273
3107
|
var init_src2 = __esm({
|
|
2274
3108
|
"src/index.ts"() {
|
|
2275
3109
|
init_mvt_loader();
|
|
3110
|
+
init_geojson_tiler();
|
|
2276
3111
|
}
|
|
2277
3112
|
});
|
|
2278
3113
|
|