@loaders.gl/mvt 4.2.1 → 4.3.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +1784 -847
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +713 -640
- 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/parse-mvt.d.ts +2 -1
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +15 -45
- package/dist/lib/parse-tilejson.d.ts +4 -4
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- 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 +83 -0
- package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
- package/dist/lib/utils/geometry-utils.js +206 -0
- package/dist/lib/vector-tile/vector-tile-feature.d.ts +72 -0
- package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/vector-tile/vector-tile-feature.js +342 -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/lib/{geojson-tiler → vector-tiler}/clip.d.ts +3 -3
- package/dist/lib/vector-tiler/clip.d.ts.map +1 -0
- package/dist/lib/vector-tiler/convert.d.ts +18 -0
- package/dist/lib/vector-tiler/convert.d.ts.map +1 -0
- package/dist/lib/{geojson-tiler → vector-tiler}/convert.js +8 -1
- package/dist/lib/vector-tiler/feature.d.ts +3 -0
- package/dist/lib/vector-tiler/feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/simplify.d.ts.map +1 -0
- package/dist/lib/{geojson-tiler → vector-tiler}/tile.d.ts +4 -4
- package/dist/lib/vector-tiler/tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/transform.d.ts +7 -0
- package/dist/lib/vector-tiler/transform.d.ts.map +1 -0
- package/dist/lib/{geojson-tiler → vector-tiler}/wrap.d.ts +2 -2
- package/dist/lib/vector-tiler/wrap.d.ts.map +1 -0
- package/dist/mvt-loader.d.ts +19 -8
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +3 -2
- package/dist/mvt-source.d.ts +4 -4
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +7 -7
- package/dist/mvt-worker.js +1244 -762
- package/dist/table-tile-source.d.ts +118 -0
- package/dist/table-tile-source.d.ts.map +1 -0
- package/dist/table-tile-source.js +370 -0
- package/dist/tilejson-loader.js +1 -1
- package/package.json +7 -6
- package/src/index.ts +3 -3
- package/src/lib/parse-mvt.ts +28 -66
- package/src/lib/parse-tilejson.ts +5 -5
- package/src/lib/types.ts +1 -39
- package/src/lib/utils/geometry-utils.ts +234 -0
- package/src/lib/vector-tile/vector-tile-feature.ts +416 -0
- package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.ts +28 -2
- package/src/lib/{geojson-tiler → vector-tiler}/clip.ts +4 -4
- package/src/lib/{geojson-tiler → vector-tiler}/convert.ts +19 -9
- package/src/lib/{geojson-tiler → vector-tiler}/feature.ts +3 -3
- package/src/lib/{geojson-tiler → vector-tiler}/tile.ts +10 -10
- package/src/lib/{geojson-tiler → vector-tiler}/transform.ts +2 -2
- package/src/lib/{geojson-tiler → vector-tiler}/wrap.ts +5 -5
- package/src/mvt-loader.ts +14 -6
- package/src/mvt-source.ts +9 -10
- package/src/table-tile-source.ts +508 -0
- package/dist/helpers/binary-util-functions.d.ts +0 -35
- package/dist/helpers/binary-util-functions.d.ts.map +0 -1
- package/dist/helpers/binary-util-functions.js +0 -114
- 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 +0 -41
- 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 +0 -3
- 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/geojson-tiler.js +0 -209
- 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 +0 -7
- 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/binary-util-functions.ts +0 -125
- 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/geojson-tiler/geojson-tiler.ts +0 -283
- 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/{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/dist/lib/{geojson-tiler → vector-tiler}/clip.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/feature.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/simplify.d.ts +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/simplify.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/tile.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/transform.js +0 -0
- /package/dist/lib/{geojson-tiler → vector-tiler}/wrap.js +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
- /package/src/lib/{geojson-tiler → vector-tiler}/LICENSE +0 -0
- /package/src/lib/{geojson-tiler → vector-tiler}/simplify.ts +0 -0
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright vis.gl contributors
|
|
4
|
-
|
|
5
|
-
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
6
|
-
import Protobuf from 'pbf';
|
|
7
|
-
import {MVTMapboxCoordinates, MVTMapboxGeometry} from '../types';
|
|
8
|
-
import {readFeature, classifyRings} from '../../helpers/mapbox-util-functions';
|
|
9
|
-
|
|
10
|
-
export class VectorTileFeature {
|
|
11
|
-
properties: {[x: string]: string | number | boolean | null};
|
|
12
|
-
extent: any;
|
|
13
|
-
type: number;
|
|
14
|
-
id: number | null;
|
|
15
|
-
_pbf: Protobuf;
|
|
16
|
-
_geometry: number;
|
|
17
|
-
_keys: string[];
|
|
18
|
-
_values: (string | number | boolean | null)[];
|
|
19
|
-
static get types() {
|
|
20
|
-
return ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
pbf: Protobuf,
|
|
25
|
-
end: number,
|
|
26
|
-
extent: any,
|
|
27
|
-
keys: string[],
|
|
28
|
-
values: (string | number | boolean | null)[]
|
|
29
|
-
) {
|
|
30
|
-
// Public
|
|
31
|
-
this.properties = {};
|
|
32
|
-
this.extent = extent;
|
|
33
|
-
this.type = 0;
|
|
34
|
-
this.id = null;
|
|
35
|
-
|
|
36
|
-
// Private
|
|
37
|
-
this._pbf = pbf;
|
|
38
|
-
this._geometry = -1;
|
|
39
|
-
this._keys = keys;
|
|
40
|
-
this._values = values;
|
|
41
|
-
|
|
42
|
-
pbf.readFields(readFeature, this, end);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// eslint-disable-next-line complexity, max-statements
|
|
46
|
-
loadGeometry(): MVTMapboxGeometry {
|
|
47
|
-
const pbf = this._pbf;
|
|
48
|
-
pbf.pos = this._geometry;
|
|
49
|
-
|
|
50
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
51
|
-
let cmd = 1;
|
|
52
|
-
let length = 0;
|
|
53
|
-
let x = 0;
|
|
54
|
-
let y = 0;
|
|
55
|
-
const lines: number[][][] = [];
|
|
56
|
-
let line: number[][] | undefined;
|
|
57
|
-
|
|
58
|
-
while (pbf.pos < end) {
|
|
59
|
-
if (length <= 0) {
|
|
60
|
-
const cmdLen = pbf.readVarint();
|
|
61
|
-
cmd = cmdLen & 0x7;
|
|
62
|
-
length = cmdLen >> 3;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
length--;
|
|
66
|
-
|
|
67
|
-
if (cmd === 1 || cmd === 2) {
|
|
68
|
-
x += pbf.readSVarint();
|
|
69
|
-
y += pbf.readSVarint();
|
|
70
|
-
|
|
71
|
-
if (cmd === 1) {
|
|
72
|
-
// moveTo
|
|
73
|
-
if (line) lines.push(line);
|
|
74
|
-
line = [];
|
|
75
|
-
}
|
|
76
|
-
if (line) line.push([x, y]);
|
|
77
|
-
} else if (cmd === 7) {
|
|
78
|
-
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
79
|
-
if (line) {
|
|
80
|
-
line.push(line[0].slice()); // closePolygon
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
throw new Error(`unknown command ${cmd}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (line) lines.push(line);
|
|
88
|
-
|
|
89
|
-
return lines;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// eslint-disable-next-line max-statements
|
|
93
|
-
bbox() {
|
|
94
|
-
const pbf = this._pbf;
|
|
95
|
-
pbf.pos = this._geometry;
|
|
96
|
-
|
|
97
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
98
|
-
let cmd = 1;
|
|
99
|
-
let length = 0;
|
|
100
|
-
let x = 0;
|
|
101
|
-
let y = 0;
|
|
102
|
-
let x1 = Infinity;
|
|
103
|
-
let x2 = -Infinity;
|
|
104
|
-
let y1 = Infinity;
|
|
105
|
-
let y2 = -Infinity;
|
|
106
|
-
|
|
107
|
-
while (pbf.pos < end) {
|
|
108
|
-
if (length <= 0) {
|
|
109
|
-
const cmdLen = pbf.readVarint();
|
|
110
|
-
cmd = cmdLen & 0x7;
|
|
111
|
-
length = cmdLen >> 3;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
length--;
|
|
115
|
-
|
|
116
|
-
if (cmd === 1 || cmd === 2) {
|
|
117
|
-
x += pbf.readSVarint();
|
|
118
|
-
y += pbf.readSVarint();
|
|
119
|
-
if (x < x1) x1 = x;
|
|
120
|
-
if (x > x2) x2 = x;
|
|
121
|
-
if (y < y1) y1 = y;
|
|
122
|
-
if (y > y2) y2 = y;
|
|
123
|
-
} else if (cmd !== 7) {
|
|
124
|
-
throw new Error(`unknown command ${cmd}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return [x1, y1, x2, y2];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
_toGeoJSON(transform) {
|
|
132
|
-
let coords = this.loadGeometry();
|
|
133
|
-
let type = VectorTileFeature.types[this.type];
|
|
134
|
-
let i: number;
|
|
135
|
-
let j: number;
|
|
136
|
-
|
|
137
|
-
// eslint-disable-next-line default-case
|
|
138
|
-
switch (this.type) {
|
|
139
|
-
case 1:
|
|
140
|
-
const points: number[] = [];
|
|
141
|
-
for (i = 0; i < coords.length; i++) {
|
|
142
|
-
points[i] = coords[i][0];
|
|
143
|
-
}
|
|
144
|
-
coords = points;
|
|
145
|
-
transform(coords, this);
|
|
146
|
-
break;
|
|
147
|
-
|
|
148
|
-
case 2:
|
|
149
|
-
for (i = 0; i < coords.length; i++) {
|
|
150
|
-
transform(coords[i], this);
|
|
151
|
-
}
|
|
152
|
-
break;
|
|
153
|
-
|
|
154
|
-
case 3:
|
|
155
|
-
coords = classifyRings(coords);
|
|
156
|
-
for (i = 0; i < coords.length; i++) {
|
|
157
|
-
for (j = 0; j < coords[i].length; j++) {
|
|
158
|
-
transform(coords[i][j], this);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (coords.length === 1) {
|
|
165
|
-
coords = coords[0];
|
|
166
|
-
} else {
|
|
167
|
-
type = `Multi${type}`;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const result: MVTMapboxCoordinates = {
|
|
171
|
-
type: 'Feature',
|
|
172
|
-
geometry: {
|
|
173
|
-
type,
|
|
174
|
-
coordinates: coords
|
|
175
|
-
},
|
|
176
|
-
properties: this.properties
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
if (this.id !== null) {
|
|
180
|
-
result.id = this.id;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return result;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
toGeoJSON(
|
|
187
|
-
options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)
|
|
188
|
-
): MVTMapboxCoordinates {
|
|
189
|
-
if (typeof options === 'function') {
|
|
190
|
-
return this._toGeoJSON(options);
|
|
191
|
-
}
|
|
192
|
-
const {x, y, z} = options;
|
|
193
|
-
const size = this.extent * Math.pow(2, z);
|
|
194
|
-
const x0 = this.extent * x;
|
|
195
|
-
const y0 = this.extent * y;
|
|
196
|
-
|
|
197
|
-
function project(line: number[]) {
|
|
198
|
-
for (let j = 0; j < line.length; j++) {
|
|
199
|
-
const p = line[j];
|
|
200
|
-
p[0] = ((p[0] + x0) * 360) / size - 180;
|
|
201
|
-
const y2 = 180 - ((p[1] + y0) * 360) / size;
|
|
202
|
-
p[1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return this._toGeoJSON(project);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|