@loaders.gl/mvt 4.2.0-alpha.3 → 4.2.0-alpha.5
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 +274 -252
- package/dist/dist.min.js +14 -0
- package/dist/helpers/binary-util-functions.d.ts +1 -1
- package/dist/helpers/binary-util-functions.d.ts.map +1 -1
- package/dist/helpers/binary-util-functions.js +99 -61
- package/dist/helpers/mapbox-util-functions.d.ts +2 -2
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -1
- package/dist/helpers/mapbox-util-functions.js +67 -33
- package/dist/index.cjs +37 -61
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +135 -118
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +77 -38
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +1 -1
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile.js +17 -12
- package/dist/lib/geojson-tiler/clip.d.ts +1 -1
- package/dist/lib/geojson-tiler/clip.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/clip.js +177 -142
- package/dist/lib/geojson-tiler/convert.d.ts +1 -1
- package/dist/lib/geojson-tiler/convert.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/convert.js +116 -100
- package/dist/lib/geojson-tiler/feature.d.ts +1 -1
- package/dist/lib/geojson-tiler/feature.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/feature.js +38 -29
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts +1 -1
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/geojson-tiler.js +197 -159
- package/dist/lib/geojson-tiler/simplify.js +60 -40
- package/dist/lib/geojson-tiler/tile.js +108 -88
- package/dist/lib/geojson-tiler/transform.d.ts +1 -1
- package/dist/lib/geojson-tiler/transform.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/transform.js +35 -26
- package/dist/lib/geojson-tiler/wrap.d.ts +1 -1
- package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/wrap.js +71 -53
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +156 -151
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +75 -38
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.js +17 -12
- package/dist/lib/parse-mvt.d.ts +1 -1
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +142 -115
- package/dist/lib/parse-tilejson.js +234 -176
- package/dist/lib/types.js +0 -1
- package/dist/mvt-loader.d.ts +1 -1
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +42 -22
- package/dist/mvt-source.js +148 -139
- package/dist/mvt-worker.js +1 -1
- package/dist/tilejson-loader.d.ts +1 -1
- package/dist/tilejson-loader.d.ts.map +1 -1
- package/dist/tilejson-loader.js +32 -31
- package/dist/workers/mvt-worker.js +0 -1
- package/package.json +12 -8
- 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/LICENSE.txt +0 -31
- 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/geojson-tiler/LICENSE +0 -19
- package/dist/lib/geojson-tiler/clip.js.map +0 -1
- package/dist/lib/geojson-tiler/convert.js.map +0 -1
- package/dist/lib/geojson-tiler/feature.js.map +0 -1
- package/dist/lib/geojson-tiler/geojson-tiler.js.map +0 -1
- package/dist/lib/geojson-tiler/simplify.js.map +0 -1
- package/dist/lib/geojson-tiler/tile.js.map +0 -1
- package/dist/lib/geojson-tiler/transform.js.map +0 -1
- package/dist/lib/geojson-tiler/wrap.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/LICENSE.txt +0 -31
- 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/parse-tilejson.js.map +0 -1
- package/dist/lib/types.js.map +0 -1
- package/dist/mvt-loader.js.map +0 -1
- package/dist/mvt-source.js.map +0 -1
- package/dist/tilejson-loader.js.map +0 -1
- package/dist/workers/mvt-worker.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Protobuf from 'pbf';
|
|
2
2
|
import { FlatFeature, FlatIndexedGeometry, GeojsonGeometryInfo } from '@loaders.gl/schema';
|
|
3
|
-
import { classifyRings } from
|
|
3
|
+
import { classifyRings } from "../../helpers/binary-util-functions.js";
|
|
4
4
|
export declare const TEST_EXPORTS: {
|
|
5
5
|
classifyRings: typeof classifyRings;
|
|
6
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAE,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAC,aAAa,EAAuB
|
|
1
|
+
{"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAE,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAC,aAAa,EAAuB,+CAA4C;AAWxF,eAAO,MAAM,YAAY;;CAExB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,aAAa,EAAE,mBAAmB,CAAC;gBAIjC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,EAC5C,YAAY,EAAE,mBAAmB;IAmBnC,YAAY,IAAI,mBAAmB;IAqDnC;;;;OAIG;IACH,oBAAoB,CAAC,SAAS,KAAA;;;;;;;IAuE9B,mBAAmB,CACjB,OAAO,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE;QAAC,MAAM,EAAE,GAAG,CAAA;KAAC,KAAK,IAAI,CAAC,GAC9F,WAAW;CAWf"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
1
2
|
import { classifyRings, project, readFeature } from "../../helpers/binary-util-functions.js";
|
|
3
|
+
// Reduce GC by reusing variables
|
|
2
4
|
let endPos;
|
|
3
5
|
let cmd;
|
|
4
6
|
let cmdLen;
|
|
@@ -7,129 +9,144 @@ let x;
|
|
|
7
9
|
let y;
|
|
8
10
|
let i;
|
|
9
11
|
export const TEST_EXPORTS = {
|
|
10
|
-
|
|
12
|
+
classifyRings
|
|
11
13
|
};
|
|
12
14
|
export default class VectorTileFeature {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this._pbf = pbf;
|
|
28
|
-
this._geometry = -1;
|
|
29
|
-
this._keys = keys;
|
|
30
|
-
this._values = values;
|
|
31
|
-
this._geometryInfo = geometryInfo;
|
|
32
|
-
pbf.readFields(readFeature, this, end);
|
|
33
|
-
}
|
|
34
|
-
loadGeometry() {
|
|
35
|
-
const pbf = this._pbf;
|
|
36
|
-
pbf.pos = this._geometry;
|
|
37
|
-
endPos = pbf.readVarint() + pbf.pos;
|
|
38
|
-
cmd = 1;
|
|
39
|
-
length = 0;
|
|
40
|
-
x = 0;
|
|
41
|
-
y = 0;
|
|
42
|
-
i = 0;
|
|
43
|
-
const indices = [];
|
|
44
|
-
const data = [];
|
|
45
|
-
while (pbf.pos < endPos) {
|
|
46
|
-
if (length <= 0) {
|
|
47
|
-
cmdLen = pbf.readVarint();
|
|
48
|
-
cmd = cmdLen & 0x7;
|
|
49
|
-
length = cmdLen >> 3;
|
|
50
|
-
}
|
|
51
|
-
length--;
|
|
52
|
-
if (cmd === 1 || cmd === 2) {
|
|
53
|
-
x += pbf.readSVarint();
|
|
54
|
-
y += pbf.readSVarint();
|
|
55
|
-
if (cmd === 1) {
|
|
56
|
-
indices.push(i);
|
|
57
|
-
}
|
|
58
|
-
data.push(x, y);
|
|
59
|
-
i += 2;
|
|
60
|
-
} else if (cmd === 7) {
|
|
61
|
-
if (i > 0) {
|
|
62
|
-
const start = indices[indices.length - 1];
|
|
63
|
-
data.push(data[start], data[start + 1]);
|
|
64
|
-
i += 2;
|
|
65
|
-
}
|
|
66
|
-
} else {
|
|
67
|
-
throw new Error(`unknown command ${cmd}`);
|
|
68
|
-
}
|
|
15
|
+
// eslint-disable-next-line max-params
|
|
16
|
+
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
17
|
+
// Public
|
|
18
|
+
this.properties = {};
|
|
19
|
+
this.extent = extent;
|
|
20
|
+
this.type = 0;
|
|
21
|
+
this.id = null;
|
|
22
|
+
// Private
|
|
23
|
+
this._pbf = pbf;
|
|
24
|
+
this._geometry = -1;
|
|
25
|
+
this._keys = keys;
|
|
26
|
+
this._values = values;
|
|
27
|
+
this._geometryInfo = geometryInfo;
|
|
28
|
+
pbf.readFields(readFeature, this, end);
|
|
69
29
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
30
|
+
// eslint-disable-next-line complexity, max-statements
|
|
31
|
+
loadGeometry() {
|
|
32
|
+
const pbf = this._pbf;
|
|
33
|
+
pbf.pos = this._geometry;
|
|
34
|
+
endPos = pbf.readVarint() + pbf.pos;
|
|
35
|
+
cmd = 1;
|
|
36
|
+
length = 0;
|
|
37
|
+
x = 0;
|
|
38
|
+
y = 0;
|
|
39
|
+
i = 0;
|
|
40
|
+
// Note: I attempted to replace the `data` array with a
|
|
41
|
+
// Float32Array, but performance was worse, both using
|
|
42
|
+
// `set()` and direct index access. Also, we cannot
|
|
43
|
+
// know how large the buffer should be, so it would
|
|
44
|
+
// increase memory usage
|
|
45
|
+
const indices = []; // Indices where geometries start
|
|
46
|
+
const data = []; // Flat array of coordinate data
|
|
47
|
+
while (pbf.pos < endPos) {
|
|
48
|
+
if (length <= 0) {
|
|
49
|
+
cmdLen = pbf.readVarint();
|
|
50
|
+
cmd = cmdLen & 0x7;
|
|
51
|
+
length = cmdLen >> 3;
|
|
52
|
+
}
|
|
53
|
+
length--;
|
|
54
|
+
if (cmd === 1 || cmd === 2) {
|
|
55
|
+
x += pbf.readSVarint();
|
|
56
|
+
y += pbf.readSVarint();
|
|
57
|
+
if (cmd === 1) {
|
|
58
|
+
// New line
|
|
59
|
+
indices.push(i);
|
|
60
|
+
}
|
|
61
|
+
data.push(x, y);
|
|
62
|
+
i += 2;
|
|
63
|
+
}
|
|
64
|
+
else if (cmd === 7) {
|
|
65
|
+
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
66
|
+
if (i > 0) {
|
|
67
|
+
const start = indices[indices.length - 1]; // start index of polygon
|
|
68
|
+
data.push(data[start], data[start + 1]); // closePolygon
|
|
69
|
+
i += 2;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new Error(`unknown command ${cmd}`);
|
|
74
|
+
}
|
|
104
75
|
}
|
|
105
|
-
|
|
106
|
-
break;
|
|
107
|
-
default:
|
|
108
|
-
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
76
|
+
return { data, indices };
|
|
109
77
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param transform
|
|
81
|
+
* @returns result
|
|
82
|
+
*/
|
|
83
|
+
_toBinaryCoordinates(transform) {
|
|
84
|
+
// Expands the protobuf data to an intermediate Flat GeoJSON
|
|
85
|
+
// data format, which maps closely to the binary data buffers.
|
|
86
|
+
// It is similar to GeoJSON, but rather than storing the coordinates
|
|
87
|
+
// in multidimensional arrays, we have a 1D `data` with all the
|
|
88
|
+
// coordinates, and then index into this using the `indices`
|
|
89
|
+
// parameter, e.g.
|
|
90
|
+
//
|
|
91
|
+
// geometry: {
|
|
92
|
+
// type: 'Point', data: [1,2], indices: [0]
|
|
93
|
+
// }
|
|
94
|
+
// geometry: {
|
|
95
|
+
// type: 'LineString', data: [1,2,3,4,...], indices: [0]
|
|
96
|
+
// }
|
|
97
|
+
// geometry: {
|
|
98
|
+
// type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
|
|
99
|
+
// }
|
|
100
|
+
// Thus the indices member lets us look up the relevant range
|
|
101
|
+
// from the data array.
|
|
102
|
+
// The Multi* versions of the above types share the same data
|
|
103
|
+
// structure, just with multiple elements in the indices array
|
|
104
|
+
const geom = this.loadGeometry();
|
|
105
|
+
let geometry;
|
|
106
|
+
// Apply the supplied transformation to data
|
|
107
|
+
transform(geom.data, this);
|
|
108
|
+
const coordLength = 2;
|
|
109
|
+
// eslint-disable-next-line default-case
|
|
110
|
+
switch (this.type) {
|
|
111
|
+
case 1: // Point
|
|
112
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
113
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
114
|
+
geometry = { type: 'Point', ...geom };
|
|
115
|
+
break;
|
|
116
|
+
case 2: // LineString
|
|
117
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
118
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
119
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
120
|
+
geometry = { type: 'LineString', ...geom };
|
|
121
|
+
break;
|
|
122
|
+
case 3: // Polygon
|
|
123
|
+
geometry = classifyRings(geom);
|
|
124
|
+
// Unlike Point & LineString geom.indices is a 2D array, thanks
|
|
125
|
+
// to the classifyRings method
|
|
126
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
127
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
128
|
+
for (const indices of geometry.indices) {
|
|
129
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
130
|
+
}
|
|
131
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
132
|
+
break;
|
|
133
|
+
default:
|
|
134
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
135
|
+
}
|
|
136
|
+
const result = { type: 'Feature', geometry, properties: this.properties };
|
|
137
|
+
if (this.id !== null) {
|
|
138
|
+
result.id = this.id;
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
117
141
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
142
|
+
toBinaryCoordinates(options) {
|
|
143
|
+
if (typeof options === 'function') {
|
|
144
|
+
return this._toBinaryCoordinates(options);
|
|
145
|
+
}
|
|
146
|
+
const { x, y, z } = options;
|
|
147
|
+
const size = this.extent * Math.pow(2, z);
|
|
148
|
+
const x0 = this.extent * x;
|
|
149
|
+
const y0 = this.extent * y;
|
|
150
|
+
return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
|
|
123
151
|
}
|
|
124
|
-
const {
|
|
125
|
-
x,
|
|
126
|
-
y,
|
|
127
|
-
z
|
|
128
|
-
} = options;
|
|
129
|
-
const size = this.extent * Math.pow(2, z);
|
|
130
|
-
const x0 = this.extent * x;
|
|
131
|
-
const y0 = this.extent * y;
|
|
132
|
-
return this._toBinaryCoordinates(data => project(data, x0, y0, size));
|
|
133
|
-
}
|
|
134
152
|
}
|
|
135
|
-
//# sourceMappingURL=vector-tile-feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,
|
|
1
|
+
{"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,iCAA8B;AACtD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,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;gBACR,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM;IAkBtC;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,mBAAmB,GAAG,iBAAiB;CAiBzE"}
|
|
@@ -1,46 +1,85 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
2
|
+
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
1
3
|
import VectorTileFeature from "./vector-tile-feature.js";
|
|
2
4
|
export default class VectorTileLayer {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
constructor(pbf, end) {
|
|
6
|
+
// Public
|
|
7
|
+
this.version = 1;
|
|
8
|
+
this.name = '';
|
|
9
|
+
this.extent = 4096;
|
|
10
|
+
this.length = 0;
|
|
11
|
+
// Private
|
|
12
|
+
this._pbf = pbf;
|
|
13
|
+
this._keys = [];
|
|
14
|
+
this._values = [];
|
|
15
|
+
this._features = [];
|
|
16
|
+
pbf.readFields(readLayer, this, end);
|
|
17
|
+
this.length = this._features.length;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* return feature `i` from this layer as a `VectorTileFeature`
|
|
21
|
+
*
|
|
22
|
+
* @param index
|
|
23
|
+
* @param geometryInfo
|
|
24
|
+
* @returns {VectorTileFeature}
|
|
25
|
+
*/
|
|
26
|
+
feature(i, geometryInfo) {
|
|
27
|
+
if (i < 0 || i >= this._features.length) {
|
|
28
|
+
throw new Error('feature index out of bounds');
|
|
29
|
+
}
|
|
30
|
+
this._pbf.pos = this._features[i];
|
|
31
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
32
|
+
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
26
33
|
}
|
|
27
|
-
this._pbf.pos = this._features[i];
|
|
28
|
-
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
29
|
-
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
30
|
-
}
|
|
31
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param tag
|
|
38
|
+
* @param layer
|
|
39
|
+
* @param pbf
|
|
40
|
+
*/
|
|
32
41
|
function readLayer(tag, layer, pbf) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
if (layer && pbf) {
|
|
43
|
+
if (tag === 15)
|
|
44
|
+
layer.version = pbf.readVarint();
|
|
45
|
+
else if (tag === 1)
|
|
46
|
+
layer.name = pbf.readString();
|
|
47
|
+
else if (tag === 5)
|
|
48
|
+
layer.extent = pbf.readVarint();
|
|
49
|
+
else if (tag === 2)
|
|
50
|
+
layer._features.push(pbf.pos);
|
|
51
|
+
else if (tag === 3)
|
|
52
|
+
layer._keys.push(pbf.readString());
|
|
53
|
+
else if (tag === 4)
|
|
54
|
+
layer._values.push(readValueMessage(pbf));
|
|
55
|
+
}
|
|
36
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param pbf
|
|
60
|
+
* @returns value
|
|
61
|
+
*/
|
|
37
62
|
function readValueMessage(pbf) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
let value = null;
|
|
64
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
65
|
+
while (pbf.pos < end) {
|
|
66
|
+
const tag = pbf.readVarint() >> 3;
|
|
67
|
+
value =
|
|
68
|
+
tag === 1
|
|
69
|
+
? pbf.readString()
|
|
70
|
+
: tag === 2
|
|
71
|
+
? pbf.readFloat()
|
|
72
|
+
: tag === 3
|
|
73
|
+
? pbf.readDouble()
|
|
74
|
+
: tag === 4
|
|
75
|
+
? pbf.readVarint64()
|
|
76
|
+
: tag === 5
|
|
77
|
+
? pbf.readVarint()
|
|
78
|
+
: tag === 6
|
|
79
|
+
? pbf.readSVarint()
|
|
80
|
+
: tag === 7
|
|
81
|
+
? pbf.readBoolean()
|
|
82
|
+
: null;
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
45
85
|
}
|
|
46
|
-
//# sourceMappingURL=vector-tile-layer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe
|
|
1
|
+
{"version":3,"file":"vector-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,+BAA4B;AAClD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,MAAM,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;KAAC,CAAC;gBAC3B,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM;CAGxC"}
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
+
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
1
2
|
import VectorTileLayer from "./vector-tile-layer.js";
|
|
2
3
|
export default class VectorTile {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
4
|
+
constructor(pbf, end) {
|
|
5
|
+
this.layers = pbf.readFields(readTile, {}, end);
|
|
6
|
+
}
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param tag
|
|
11
|
+
* @param layers
|
|
12
|
+
* @param pbf
|
|
13
|
+
*/
|
|
8
14
|
function readTile(tag, layers, pbf) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
if (tag === 3) {
|
|
16
|
+
if (pbf) {
|
|
17
|
+
const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
|
|
18
|
+
if (layer.length && layers) {
|
|
19
|
+
layers[layer.name] = layer;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
15
22
|
}
|
|
16
|
-
}
|
|
17
23
|
}
|
|
18
|
-
//# sourceMappingURL=vector-tile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/clip.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,kBAAkB,EAAC,
|
|
1
|
+
{"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/clip.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAK/C;;;;;;;;;;GAUG;AAEH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,kBAAkB,EAAE,EAC9B,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,KAAA,EACJ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAC,WAAW,EAAE,OAAO,CAAA;CAAC,GAC9B,kBAAkB,EAAE,GAAG,IAAI,CA4E7B"}
|