@loaders.gl/mvt 4.0.0-alpha.4 → 4.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +3124 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/helpers/binary-util-functions.js +82 -0
- package/dist/es5/helpers/binary-util-functions.js.map +1 -0
- package/dist/es5/helpers/mapbox-util-functions.js +50 -0
- package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/es5/index.js +26 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +168 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +62 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +28 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
- package/dist/es5/lib/geojson-tiler/clip.js +237 -0
- package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/convert.js +161 -0
- package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/feature.js +62 -0
- package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js +186 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/simplify.js +52 -0
- package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/tile.js +121 -0
- package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/transform.js +50 -0
- package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/wrap.js +122 -0
- package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +184 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +62 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +28 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/es5/lib/parse-mvt.js +143 -0
- package/dist/es5/lib/parse-mvt.js.map +1 -0
- package/dist/es5/lib/types.js +2 -0
- package/dist/es5/lib/types.js.map +1 -0
- package/dist/es5/mvt-loader.js +58 -0
- package/dist/es5/mvt-loader.js.map +1 -0
- package/dist/es5/workers/mvt-worker.js +6 -0
- package/dist/es5/workers/mvt-worker.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/helpers/binary-util-functions.js +73 -0
- package/dist/esm/helpers/binary-util-functions.js.map +1 -0
- package/dist/esm/helpers/mapbox-util-functions.js +41 -0
- package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +136 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +47 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile.js +19 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
- package/dist/esm/lib/geojson-tiler/clip.js +173 -0
- package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/convert.js +116 -0
- package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/feature.js +35 -0
- package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js +171 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/simplify.js +46 -0
- package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/tile.js +103 -0
- package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/transform.js +32 -0
- package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/wrap.js +67 -0
- package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +163 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +47 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +19 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/esm/lib/parse-mvt.js +138 -0
- package/dist/esm/lib/parse-mvt.js.map +1 -0
- package/dist/esm/lib/types.js +2 -0
- package/dist/esm/lib/types.js.map +1 -0
- package/dist/esm/mvt-loader.js +29 -0
- package/dist/esm/mvt-loader.js.map +1 -0
- package/dist/esm/workers/mvt-worker.js +4 -0
- package/dist/esm/workers/mvt-worker.js.map +1 -0
- package/dist/helpers/binary-util-functions.d.ts +35 -0
- package/dist/helpers/binary-util-functions.d.ts.map +1 -0
- package/dist/helpers/binary-util-functions.js +111 -74
- package/dist/helpers/mapbox-util-functions.d.ts +29 -0
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
- package/dist/helpers/mapbox-util-functions.js +78 -45
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -2
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +41 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -142
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
- package/dist/lib/geojson-tiler/clip.d.ts +16 -0
- package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/clip.js +209 -0
- package/dist/lib/geojson-tiler/convert.d.ts +10 -0
- package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/convert.js +134 -0
- package/dist/lib/geojson-tiler/feature.d.ts +3 -0
- package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/feature.js +46 -0
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
- package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
- package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/simplify.js +68 -0
- package/dist/lib/geojson-tiler/tile.d.ts +38 -0
- package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/tile.js +125 -0
- package/dist/lib/geojson-tiler/transform.d.ts +7 -0
- package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/transform.js +43 -0
- package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
- package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/wrap.js +86 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +27 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
- package/dist/lib/parse-mvt.d.ts +14 -0
- package/dist/lib/parse-mvt.d.ts.map +1 -0
- package/dist/lib/parse-mvt.js +149 -98
- package/dist/lib/types.d.ts +69 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -2
- package/dist/mvt-loader.d.ts +10 -0
- package/dist/mvt-loader.d.ts.map +1 -0
- package/dist/mvt-loader.js +43 -22
- package/dist/mvt-worker.js +845 -766
- package/dist/workers/mvt-worker.d.ts +2 -0
- package/dist/workers/mvt-worker.d.ts.map +1 -0
- package/dist/workers/mvt-worker.js +5 -4
- package/package.json +10 -9
- package/src/helpers/binary-util-functions.ts +9 -7
- package/src/helpers/mapbox-util-functions.ts +2 -2
- package/src/index.ts +7 -0
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +42 -45
- package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
- package/src/lib/geojson-tiler/LICENSE +19 -0
- package/src/lib/geojson-tiler/clip.ts +248 -0
- package/src/lib/geojson-tiler/convert.ts +158 -0
- package/src/lib/geojson-tiler/feature.ts +45 -0
- package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
- package/src/lib/geojson-tiler/simplify.ts +77 -0
- package/src/lib/geojson-tiler/tile.ts +185 -0
- package/src/lib/geojson-tiler/transform.ts +55 -0
- package/src/lib/geojson-tiler/wrap.ts +108 -0
- package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +4 -4
- package/src/lib/parse-mvt.ts +138 -93
- package/src/lib/types.ts +49 -72
- package/src/mvt-loader.ts +13 -9
- package/dist/bundle.js.map +0 -1
- package/dist/helpers/binary-util-functions.js.map +0 -1
- package/dist/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/binary-vector-tile/features-to-binary.js +0 -327
- package/dist/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/parse-mvt.js.map +0 -1
- package/dist/lib/types.js.map +0 -1
- package/dist/mvt-loader.js.map +0 -1
- package/dist/workers/mvt-worker.js.map +0 -1
- package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
- /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
- /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
package/dist/lib/parse-mvt.js
CHANGED
|
@@ -1,116 +1,167 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const gis_1 = require("@loaders.gl/gis");
|
|
7
|
+
const pbf_1 = __importDefault(require("pbf"));
|
|
8
|
+
const vector_tile_1 = __importDefault(require("./mapbox-vector-tile/vector-tile"));
|
|
9
|
+
const vector_tile_2 = __importDefault(require("./binary-vector-tile/vector-tile"));
|
|
10
|
+
/**
|
|
11
|
+
* Parse MVT arrayBuffer and return GeoJSON.
|
|
12
|
+
*
|
|
13
|
+
* @param arrayBuffer A MVT arrayBuffer
|
|
14
|
+
* @param options
|
|
15
|
+
* @returns A GeoJSON geometry object or a binary representation
|
|
16
|
+
*/
|
|
17
|
+
function parseMVT(arrayBuffer, options) {
|
|
18
|
+
const mvtOptions = normalizeOptions(options);
|
|
19
|
+
const shape = options?.gis?.format || options?.mvt?.shape;
|
|
20
|
+
switch (shape) {
|
|
21
|
+
case 'columnar-table': // binary + some JS arrays
|
|
22
|
+
return { shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions) };
|
|
23
|
+
case 'geojson-row-table': {
|
|
24
|
+
const table = {
|
|
25
|
+
shape: 'geojson-row-table',
|
|
26
|
+
data: parseToGeojson(arrayBuffer, mvtOptions)
|
|
27
|
+
};
|
|
28
|
+
return table;
|
|
29
|
+
}
|
|
30
|
+
case 'geojson':
|
|
31
|
+
return parseToGeojson(arrayBuffer, mvtOptions);
|
|
32
|
+
case 'binary-geometry':
|
|
33
|
+
return parseToBinary(arrayBuffer, mvtOptions);
|
|
34
|
+
case 'binary':
|
|
35
|
+
return parseToBinary(arrayBuffer, mvtOptions);
|
|
36
|
+
default:
|
|
37
|
+
throw new Error(shape);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = parseMVT;
|
|
41
|
+
function parseToBinary(arrayBuffer, options) {
|
|
42
|
+
const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);
|
|
43
|
+
const binaryData = (0, gis_1.flatGeojsonToBinary)(flatGeoJsonFeatures, geometryInfo);
|
|
44
|
+
// Add the original byteLength (as a reasonable approximation of the size of the binary data)
|
|
45
|
+
// TODO decide where to store extra fields like byteLength (header etc) and document
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
binaryData.byteLength = arrayBuffer.byteLength;
|
|
48
|
+
return binaryData;
|
|
49
|
+
}
|
|
50
|
+
function parseToFlatGeoJson(arrayBuffer, options) {
|
|
51
|
+
const features = [];
|
|
52
|
+
const geometryInfo = {
|
|
53
|
+
coordLength: 2,
|
|
54
|
+
pointPositionsCount: 0,
|
|
55
|
+
pointFeaturesCount: 0,
|
|
56
|
+
linePositionsCount: 0,
|
|
57
|
+
linePathsCount: 0,
|
|
58
|
+
lineFeaturesCount: 0,
|
|
59
|
+
polygonPositionsCount: 0,
|
|
60
|
+
polygonObjectsCount: 0,
|
|
61
|
+
polygonRingsCount: 0,
|
|
62
|
+
polygonFeaturesCount: 0
|
|
21
63
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
64
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
65
|
+
return [features, geometryInfo];
|
|
66
|
+
}
|
|
67
|
+
const tile = new vector_tile_2.default(new pbf_1.default(arrayBuffer));
|
|
68
|
+
const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
69
|
+
selectedLayers.forEach((layerName) => {
|
|
28
70
|
const vectorTileLayer = tile.layers[layerName];
|
|
29
|
-
const featureOptions = { ...loaderOptions,
|
|
30
|
-
layerName
|
|
31
|
-
};
|
|
32
|
-
|
|
33
71
|
if (!vectorTileLayer) {
|
|
34
|
-
|
|
72
|
+
return;
|
|
35
73
|
}
|
|
36
|
-
|
|
37
74
|
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
75
|
+
const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
|
|
76
|
+
const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
|
|
77
|
+
features.push(decodedFeature);
|
|
41
78
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return data;
|
|
79
|
+
});
|
|
80
|
+
return [features, geometryInfo];
|
|
81
|
+
}
|
|
82
|
+
function parseToGeojson(arrayBuffer, options) {
|
|
83
|
+
if (arrayBuffer.byteLength <= 0) {
|
|
84
|
+
return [];
|
|
49
85
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
86
|
+
const features = [];
|
|
87
|
+
const tile = new vector_tile_1.default(new pbf_1.default(arrayBuffer));
|
|
88
|
+
const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
|
|
89
|
+
selectedLayers.forEach((layerName) => {
|
|
90
|
+
const vectorTileLayer = tile.layers[layerName];
|
|
91
|
+
if (!vectorTileLayer) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
95
|
+
const vectorTileFeature = vectorTileLayer.feature(i);
|
|
96
|
+
const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
|
|
97
|
+
features.push(decodedFeature);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return features;
|
|
53
101
|
}
|
|
54
|
-
|
|
55
102
|
function normalizeOptions(options) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
103
|
+
if (!options?.mvt) {
|
|
104
|
+
throw new Error('mvt options required');
|
|
105
|
+
}
|
|
106
|
+
// Validate
|
|
107
|
+
const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';
|
|
108
|
+
const { tileIndex } = options.mvt;
|
|
109
|
+
const hasTileIndex = tileIndex &&
|
|
110
|
+
Number.isFinite(tileIndex.x) &&
|
|
111
|
+
Number.isFinite(tileIndex.y) &&
|
|
112
|
+
Number.isFinite(tileIndex.z);
|
|
67
113
|
if (wgs84Coordinates && !hasTileIndex) {
|
|
68
|
-
|
|
114
|
+
throw new Error('MVT Loader: WGS84 coordinates need tileIndex property');
|
|
69
115
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return options;
|
|
116
|
+
return options.mvt;
|
|
73
117
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
118
|
+
/**
|
|
119
|
+
* @param feature
|
|
120
|
+
* @param options
|
|
121
|
+
* @returns decoded feature
|
|
122
|
+
*/
|
|
123
|
+
function getDecodedFeature(feature, options, layerName) {
|
|
124
|
+
const decodedFeature = feature.toGeoJSON(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
|
|
125
|
+
// Add layer name to GeoJSON properties
|
|
126
|
+
if (options.layerProperty) {
|
|
127
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
128
|
+
}
|
|
129
|
+
return decodedFeature;
|
|
83
130
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
131
|
+
/**
|
|
132
|
+
* @param feature
|
|
133
|
+
* @param options
|
|
134
|
+
* @returns decoded binary feature
|
|
135
|
+
*/
|
|
136
|
+
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
137
|
+
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
138
|
+
// Add layer name to GeoJSON properties
|
|
139
|
+
if (options.layerProperty && decodedFeature.properties) {
|
|
140
|
+
decodedFeature.properties[options.layerProperty] = layerName;
|
|
141
|
+
}
|
|
142
|
+
return decodedFeature;
|
|
93
143
|
}
|
|
94
|
-
|
|
144
|
+
/**
|
|
145
|
+
* @param line
|
|
146
|
+
* @param feature
|
|
147
|
+
*/
|
|
95
148
|
function transformToLocalCoordinates(line, feature) {
|
|
96
|
-
|
|
97
|
-
extent
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
149
|
+
// This function transforms local coordinates in a
|
|
150
|
+
// [0 - bufferSize, this.extent + bufferSize] range to a
|
|
151
|
+
// [0 - (bufferSize / this.extent), 1 + (bufferSize / this.extent)] range.
|
|
152
|
+
// The resulting extent would be 1.
|
|
153
|
+
const { extent } = feature;
|
|
154
|
+
for (let i = 0; i < line.length; i++) {
|
|
155
|
+
const p = line[i];
|
|
156
|
+
p[0] /= extent;
|
|
157
|
+
p[1] /= extent;
|
|
158
|
+
}
|
|
105
159
|
}
|
|
106
|
-
|
|
107
160
|
function transformToLocalCoordinatesBinary(data, feature) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
161
|
+
// For the binary code path, the feature data is just
|
|
162
|
+
// one big flat array, so we just divide each value
|
|
163
|
+
const { extent } = feature;
|
|
164
|
+
for (let i = 0, il = data.length; i < il; ++i) {
|
|
165
|
+
data[i] /= extent;
|
|
166
|
+
}
|
|
115
167
|
}
|
|
116
|
-
//# sourceMappingURL=parse-mvt.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
/** For local coordinates, the tileIndex is not required */
|
|
3
|
+
type MVTLocalCoordinatesOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.
|
|
6
|
+
*/
|
|
7
|
+
coordinates: 'local';
|
|
8
|
+
tileIndex: null;
|
|
9
|
+
};
|
|
10
|
+
/** In WGS84 coordinates, the tileIndex is required */
|
|
11
|
+
type MVTWgs84CoordinatesOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* When set to `wgs84`, the parser will return a flat array of GeoJSON objects with coordinates in longitude, latitude decoded from the provided tile index.
|
|
14
|
+
*/
|
|
15
|
+
coordinates: 'wgs84';
|
|
16
|
+
/**
|
|
17
|
+
* Mandatory with `wgs84` coordinates option. An object containing tile index values (`x`, `y`,
|
|
18
|
+
* `z`) to reproject features' coordinates into WGS84.
|
|
19
|
+
*/
|
|
20
|
+
tileIndex: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
z: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {
|
|
27
|
+
/**
|
|
28
|
+
* When non-`null`, the layer name of each feature is added to
|
|
29
|
+
* `feature.properties[layerProperty]`. (A `feature.properties` object is created if the feature
|
|
30
|
+
* has no existing properties). If set to `null`, a layer name property will not be added.
|
|
31
|
+
*/
|
|
32
|
+
layerProperty?: string | number;
|
|
33
|
+
/**
|
|
34
|
+
* Optional list of layer names. If not `null`, only features belonging to the named layers will
|
|
35
|
+
* be included in the output. If `null`, features from all layers are returned.
|
|
36
|
+
*/
|
|
37
|
+
layers?: string[];
|
|
38
|
+
shape?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
39
|
+
};
|
|
40
|
+
export type MVTMapboxGeometry = {
|
|
41
|
+
type?: string;
|
|
42
|
+
id?: number;
|
|
43
|
+
length: number;
|
|
44
|
+
coordinates?: any[];
|
|
45
|
+
};
|
|
46
|
+
export type MVTMapboxCoordinates = {
|
|
47
|
+
type: string;
|
|
48
|
+
geometry: {
|
|
49
|
+
type: string;
|
|
50
|
+
coordinates: MVTMapboxGeometry;
|
|
51
|
+
};
|
|
52
|
+
properties: {
|
|
53
|
+
[x: string]: string | number | boolean | null;
|
|
54
|
+
};
|
|
55
|
+
id?: number;
|
|
56
|
+
};
|
|
57
|
+
export type MVTLoaderOptions = LoaderOptions & {
|
|
58
|
+
mvt?: MVTOptions;
|
|
59
|
+
gis?: {
|
|
60
|
+
/**
|
|
61
|
+
* When set to `true`, the parser will output the data in binary format. This is equivalent to loading the data as GeoJSON and then applying [geojsonToBinary](https://loaders.gl/modules/gis/docs/api-reference/geojson-to-binary).
|
|
62
|
+
*/
|
|
63
|
+
binary?: boolean;
|
|
64
|
+
/** @deprecated. Use options.mvt.shape */
|
|
65
|
+
format?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE5D,2DAA2D;AAC3D,KAAK,0BAA0B,GAAG;IAChC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC;AAEF,sDAAsD;AACtD,KAAK,0BAA0B,GAAG;IAChC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,SAAS,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,0BAA0B,GAAG,0BAA0B,CAAC,GAAG;IACnF;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEhC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;CAC3F,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,iBAAiB,CAAC;KAChC,CAAC;IACF,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,GAAG,CAAC,EAAE;QACJ;;WAEG;QACH,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,yCAAyC;QACzC,MAAM,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;KAC5F,CAAC;CACH,CAAC"}
|
package/dist/lib/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Loader, LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Worker loader for the Mapbox Vector Tile format
|
|
4
|
+
*/
|
|
5
|
+
export declare const MVTWorkerLoader: Loader;
|
|
6
|
+
/**
|
|
7
|
+
* Loader for the Mapbox Vector Tile format
|
|
8
|
+
*/
|
|
9
|
+
export declare const MVTLoader: LoaderWithParser;
|
|
10
|
+
//# sourceMappingURL=mvt-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvt-loader.d.ts","sourceRoot":"","sources":["../src/mvt-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAkBvE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAe7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAKvB,CAAC"}
|
package/dist/mvt-loader.js
CHANGED
|
@@ -1,26 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
options: {
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MVTLoader = exports.MVTWorkerLoader = void 0;
|
|
7
|
+
const parse_mvt_1 = __importDefault(require("./lib/parse-mvt"));
|
|
8
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
9
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
10
|
+
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
11
|
+
const DEFAULT_MVT_LOADER_OPTIONS = {
|
|
13
12
|
mvt: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
shape: 'geojson',
|
|
14
|
+
coordinates: 'local',
|
|
15
|
+
layerProperty: 'layerName',
|
|
16
|
+
layers: undefined,
|
|
17
|
+
tileIndex: null
|
|
18
18
|
}
|
|
19
|
-
}
|
|
20
19
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Worker loader for the Mapbox Vector Tile format
|
|
22
|
+
*/
|
|
23
|
+
exports.MVTWorkerLoader = {
|
|
24
|
+
name: 'Mapbox Vector Tile',
|
|
25
|
+
id: 'mvt',
|
|
26
|
+
module: 'mvt',
|
|
27
|
+
version: VERSION,
|
|
28
|
+
// Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
|
|
29
|
+
extensions: ['mvt', 'pbf'],
|
|
30
|
+
mimeTypes: [
|
|
31
|
+
'application/vnd.mapbox-vector-tile',
|
|
32
|
+
'application/x-protobuf'
|
|
33
|
+
// 'application/octet-stream'
|
|
34
|
+
],
|
|
35
|
+
worker: true,
|
|
36
|
+
category: 'geometry',
|
|
37
|
+
options: DEFAULT_MVT_LOADER_OPTIONS
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Loader for the Mapbox Vector Tile format
|
|
41
|
+
*/
|
|
42
|
+
exports.MVTLoader = {
|
|
43
|
+
...exports.MVTWorkerLoader,
|
|
44
|
+
parse: async (arrayBuffer, options) => (0, parse_mvt_1.default)(arrayBuffer, options),
|
|
45
|
+
parseSync: parse_mvt_1.default,
|
|
46
|
+
binary: true
|
|
25
47
|
};
|
|
26
|
-
//# sourceMappingURL=mvt-loader.js.map
|