@loaders.gl/mvt 4.2.0 → 4.3.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +1311 -767
- package/dist/dist.min.js +1 -1
- package/dist/geojson-tile-source.d.ts +79 -0
- package/dist/geojson-tile-source.d.ts.map +1 -0
- package/dist/{lib/geojson-tiler/geojson-tiler.js → geojson-tile-source.js} +137 -27
- package/dist/index.cjs +570 -560
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/geojsonvt/clip.d.ts.map +1 -0
- package/dist/lib/geojsonvt/convert.d.ts +10 -0
- package/dist/lib/geojsonvt/convert.d.ts.map +1 -0
- package/dist/lib/geojsonvt/feature.d.ts.map +1 -0
- package/dist/lib/geojsonvt/simplify.d.ts.map +1 -0
- package/dist/lib/geojsonvt/tile.d.ts.map +1 -0
- package/dist/lib/geojsonvt/transform.d.ts.map +1 -0
- package/dist/lib/geojsonvt/wrap.d.ts.map +1 -0
- package/dist/lib/parse-mvt.d.ts +3 -2
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +13 -15
- package/dist/lib/types.d.ts +1 -39
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/utils/geometry-utils.d.ts +46 -0
- package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
- package/dist/{helpers/binary-util-functions.js → lib/utils/geometry-utils.js} +79 -46
- package/dist/lib/{binary-vector-tile → vector-tile}/vector-tile-feature.d.ts +27 -15
- package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/vector-tile/vector-tile-feature.js +345 -0
- package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.d.ts +10 -1
- package/dist/lib/vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.js +16 -1
- package/dist/lib/vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/mvt-loader.d.ts +20 -9
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +3 -2
- package/dist/mvt-source.js +4 -4
- package/dist/mvt-worker.js +1172 -735
- package/dist/tilejson-loader.js +1 -1
- package/package.json +6 -6
- package/src/{lib/geojson-tiler/geojson-tiler.ts → geojson-tile-source.ts} +172 -33
- package/src/index.ts +3 -3
- package/src/lib/{geojson-tiler → geojsonvt}/convert.ts +2 -2
- package/src/lib/{geojson-tiler → geojsonvt}/tile.ts +2 -2
- package/src/lib/parse-mvt.ts +24 -33
- package/src/lib/types.ts +1 -39
- package/src/{helpers/binary-util-functions.ts → lib/utils/geometry-utils.ts} +92 -48
- package/src/lib/vector-tile/vector-tile-feature.ts +407 -0
- package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.ts +28 -2
- package/src/mvt-loader.ts +14 -6
- package/src/mvt-source.ts +4 -4
- package/dist/helpers/binary-util-functions.d.ts +0 -35
- package/dist/helpers/binary-util-functions.d.ts.map +0 -1
- package/dist/helpers/mapbox-util-functions.d.ts +0 -29
- package/dist/helpers/mapbox-util-functions.d.ts.map +0 -1
- package/dist/helpers/mapbox-util-functions.js +0 -78
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -163
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -23
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -96
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +0 -9
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile.js +0 -27
- package/dist/lib/geojson-tiler/clip.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/convert.d.ts +0 -10
- package/dist/lib/geojson-tiler/convert.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/feature.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts +0 -44
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/simplify.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/tile.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/transform.d.ts.map +0 -1
- package/dist/lib/geojson-tiler/wrap.d.ts.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -27
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -178
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +0 -1
- package/src/helpers/mapbox-util-functions.ts +0 -82
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +0 -203
- package/src/lib/binary-vector-tile/vector-tile-layer.ts +0 -113
- package/src/lib/binary-vector-tile/vector-tile.ts +0 -36
- package/src/lib/mapbox-vector-tile/LICENSE.txt +0 -31
- package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +0 -207
- /package/dist/lib/{geojson-tiler → geojsonvt}/clip.d.ts +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/clip.js +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/convert.js +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/feature.d.ts +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/feature.js +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/simplify.d.ts +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/simplify.js +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/tile.d.ts +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/tile.js +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/transform.d.ts +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/transform.js +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/wrap.d.ts +0 -0
- /package/dist/lib/{geojson-tiler → geojsonvt}/wrap.js +0 -0
- /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.d.ts +0 -0
- /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.js +0 -0
- /package/src/lib/{geojson-tiler → geojsonvt}/LICENSE +0 -0
- /package/src/lib/{geojson-tiler → geojsonvt}/clip.ts +0 -0
- /package/src/lib/{geojson-tiler → geojsonvt}/feature.ts +0 -0
- /package/src/lib/{geojson-tiler → geojsonvt}/simplify.ts +0 -0
- /package/src/lib/{geojson-tiler → geojsonvt}/transform.ts +0 -0
- /package/src/lib/{geojson-tiler → geojsonvt}/wrap.ts +0 -0
- /package/src/lib/{binary-vector-tile → vector-tile}/LICENSE.txt +0 -0
- /package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile.ts +0 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
import { classifyRings, classifyRingsFlat, projectToLngLatFlat } from "../utils/geometry-utils.js";
|
|
5
|
+
export class VectorTileFeature {
|
|
6
|
+
properties;
|
|
7
|
+
extent;
|
|
8
|
+
type;
|
|
9
|
+
id;
|
|
10
|
+
_pbf;
|
|
11
|
+
_geometry;
|
|
12
|
+
_keys;
|
|
13
|
+
_values;
|
|
14
|
+
_geometryInfo;
|
|
15
|
+
static types = ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
16
|
+
// eslint-disable-next-line max-params
|
|
17
|
+
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
18
|
+
// Public
|
|
19
|
+
this.properties = {};
|
|
20
|
+
this.extent = extent;
|
|
21
|
+
this.type = 0;
|
|
22
|
+
this.id = null;
|
|
23
|
+
// Private
|
|
24
|
+
this._pbf = pbf;
|
|
25
|
+
this._geometry = -1;
|
|
26
|
+
this._keys = keys;
|
|
27
|
+
this._values = values;
|
|
28
|
+
// Only used by binary tiles
|
|
29
|
+
this._geometryInfo = geometryInfo;
|
|
30
|
+
pbf.readFields(readFeature, this, end);
|
|
31
|
+
}
|
|
32
|
+
toGeoJSON(options) {
|
|
33
|
+
const coords = this.loadGeometry();
|
|
34
|
+
if (typeof options === 'function') {
|
|
35
|
+
return _toGeoJSON(this, coords, options);
|
|
36
|
+
}
|
|
37
|
+
const { x, y, z } = options;
|
|
38
|
+
const size = this.extent * Math.pow(2, z);
|
|
39
|
+
const x0 = this.extent * x;
|
|
40
|
+
const y0 = this.extent * y;
|
|
41
|
+
function project(line) {
|
|
42
|
+
for (let j = 0; j < line.length; j++) {
|
|
43
|
+
const p = line[j];
|
|
44
|
+
p[0] = ((p[0] + x0) * 360) / size - 180;
|
|
45
|
+
const y2 = 180 - ((p[1] + y0) * 360) / size;
|
|
46
|
+
p[1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return _toGeoJSON(this, coords, project);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param options
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
toBinaryCoordinates(options) {
|
|
57
|
+
if (typeof options === 'function') {
|
|
58
|
+
return this._toBinaryCoordinates(options);
|
|
59
|
+
}
|
|
60
|
+
const tileIndex = options;
|
|
61
|
+
return this._toBinaryCoordinates((data) => projectToLngLatFlat(data, tileIndex, this.extent));
|
|
62
|
+
}
|
|
63
|
+
// eslint-disable-next-line max-statements
|
|
64
|
+
bbox() {
|
|
65
|
+
const pbf = this._pbf;
|
|
66
|
+
pbf.pos = this._geometry;
|
|
67
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
68
|
+
let cmd = 1;
|
|
69
|
+
let length = 0;
|
|
70
|
+
let x = 0;
|
|
71
|
+
let y = 0;
|
|
72
|
+
let x1 = Infinity;
|
|
73
|
+
let x2 = -Infinity;
|
|
74
|
+
let y1 = Infinity;
|
|
75
|
+
let y2 = -Infinity;
|
|
76
|
+
while (pbf.pos < end) {
|
|
77
|
+
if (length <= 0) {
|
|
78
|
+
const cmdLen = pbf.readVarint();
|
|
79
|
+
cmd = cmdLen & 0x7;
|
|
80
|
+
length = cmdLen >> 3;
|
|
81
|
+
}
|
|
82
|
+
length--;
|
|
83
|
+
if (cmd === 1 || cmd === 2) {
|
|
84
|
+
x += pbf.readSVarint();
|
|
85
|
+
y += pbf.readSVarint();
|
|
86
|
+
if (x < x1)
|
|
87
|
+
x1 = x;
|
|
88
|
+
if (x > x2)
|
|
89
|
+
x2 = x;
|
|
90
|
+
if (y < y1)
|
|
91
|
+
y1 = y;
|
|
92
|
+
if (y > y2)
|
|
93
|
+
y2 = y;
|
|
94
|
+
}
|
|
95
|
+
else if (cmd !== 7) {
|
|
96
|
+
throw new Error(`unknown command ${cmd}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return [x1, y1, x2, y2];
|
|
100
|
+
}
|
|
101
|
+
// BINARY HELPERS
|
|
102
|
+
/**
|
|
103
|
+
*
|
|
104
|
+
* @param transform
|
|
105
|
+
* @returns result
|
|
106
|
+
*/
|
|
107
|
+
_toBinaryCoordinates(transform) {
|
|
108
|
+
// Expands the protobuf data to an intermediate Flat GeoJSON
|
|
109
|
+
// data format, which maps closely to the binary data buffers.
|
|
110
|
+
// It is similar to GeoJSON, but rather than storing the coordinates
|
|
111
|
+
// in multidimensional arrays, we have a 1D `data` with all the
|
|
112
|
+
// coordinates, and then index into this using the `indices`
|
|
113
|
+
// parameter, e.g.
|
|
114
|
+
//
|
|
115
|
+
// geometry: {
|
|
116
|
+
// type: 'Point', data: [1,2], indices: [0]
|
|
117
|
+
// }
|
|
118
|
+
// geometry: {
|
|
119
|
+
// type: 'LineString', data: [1,2,3,4,...], indices: [0]
|
|
120
|
+
// }
|
|
121
|
+
// geometry: {
|
|
122
|
+
// type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
|
|
123
|
+
// }
|
|
124
|
+
// Thus the indices member lets us look up the relevant range
|
|
125
|
+
// from the data array.
|
|
126
|
+
// The Multi* versions of the above types share the same data
|
|
127
|
+
// structure, just with multiple elements in the indices array
|
|
128
|
+
const geom = this.loadFlatGeometry();
|
|
129
|
+
let geometry;
|
|
130
|
+
// Apply the supplied transformation to data
|
|
131
|
+
transform(geom.data, this);
|
|
132
|
+
const coordLength = 2;
|
|
133
|
+
// eslint-disable-next-line default-case
|
|
134
|
+
switch (this.type) {
|
|
135
|
+
case 1: // Point
|
|
136
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
137
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
138
|
+
geometry = { type: 'Point', ...geom };
|
|
139
|
+
break;
|
|
140
|
+
case 2: // LineString
|
|
141
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
142
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
143
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
144
|
+
geometry = { type: 'LineString', ...geom };
|
|
145
|
+
break;
|
|
146
|
+
case 3: // Polygon
|
|
147
|
+
geometry = classifyRingsFlat(geom);
|
|
148
|
+
// Unlike Point & LineString geom.indices is a 2D array, thanks
|
|
149
|
+
// to the classifyRings method
|
|
150
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
151
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
152
|
+
for (const indices of geometry.indices) {
|
|
153
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
154
|
+
}
|
|
155
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
159
|
+
}
|
|
160
|
+
const result = { type: 'Feature', geometry, properties: this.properties };
|
|
161
|
+
if (this.id !== null) {
|
|
162
|
+
result.id = this.id;
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
// GEOJSON HELPER
|
|
167
|
+
// eslint-disable-next-line complexity, max-statements
|
|
168
|
+
loadGeometry() {
|
|
169
|
+
const pbf = this._pbf;
|
|
170
|
+
pbf.pos = this._geometry;
|
|
171
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
172
|
+
let cmd = 1;
|
|
173
|
+
let length = 0;
|
|
174
|
+
let x = 0;
|
|
175
|
+
let y = 0;
|
|
176
|
+
const lines = [];
|
|
177
|
+
let line;
|
|
178
|
+
while (pbf.pos < end) {
|
|
179
|
+
if (length <= 0) {
|
|
180
|
+
const cmdLen = pbf.readVarint();
|
|
181
|
+
cmd = cmdLen & 0x7;
|
|
182
|
+
length = cmdLen >> 3;
|
|
183
|
+
}
|
|
184
|
+
length--;
|
|
185
|
+
switch (cmd) {
|
|
186
|
+
case 1:
|
|
187
|
+
case 2:
|
|
188
|
+
x += pbf.readSVarint();
|
|
189
|
+
y += pbf.readSVarint();
|
|
190
|
+
if (cmd === 1) {
|
|
191
|
+
// moveTo
|
|
192
|
+
if (line)
|
|
193
|
+
lines.push(line);
|
|
194
|
+
line = [];
|
|
195
|
+
}
|
|
196
|
+
if (line)
|
|
197
|
+
line.push([x, y]);
|
|
198
|
+
break;
|
|
199
|
+
case 7:
|
|
200
|
+
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
201
|
+
if (line) {
|
|
202
|
+
line.push(line[0].slice()); // closePolygon
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
default:
|
|
206
|
+
throw new Error(`unknown command ${cmd}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (line)
|
|
210
|
+
lines.push(line);
|
|
211
|
+
return lines;
|
|
212
|
+
}
|
|
213
|
+
// eslint-disable-next-line complexity, max-statements
|
|
214
|
+
loadFlatGeometry() {
|
|
215
|
+
const pbf = this._pbf;
|
|
216
|
+
pbf.pos = this._geometry;
|
|
217
|
+
const endPos = pbf.readVarint() + pbf.pos;
|
|
218
|
+
let cmd = 1;
|
|
219
|
+
let cmdLen;
|
|
220
|
+
let length = 0;
|
|
221
|
+
let x = 0;
|
|
222
|
+
let y = 0;
|
|
223
|
+
let i = 0;
|
|
224
|
+
// Note: I attempted to replace the `data` array with a
|
|
225
|
+
// Float32Array, but performance was worse, both using
|
|
226
|
+
// `set()` and direct index access. Also, we cannot
|
|
227
|
+
// know how large the buffer should be, so it would
|
|
228
|
+
// increase memory usage
|
|
229
|
+
const indices = []; // Indices where geometries start
|
|
230
|
+
const data = []; // Flat array of coordinate data
|
|
231
|
+
while (pbf.pos < endPos) {
|
|
232
|
+
if (length <= 0) {
|
|
233
|
+
cmdLen = pbf.readVarint();
|
|
234
|
+
cmd = cmdLen & 0x7;
|
|
235
|
+
length = cmdLen >> 3;
|
|
236
|
+
}
|
|
237
|
+
length--;
|
|
238
|
+
if (cmd === 1 || cmd === 2) {
|
|
239
|
+
x += pbf.readSVarint();
|
|
240
|
+
y += pbf.readSVarint();
|
|
241
|
+
if (cmd === 1) {
|
|
242
|
+
// New line
|
|
243
|
+
indices.push(i);
|
|
244
|
+
}
|
|
245
|
+
data.push(x, y);
|
|
246
|
+
i += 2;
|
|
247
|
+
}
|
|
248
|
+
else if (cmd === 7) {
|
|
249
|
+
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
250
|
+
if (i > 0) {
|
|
251
|
+
const start = indices[indices.length - 1]; // start index of polygon
|
|
252
|
+
data.push(data[start], data[start + 1]); // closePolygon
|
|
253
|
+
i += 2;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
throw new Error(`unknown command ${cmd}`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return { data, indices };
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function _toGeoJSON(vtFeature, coords, transform) {
|
|
264
|
+
let type = VectorTileFeature.types[vtFeature.type];
|
|
265
|
+
let i;
|
|
266
|
+
let j;
|
|
267
|
+
let coordinates;
|
|
268
|
+
switch (vtFeature.type) {
|
|
269
|
+
case 1:
|
|
270
|
+
const points = [];
|
|
271
|
+
for (i = 0; i < coords.length; i++) {
|
|
272
|
+
points[i] = coords[i][0];
|
|
273
|
+
}
|
|
274
|
+
coordinates = points;
|
|
275
|
+
transform(coordinates, vtFeature);
|
|
276
|
+
break;
|
|
277
|
+
case 2:
|
|
278
|
+
coordinates = coords;
|
|
279
|
+
for (i = 0; i < coordinates.length; i++) {
|
|
280
|
+
transform(coordinates[i], vtFeature);
|
|
281
|
+
}
|
|
282
|
+
break;
|
|
283
|
+
case 3:
|
|
284
|
+
coordinates = classifyRings(coords);
|
|
285
|
+
for (i = 0; i < coordinates.length; i++) {
|
|
286
|
+
for (j = 0; j < coordinates[i].length; j++) {
|
|
287
|
+
transform(coordinates[i][j], vtFeature);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
break;
|
|
291
|
+
default:
|
|
292
|
+
throw new Error('illegal vector tile type');
|
|
293
|
+
}
|
|
294
|
+
if (coordinates.length === 1) {
|
|
295
|
+
// @ts-expect-error
|
|
296
|
+
coordinates = coordinates[0];
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
type = `Multi${type}`;
|
|
300
|
+
}
|
|
301
|
+
const result = {
|
|
302
|
+
type: 'Feature',
|
|
303
|
+
geometry: {
|
|
304
|
+
type: type,
|
|
305
|
+
coordinates: coordinates
|
|
306
|
+
},
|
|
307
|
+
properties: vtFeature.properties
|
|
308
|
+
};
|
|
309
|
+
if (vtFeature.id !== null) {
|
|
310
|
+
result.id = vtFeature.id;
|
|
311
|
+
}
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
// PBF READER UTILS
|
|
315
|
+
/**
|
|
316
|
+
*
|
|
317
|
+
* @param tag
|
|
318
|
+
* @param feature
|
|
319
|
+
* @param pbf
|
|
320
|
+
*/
|
|
321
|
+
function readFeature(tag, feature, pbf) {
|
|
322
|
+
if (feature && pbf) {
|
|
323
|
+
if (tag === 1)
|
|
324
|
+
feature.id = pbf.readVarint();
|
|
325
|
+
else if (tag === 2)
|
|
326
|
+
readTag(pbf, feature);
|
|
327
|
+
else if (tag === 3)
|
|
328
|
+
feature.type = pbf.readVarint();
|
|
329
|
+
else if (tag === 4)
|
|
330
|
+
feature._geometry = pbf.pos;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
*
|
|
335
|
+
* @param pbf
|
|
336
|
+
* @param feature
|
|
337
|
+
*/
|
|
338
|
+
function readTag(pbf, feature) {
|
|
339
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
340
|
+
while (pbf.pos < end) {
|
|
341
|
+
const key = feature._keys[pbf.readVarint()];
|
|
342
|
+
const value = feature._values[pbf.readVarint()];
|
|
343
|
+
feature.properties[key] = value;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Protobuf from 'pbf';
|
|
2
2
|
import { VectorTileFeature } from "./vector-tile-feature.js";
|
|
3
|
+
import { GeojsonGeometryInfo } from '@loaders.gl/schema';
|
|
3
4
|
export declare class VectorTileLayer {
|
|
4
5
|
version: number;
|
|
5
6
|
name: string;
|
|
@@ -15,6 +16,14 @@ export declare class VectorTileLayer {
|
|
|
15
16
|
* @param index
|
|
16
17
|
* @returns feature
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
+
getGeoJSONFeature(i: number): VectorTileFeature;
|
|
20
|
+
/**
|
|
21
|
+
* return binary feature `i` from this layer as a `VectorTileFeature`
|
|
22
|
+
*
|
|
23
|
+
* @param index
|
|
24
|
+
* @param geometryInfo
|
|
25
|
+
* @returns binary feature
|
|
26
|
+
*/
|
|
27
|
+
getBinaryFeature(i: number, geometryInfo: GeojsonGeometryInfo): VectorTileFeature;
|
|
19
28
|
}
|
|
20
29
|
//# sourceMappingURL=vector-tile-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAOA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,iBAAiB,EAAC,iCAA8B;AACxD,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAEvD,qBAAa,eAAe;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,SAAS,EAAE,MAAM,EAAE,CAAC;gBAER,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM;IAkBtC;;;;OAIG;IACH,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,iBAAiB;IAW/C;;;;;;OAMG;IACH,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,mBAAmB,GAAG,iBAAiB;CAiBlF"}
|
|
@@ -30,7 +30,7 @@ export class VectorTileLayer {
|
|
|
30
30
|
* @param index
|
|
31
31
|
* @returns feature
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
getGeoJSONFeature(i) {
|
|
34
34
|
if (i < 0 || i >= this._features.length) {
|
|
35
35
|
throw new Error('feature index out of bounds');
|
|
36
36
|
}
|
|
@@ -38,6 +38,21 @@ export class VectorTileLayer {
|
|
|
38
38
|
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
39
39
|
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* return binary feature `i` from this layer as a `VectorTileFeature`
|
|
43
|
+
*
|
|
44
|
+
* @param index
|
|
45
|
+
* @param geometryInfo
|
|
46
|
+
* @returns binary feature
|
|
47
|
+
*/
|
|
48
|
+
getBinaryFeature(i, geometryInfo) {
|
|
49
|
+
if (i < 0 || i >= this._features.length) {
|
|
50
|
+
throw new Error('feature index out of bounds');
|
|
51
|
+
}
|
|
52
|
+
this._pbf.pos = this._features[i];
|
|
53
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
54
|
+
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
55
|
+
}
|
|
41
56
|
}
|
|
42
57
|
/**
|
|
43
58
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tile/vector-tile.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,eAAe,EAAC,+BAA4B;AACpD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,qBAAa,UAAU;IACrB,MAAM,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;KAAC,CAAC;gBAC3B,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM;CAGxC"}
|
package/dist/mvt-loader.d.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import type { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
import { parseMVT } from "./lib/parse-mvt.js";
|
|
3
|
-
import type { MVTOptions } from "./lib/types.js";
|
|
4
3
|
export type MVTLoaderOptions = LoaderOptions & {
|
|
5
|
-
mvt?:
|
|
4
|
+
mvt?: {
|
|
5
|
+
/** Shape of returned data */
|
|
6
|
+
shape?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
7
|
+
/** `wgs84`: coordinates in long, lat (`tileIndex` must be provided. `local` coordinates are `0-1` from tile origin */
|
|
8
|
+
coordinates?: 'wgs84' | 'local';
|
|
9
|
+
/** An object containing tile index values (`x`, `y`, `z`) to reproject features' coordinates into WGS84. Mandatory with `wgs84` coordinates option. */
|
|
10
|
+
tileIndex?: {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
z: number;
|
|
14
|
+
};
|
|
15
|
+
/** If provided, stored the layer name of each feature is added to `feature.properties[layerProperty]`. */
|
|
16
|
+
layerProperty?: string | number;
|
|
17
|
+
/** layer filter. If provided, only features belonging to the named layers will be included, otherwise features from all layers are returned. */
|
|
18
|
+
layers?: string[];
|
|
6
19
|
/** Override the URL to the worker bundle (by default loads from unpkg.com) */
|
|
7
20
|
workerUrl?: string;
|
|
8
21
|
};
|
|
9
22
|
gis?: {
|
|
10
|
-
/** `true`: parser will output the data in binary format. Equivalent to loading the data as GeoJSON and then applying geojsonToBinary */
|
|
11
|
-
binary?: boolean;
|
|
12
23
|
/** @deprecated. Use options.mvt.shape */
|
|
13
24
|
format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
14
25
|
};
|
|
@@ -32,8 +43,8 @@ export declare const MVTWorkerLoader: {
|
|
|
32
43
|
readonly shape: "geojson";
|
|
33
44
|
readonly coordinates: "local";
|
|
34
45
|
readonly layerProperty: "layerName";
|
|
35
|
-
readonly layers:
|
|
36
|
-
readonly tileIndex:
|
|
46
|
+
readonly layers: never;
|
|
47
|
+
readonly tileIndex: never;
|
|
37
48
|
};
|
|
38
49
|
};
|
|
39
50
|
};
|
|
@@ -41,7 +52,7 @@ export declare const MVTWorkerLoader: {
|
|
|
41
52
|
* Loader for the Mapbox Vector Tile format
|
|
42
53
|
*/
|
|
43
54
|
export declare const MVTLoader: {
|
|
44
|
-
readonly parse: (arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions) => Promise<import("@loaders.gl/schema").
|
|
55
|
+
readonly parse: (arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions) => Promise<import("@loaders.gl/schema").GeoJSONTable | import("geojson").Feature<import("geojson").Geometry, import("geojson").GeoJsonProperties>[] | import("@loaders.gl/schema").BinaryFeatureCollection | {
|
|
45
56
|
shape: string;
|
|
46
57
|
data: import("@loaders.gl/schema").BinaryFeatureCollection;
|
|
47
58
|
}>;
|
|
@@ -62,8 +73,8 @@ export declare const MVTLoader: {
|
|
|
62
73
|
readonly shape: "geojson";
|
|
63
74
|
readonly coordinates: "local";
|
|
64
75
|
readonly layerProperty: "layerName";
|
|
65
|
-
readonly layers:
|
|
66
|
-
readonly tileIndex:
|
|
76
|
+
readonly layers: never;
|
|
77
|
+
readonly tileIndex: never;
|
|
67
78
|
};
|
|
68
79
|
};
|
|
69
80
|
};
|
package/dist/mvt-loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mvt-loader.d.ts","sourceRoot":"","sources":["../src/mvt-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA2B,aAAa,EAAC,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"mvt-loader.d.ts","sourceRoot":"","sources":["../src/mvt-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA2B,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEtF,OAAO,EAAC,QAAQ,EAAC,2BAAwB;AAMzC,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE;QACJ,6BAA6B;QAC7B,KAAK,CAAC,EAAE,eAAe,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;QACtF,sHAAsH;QACtH,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;QAChC,uJAAuJ;QACvJ,SAAS,CAAC,EAAE;YAAC,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAA;SAAC,CAAC;QAC9C,0GAA0G;QAC1G,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAChC,gJAAgJ;QAChJ,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAClB,8EAA8E;QAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,yCAAyC;QACzC,MAAM,CAAC,EAAE,eAAe,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;KACxF,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;CA+B3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS;yDAEiB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;CAOtD,CAAC"}
|
package/dist/mvt-loader.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright vis.gl contributors
|
|
4
|
+
// import type {MVTOptions} from './lib/types';
|
|
4
5
|
import { parseMVT } from "./lib/parse-mvt.js";
|
|
5
6
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
7
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
-
const VERSION = typeof "4.2.0
|
|
8
|
+
const VERSION = typeof "4.2.0" !== 'undefined' ? "4.2.0" : 'latest';
|
|
8
9
|
/**
|
|
9
10
|
* Worker loader for the Mapbox Vector Tile format
|
|
10
11
|
*/
|
|
@@ -31,7 +32,7 @@ export const MVTWorkerLoader = {
|
|
|
31
32
|
coordinates: 'local',
|
|
32
33
|
layerProperty: 'layerName',
|
|
33
34
|
layers: undefined,
|
|
34
|
-
tileIndex:
|
|
35
|
+
tileIndex: undefined
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
};
|
package/dist/mvt-source.js
CHANGED
|
@@ -68,7 +68,7 @@ export class MVTSource extends DataSource {
|
|
|
68
68
|
return this.mimeType;
|
|
69
69
|
}
|
|
70
70
|
async getTile(tileParams) {
|
|
71
|
-
const { x, y,
|
|
71
|
+
const { x, y, z } = tileParams;
|
|
72
72
|
const tileUrl = this.getTileURL(x, y, z);
|
|
73
73
|
const response = await this.fetch(tileUrl);
|
|
74
74
|
if (!response.ok) {
|
|
@@ -83,7 +83,7 @@ export class MVTSource extends DataSource {
|
|
|
83
83
|
const { x, y, z } = tileParams.index;
|
|
84
84
|
// const metadata = await this.metadata;
|
|
85
85
|
// mimeType = metadata?.tileMIMEType || 'application/vnd.mapbox-vector-tile';
|
|
86
|
-
const arrayBuffer = await this.getTile({ x, y,
|
|
86
|
+
const arrayBuffer = await this.getTile({ x, y, z, layers: [] });
|
|
87
87
|
if (arrayBuffer === null) {
|
|
88
88
|
return null;
|
|
89
89
|
}
|
|
@@ -92,7 +92,7 @@ export class MVTSource extends DataSource {
|
|
|
92
92
|
this.mimeType || imageMetadata?.mimeType || 'application/vnd.mapbox-vector-tile';
|
|
93
93
|
switch (this.mimeType) {
|
|
94
94
|
case 'application/vnd.mapbox-vector-tile':
|
|
95
|
-
return await this._parseVectorTile(arrayBuffer, { x, y,
|
|
95
|
+
return await this._parseVectorTile(arrayBuffer, { x, y, z, layers: [] });
|
|
96
96
|
default:
|
|
97
97
|
return await this._parseImageTile(arrayBuffer);
|
|
98
98
|
}
|
|
@@ -115,7 +115,7 @@ export class MVTSource extends DataSource {
|
|
|
115
115
|
shape: 'geojson-table',
|
|
116
116
|
mvt: {
|
|
117
117
|
coordinates: 'wgs84',
|
|
118
|
-
tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.
|
|
118
|
+
tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.z },
|
|
119
119
|
...this.loadOptions?.mvt
|
|
120
120
|
},
|
|
121
121
|
...this.loadOptions
|