@loaders.gl/mvt 4.2.1 → 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 +568 -558
- 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 +2 -1
- package/dist/mvt-source.js +4 -4
- package/dist/mvt-worker.js +1172 -735
- 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
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import Protobuf from 'pbf';
|
|
6
|
-
import {MVTMapboxGeometry} from '../lib/types';
|
|
7
|
-
import {VectorTileFeature} from '../lib/mapbox-vector-tile/vector-tile-feature';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Classifies an array of rings into polygons with outer rings and holes
|
|
11
|
-
* @param rings
|
|
12
|
-
* @returns polygons
|
|
13
|
-
*/
|
|
14
|
-
export function classifyRings(rings: MVTMapboxGeometry) {
|
|
15
|
-
const len = rings.length;
|
|
16
|
-
|
|
17
|
-
if (len <= 1) return [rings];
|
|
18
|
-
|
|
19
|
-
const polygons: number[][][] = [];
|
|
20
|
-
let polygon: number[][] | undefined;
|
|
21
|
-
let ccw: boolean | undefined;
|
|
22
|
-
|
|
23
|
-
for (let i = 0; i < len; i++) {
|
|
24
|
-
const area = signedArea(rings[i]);
|
|
25
|
-
if (area === 0) continue; // eslint-disable-line no-continue
|
|
26
|
-
|
|
27
|
-
if (ccw === undefined) ccw = area < 0;
|
|
28
|
-
|
|
29
|
-
if (ccw === area < 0) {
|
|
30
|
-
if (polygon) polygons.push(polygon);
|
|
31
|
-
polygon = [rings[i]];
|
|
32
|
-
} else if (polygon) polygon.push(rings[i]);
|
|
33
|
-
}
|
|
34
|
-
if (polygon) polygons.push(polygon);
|
|
35
|
-
|
|
36
|
-
return polygons;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param ring
|
|
42
|
-
* @returns sum
|
|
43
|
-
*/
|
|
44
|
-
export function signedArea(ring: number[][]) {
|
|
45
|
-
let sum = 0;
|
|
46
|
-
for (let i = 0, j = ring.length - 1, p1: number[], p2: number[]; i < ring.length; j = i++) {
|
|
47
|
-
p1 = ring[i];
|
|
48
|
-
p2 = ring[j];
|
|
49
|
-
sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
|
|
50
|
-
}
|
|
51
|
-
return sum;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @param tag
|
|
57
|
-
* @param feature
|
|
58
|
-
* @param pbf
|
|
59
|
-
*/
|
|
60
|
-
export function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Protobuf): void {
|
|
61
|
-
if (feature && pbf) {
|
|
62
|
-
if (tag === 1) feature.id = pbf.readVarint();
|
|
63
|
-
else if (tag === 2) readTag(pbf, feature);
|
|
64
|
-
else if (tag === 3) feature.type = pbf.readVarint();
|
|
65
|
-
else if (tag === 4) feature._geometry = pbf.pos;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
* @param pbf
|
|
72
|
-
* @param feature
|
|
73
|
-
*/
|
|
74
|
-
export function readTag(pbf: Protobuf, feature: VectorTileFeature): void {
|
|
75
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
76
|
-
|
|
77
|
-
while (pbf.pos < end) {
|
|
78
|
-
const key = feature._keys[pbf.readVarint()];
|
|
79
|
-
const value = feature._values[pbf.readVarint()];
|
|
80
|
-
feature.properties[key] = value;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,203 +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
|
-
|
|
7
|
-
import Protobuf from 'pbf';
|
|
8
|
-
import {FlatFeature, FlatIndexedGeometry, GeojsonGeometryInfo} from '@loaders.gl/schema';
|
|
9
|
-
import {classifyRings, project, readFeature} from '../../helpers/binary-util-functions';
|
|
10
|
-
|
|
11
|
-
// Reduce GC by reusing variables
|
|
12
|
-
let endPos: number;
|
|
13
|
-
let cmd: number;
|
|
14
|
-
let cmdLen: number;
|
|
15
|
-
let length: number;
|
|
16
|
-
let x: number;
|
|
17
|
-
let y: number;
|
|
18
|
-
let i: number;
|
|
19
|
-
|
|
20
|
-
export const TEST_EXPORTS = {
|
|
21
|
-
classifyRings
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export class BinaryVectorTileFeature {
|
|
25
|
-
properties: {[x: string]: string | number | boolean | null};
|
|
26
|
-
extent: any;
|
|
27
|
-
type: number;
|
|
28
|
-
id: number | null;
|
|
29
|
-
_pbf: Protobuf;
|
|
30
|
-
_geometry: number;
|
|
31
|
-
_keys: string[];
|
|
32
|
-
_values: (string | number | boolean | null)[];
|
|
33
|
-
_geometryInfo: GeojsonGeometryInfo;
|
|
34
|
-
|
|
35
|
-
// eslint-disable-next-line max-params
|
|
36
|
-
constructor(
|
|
37
|
-
pbf: Protobuf,
|
|
38
|
-
end: number,
|
|
39
|
-
extent: any,
|
|
40
|
-
keys: string[],
|
|
41
|
-
values: (string | number | boolean | null)[],
|
|
42
|
-
geometryInfo: GeojsonGeometryInfo
|
|
43
|
-
) {
|
|
44
|
-
// Public
|
|
45
|
-
this.properties = {};
|
|
46
|
-
this.extent = extent;
|
|
47
|
-
this.type = 0;
|
|
48
|
-
this.id = null;
|
|
49
|
-
|
|
50
|
-
// Private
|
|
51
|
-
this._pbf = pbf;
|
|
52
|
-
this._geometry = -1;
|
|
53
|
-
this._keys = keys;
|
|
54
|
-
this._values = values;
|
|
55
|
-
this._geometryInfo = geometryInfo;
|
|
56
|
-
|
|
57
|
-
pbf.readFields(readFeature, this, end);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// eslint-disable-next-line complexity, max-statements
|
|
61
|
-
loadGeometry(): FlatIndexedGeometry {
|
|
62
|
-
const pbf = this._pbf;
|
|
63
|
-
pbf.pos = this._geometry;
|
|
64
|
-
|
|
65
|
-
endPos = pbf.readVarint() + pbf.pos;
|
|
66
|
-
cmd = 1;
|
|
67
|
-
length = 0;
|
|
68
|
-
x = 0;
|
|
69
|
-
y = 0;
|
|
70
|
-
i = 0;
|
|
71
|
-
|
|
72
|
-
// Note: I attempted to replace the `data` array with a
|
|
73
|
-
// Float32Array, but performance was worse, both using
|
|
74
|
-
// `set()` and direct index access. Also, we cannot
|
|
75
|
-
// know how large the buffer should be, so it would
|
|
76
|
-
// increase memory usage
|
|
77
|
-
const indices: number[] = []; // Indices where geometries start
|
|
78
|
-
const data: number[] = []; // Flat array of coordinate data
|
|
79
|
-
|
|
80
|
-
while (pbf.pos < endPos) {
|
|
81
|
-
if (length <= 0) {
|
|
82
|
-
cmdLen = pbf.readVarint();
|
|
83
|
-
cmd = cmdLen & 0x7;
|
|
84
|
-
length = cmdLen >> 3;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
length--;
|
|
88
|
-
|
|
89
|
-
if (cmd === 1 || cmd === 2) {
|
|
90
|
-
x += pbf.readSVarint();
|
|
91
|
-
y += pbf.readSVarint();
|
|
92
|
-
|
|
93
|
-
if (cmd === 1) {
|
|
94
|
-
// New line
|
|
95
|
-
indices.push(i);
|
|
96
|
-
}
|
|
97
|
-
data.push(x, y);
|
|
98
|
-
i += 2;
|
|
99
|
-
} else if (cmd === 7) {
|
|
100
|
-
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
101
|
-
if (i > 0) {
|
|
102
|
-
const start = indices[indices.length - 1]; // start index of polygon
|
|
103
|
-
data.push(data[start], data[start + 1]); // closePolygon
|
|
104
|
-
i += 2;
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
throw new Error(`unknown command ${cmd}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return {data, indices};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
*
|
|
116
|
-
* @param transform
|
|
117
|
-
* @returns result
|
|
118
|
-
*/
|
|
119
|
-
_toBinaryCoordinates(transform) {
|
|
120
|
-
// Expands the protobuf data to an intermediate Flat GeoJSON
|
|
121
|
-
// data format, which maps closely to the binary data buffers.
|
|
122
|
-
// It is similar to GeoJSON, but rather than storing the coordinates
|
|
123
|
-
// in multidimensional arrays, we have a 1D `data` with all the
|
|
124
|
-
// coordinates, and then index into this using the `indices`
|
|
125
|
-
// parameter, e.g.
|
|
126
|
-
//
|
|
127
|
-
// geometry: {
|
|
128
|
-
// type: 'Point', data: [1,2], indices: [0]
|
|
129
|
-
// }
|
|
130
|
-
// geometry: {
|
|
131
|
-
// type: 'LineString', data: [1,2,3,4,...], indices: [0]
|
|
132
|
-
// }
|
|
133
|
-
// geometry: {
|
|
134
|
-
// type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
|
|
135
|
-
// }
|
|
136
|
-
// Thus the indices member lets us look up the relevant range
|
|
137
|
-
// from the data array.
|
|
138
|
-
// The Multi* versions of the above types share the same data
|
|
139
|
-
// structure, just with multiple elements in the indices array
|
|
140
|
-
const geom = this.loadGeometry();
|
|
141
|
-
let geometry;
|
|
142
|
-
|
|
143
|
-
// Apply the supplied transformation to data
|
|
144
|
-
transform(geom.data, this);
|
|
145
|
-
|
|
146
|
-
const coordLength = 2;
|
|
147
|
-
|
|
148
|
-
// eslint-disable-next-line default-case
|
|
149
|
-
switch (this.type) {
|
|
150
|
-
case 1: // Point
|
|
151
|
-
this._geometryInfo.pointFeaturesCount++;
|
|
152
|
-
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
153
|
-
geometry = {type: 'Point', ...geom};
|
|
154
|
-
break;
|
|
155
|
-
|
|
156
|
-
case 2: // LineString
|
|
157
|
-
this._geometryInfo.lineFeaturesCount++;
|
|
158
|
-
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
159
|
-
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
160
|
-
geometry = {type: 'LineString', ...geom};
|
|
161
|
-
break;
|
|
162
|
-
|
|
163
|
-
case 3: // Polygon
|
|
164
|
-
geometry = classifyRings(geom);
|
|
165
|
-
|
|
166
|
-
// Unlike Point & LineString geom.indices is a 2D array, thanks
|
|
167
|
-
// to the classifyRings method
|
|
168
|
-
this._geometryInfo.polygonFeaturesCount++;
|
|
169
|
-
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
170
|
-
|
|
171
|
-
for (const indices of geometry.indices) {
|
|
172
|
-
this._geometryInfo.polygonRingsCount += indices.length;
|
|
173
|
-
}
|
|
174
|
-
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
175
|
-
|
|
176
|
-
break;
|
|
177
|
-
default:
|
|
178
|
-
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const result: FlatFeature = {type: 'Feature', geometry, properties: this.properties};
|
|
182
|
-
|
|
183
|
-
if (this.id !== null) {
|
|
184
|
-
result.id = this.id;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return result;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
toBinaryCoordinates(
|
|
191
|
-
options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)
|
|
192
|
-
): FlatFeature {
|
|
193
|
-
if (typeof options === 'function') {
|
|
194
|
-
return this._toBinaryCoordinates(options);
|
|
195
|
-
}
|
|
196
|
-
const {x, y, z} = options;
|
|
197
|
-
const size = this.extent * Math.pow(2, z);
|
|
198
|
-
const x0 = this.extent * x;
|
|
199
|
-
const y0 = this.extent * y;
|
|
200
|
-
|
|
201
|
-
return this._toBinaryCoordinates((data: number[]) => project(data, x0, y0, size));
|
|
202
|
-
}
|
|
203
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright vis.gl contributors
|
|
4
|
-
|
|
5
|
-
/* eslint-disable indent */
|
|
6
|
-
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
7
|
-
|
|
8
|
-
import {BinaryVectorTileFeature} from './vector-tile-feature';
|
|
9
|
-
import Protobuf from 'pbf';
|
|
10
|
-
import {GeojsonGeometryInfo} from '@loaders.gl/schema';
|
|
11
|
-
|
|
12
|
-
export class BinaryVectorTileLayer {
|
|
13
|
-
version: number;
|
|
14
|
-
name: string;
|
|
15
|
-
extent: number;
|
|
16
|
-
length: number;
|
|
17
|
-
_pbf: Protobuf;
|
|
18
|
-
_keys: string[];
|
|
19
|
-
_values: (string | number | boolean | null)[];
|
|
20
|
-
_features: number[];
|
|
21
|
-
constructor(pbf: Protobuf, end: number) {
|
|
22
|
-
// Public
|
|
23
|
-
this.version = 1;
|
|
24
|
-
this.name = '';
|
|
25
|
-
this.extent = 4096;
|
|
26
|
-
this.length = 0;
|
|
27
|
-
|
|
28
|
-
// Private
|
|
29
|
-
this._pbf = pbf;
|
|
30
|
-
this._keys = [];
|
|
31
|
-
this._values = [];
|
|
32
|
-
this._features = [];
|
|
33
|
-
|
|
34
|
-
pbf.readFields(readLayer, this, end);
|
|
35
|
-
|
|
36
|
-
this.length = this._features.length;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* return feature `i` from this layer as a `BinaryVectorTileFeature`
|
|
41
|
-
*
|
|
42
|
-
* @param index
|
|
43
|
-
* @param geometryInfo
|
|
44
|
-
* @returns {BinaryVectorTileFeature}
|
|
45
|
-
*/
|
|
46
|
-
feature(i: number, geometryInfo: GeojsonGeometryInfo): BinaryVectorTileFeature {
|
|
47
|
-
if (i < 0 || i >= this._features.length) {
|
|
48
|
-
throw new Error('feature index out of bounds');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this._pbf.pos = this._features[i];
|
|
52
|
-
|
|
53
|
-
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
54
|
-
return new BinaryVectorTileFeature(
|
|
55
|
-
this._pbf,
|
|
56
|
-
end,
|
|
57
|
-
this.extent,
|
|
58
|
-
this._keys,
|
|
59
|
-
this._values,
|
|
60
|
-
geometryInfo
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
*
|
|
67
|
-
* @param tag
|
|
68
|
-
* @param layer
|
|
69
|
-
* @param pbf
|
|
70
|
-
*/
|
|
71
|
-
function readLayer(tag: number, layer?: BinaryVectorTileLayer, pbf?: Protobuf): void {
|
|
72
|
-
if (layer && pbf) {
|
|
73
|
-
if (tag === 15) layer.version = pbf.readVarint();
|
|
74
|
-
else if (tag === 1) layer.name = pbf.readString();
|
|
75
|
-
else if (tag === 5) layer.extent = pbf.readVarint();
|
|
76
|
-
else if (tag === 2) layer._features.push(pbf.pos);
|
|
77
|
-
else if (tag === 3) layer._keys.push(pbf.readString());
|
|
78
|
-
else if (tag === 4) layer._values.push(readValueMessage(pbf));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* @param pbf
|
|
85
|
-
* @returns value
|
|
86
|
-
*/
|
|
87
|
-
function readValueMessage(pbf: Protobuf) {
|
|
88
|
-
let value: string | number | boolean | null = null;
|
|
89
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
90
|
-
|
|
91
|
-
while (pbf.pos < end) {
|
|
92
|
-
const tag = pbf.readVarint() >> 3;
|
|
93
|
-
|
|
94
|
-
value =
|
|
95
|
-
tag === 1
|
|
96
|
-
? pbf.readString()
|
|
97
|
-
: tag === 2
|
|
98
|
-
? pbf.readFloat()
|
|
99
|
-
: tag === 3
|
|
100
|
-
? pbf.readDouble()
|
|
101
|
-
: tag === 4
|
|
102
|
-
? pbf.readVarint64()
|
|
103
|
-
: tag === 5
|
|
104
|
-
? pbf.readVarint()
|
|
105
|
-
: tag === 6
|
|
106
|
-
? pbf.readSVarint()
|
|
107
|
-
: tag === 7
|
|
108
|
-
? pbf.readBoolean()
|
|
109
|
-
: null;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return value;
|
|
113
|
-
}
|
|
@@ -1,36 +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
|
-
|
|
7
|
-
import {BinaryVectorTileLayer} from './vector-tile-layer';
|
|
8
|
-
import Protobuf from 'pbf';
|
|
9
|
-
|
|
10
|
-
export class BinaryVectorTile {
|
|
11
|
-
layers: {[x: string]: BinaryVectorTileLayer};
|
|
12
|
-
constructor(pbf: Protobuf, end?: number) {
|
|
13
|
-
this.layers = pbf.readFields(readTile, {}, end);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* @param tag
|
|
20
|
-
* @param layers
|
|
21
|
-
* @param pbf
|
|
22
|
-
*/
|
|
23
|
-
function readTile(
|
|
24
|
-
tag: number,
|
|
25
|
-
layers?: {[x: string]: BinaryVectorTileLayer},
|
|
26
|
-
pbf?: Protobuf
|
|
27
|
-
): void {
|
|
28
|
-
if (tag === 3) {
|
|
29
|
-
if (pbf) {
|
|
30
|
-
const layer = new BinaryVectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
|
|
31
|
-
if (layer.length && layers) {
|
|
32
|
-
layers[layer.name] = layer;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Copyright (c) 2014, Mapbox
|
|
6
|
-
|
|
7
|
-
All rights reserved.
|
|
8
|
-
|
|
9
|
-
Redistribution and use in source and binary forms, with or without modification,
|
|
10
|
-
are permitted provided that the following conditions are met:
|
|
11
|
-
|
|
12
|
-
* Redistributions of source code must retain the above copyright notice,
|
|
13
|
-
this list of conditions and the following disclaimer.
|
|
14
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
|
15
|
-
this list of conditions and the following disclaimer in the documentation
|
|
16
|
-
and/or other materials provided with the distribution.
|
|
17
|
-
* Neither the name of Mapbox nor the names of its contributors
|
|
18
|
-
may be used to endorse or promote products derived from this software
|
|
19
|
-
without specific prior written permission.
|
|
20
|
-
|
|
21
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
22
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
23
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
24
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
25
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
26
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
28
|
-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
29
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
30
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
31
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -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
|