@loaders.gl/mvt 3.1.3 → 4.0.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/bundle.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/helpers/binary-util-functions.js +77 -111
- package/dist/helpers/binary-util-functions.js.map +1 -0
- package/dist/helpers/mapbox-util-functions.js +45 -78
- package/dist/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/index.js +2 -6
- package/dist/index.js.map +1 -0
- package/dist/{es5/lib → lib}/binary-vector-tile/LICENSE.txt +0 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +143 -138
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +58 -85
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile.js +19 -25
- package/dist/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/{es5/lib → lib}/mapbox-vector-tile/LICENSE.txt +0 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +193 -161
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +58 -83
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.js +19 -25
- package/dist/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/lib/parse-mvt.js +101 -127
- package/dist/lib/parse-mvt.js.map +1 -0
- package/dist/lib/types.js +2 -2
- package/dist/{es5/lib → lib}/types.js.map +0 -0
- package/dist/mvt-loader.js +23 -42
- package/dist/mvt-loader.js.map +1 -0
- package/dist/mvt-worker.js +1 -1
- package/dist/workers/mvt-worker.js +4 -5
- package/dist/workers/mvt-worker.js.map +1 -0
- package/package.json +8 -8
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/helpers/binary-util-functions.js +0 -98
- package/dist/es5/helpers/binary-util-functions.js.map +0 -1
- package/dist/es5/helpers/mapbox-util-functions.js +0 -62
- package/dist/es5/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/es5/index.js +0 -20
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +0 -191
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +0 -77
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +0 -35
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +0 -217
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +0 -77
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +0 -35
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/es5/lib/parse-mvt.js +0 -132
- package/dist/es5/lib/parse-mvt.js.map +0 -1
- package/dist/es5/lib/types.js +0 -2
- package/dist/es5/mvt-loader.js +0 -71
- package/dist/es5/mvt-loader.js.map +0 -1
- package/dist/es5/workers/mvt-worker.js +0 -8
- package/dist/es5/workers/mvt-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/helpers/binary-util-functions.js +0 -84
- package/dist/esm/helpers/binary-util-functions.js.map +0 -1
- package/dist/esm/helpers/mapbox-util-functions.js +0 -49
- package/dist/esm/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/LICENSE.txt +0 -31
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +0 -157
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +0 -64
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile.js +0 -23
- package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +0 -31
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +0 -202
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +0 -64
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +0 -23
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/esm/lib/parse-mvt.js +0 -117
- package/dist/esm/lib/parse-mvt.js.map +0 -1
- package/dist/esm/lib/types.js +0 -2
- package/dist/esm/lib/types.js.map +0 -1
- package/dist/esm/mvt-loader.js +0 -26
- package/dist/esm/mvt-loader.js.map +0 -1
- package/dist/esm/workers/mvt-worker.js +0 -4
- package/dist/esm/workers/mvt-worker.js.map +0 -1
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import VectorTile from './mapbox-vector-tile/vector-tile';
|
|
2
|
-
import BinaryVectorTile from './binary-vector-tile/vector-tile';
|
|
3
|
-
import { flatGeojsonToBinary } from '@loaders.gl/gis';
|
|
4
|
-
import Protobuf from 'pbf';
|
|
5
|
-
export default function parseMVT(arrayBuffer, options) {
|
|
6
|
-
options = normalizeOptions(options);
|
|
7
|
-
const features = [];
|
|
8
|
-
|
|
9
|
-
if (options) {
|
|
10
|
-
const binary = options.gis.format === 'binary';
|
|
11
|
-
const geometryInfo = {
|
|
12
|
-
coordLength: 2,
|
|
13
|
-
pointPositionsCount: 0,
|
|
14
|
-
pointFeaturesCount: 0,
|
|
15
|
-
linePositionsCount: 0,
|
|
16
|
-
linePathsCount: 0,
|
|
17
|
-
lineFeaturesCount: 0,
|
|
18
|
-
polygonPositionsCount: 0,
|
|
19
|
-
polygonObjectsCount: 0,
|
|
20
|
-
polygonRingsCount: 0,
|
|
21
|
-
polygonFeaturesCount: 0
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
if (arrayBuffer.byteLength > 0) {
|
|
25
|
-
const tile = binary ? new BinaryVectorTile(new Protobuf(arrayBuffer)) : new VectorTile(new Protobuf(arrayBuffer));
|
|
26
|
-
const loaderOptions = options.mvt;
|
|
27
|
-
const selectedLayers = Array.isArray(loaderOptions.layers) ? loaderOptions.layers : Object.keys(tile.layers);
|
|
28
|
-
selectedLayers.forEach(layerName => {
|
|
29
|
-
const vectorTileLayer = tile.layers[layerName];
|
|
30
|
-
const featureOptions = { ...loaderOptions,
|
|
31
|
-
layerName
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
if (!vectorTileLayer) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
39
|
-
const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
|
|
40
|
-
const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
|
|
41
|
-
features.push(decodedFeature);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (binary) {
|
|
47
|
-
const data = flatGeojsonToBinary(features, geometryInfo);
|
|
48
|
-
data.byteLength = arrayBuffer.byteLength;
|
|
49
|
-
return data;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return features;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function normalizeOptions(options) {
|
|
57
|
-
if (options) {
|
|
58
|
-
options = { ...options,
|
|
59
|
-
mvt: options.mvt || {},
|
|
60
|
-
gis: options.gis || {}
|
|
61
|
-
};
|
|
62
|
-
const wgs84Coordinates = options.coordinates === 'wgs84';
|
|
63
|
-
const {
|
|
64
|
-
tileIndex
|
|
65
|
-
} = options;
|
|
66
|
-
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
67
|
-
|
|
68
|
-
if (wgs84Coordinates && !hasTileIndex) {
|
|
69
|
-
throw new Error('MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return options;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function getDecodedFeature(feature, options) {
|
|
77
|
-
const decodedFeature = feature.toGeoJSON(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
|
|
78
|
-
|
|
79
|
-
if (options.layerProperty) {
|
|
80
|
-
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return decodedFeature;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function getDecodedFeatureBinary(feature, options) {
|
|
87
|
-
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
88
|
-
|
|
89
|
-
if (options.layerProperty && decodedFeature.properties) {
|
|
90
|
-
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return decodedFeature;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function transformToLocalCoordinates(line, feature) {
|
|
97
|
-
const {
|
|
98
|
-
extent
|
|
99
|
-
} = feature;
|
|
100
|
-
|
|
101
|
-
for (let i = 0; i < line.length; i++) {
|
|
102
|
-
const p = line[i];
|
|
103
|
-
p[0] /= extent;
|
|
104
|
-
p[1] /= extent;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function transformToLocalCoordinatesBinary(data, feature) {
|
|
109
|
-
const {
|
|
110
|
-
extent
|
|
111
|
-
} = feature;
|
|
112
|
-
|
|
113
|
-
for (let i = 0, il = data.length; i < il; ++i) {
|
|
114
|
-
data[i] /= extent;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=parse-mvt.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/parse-mvt.ts"],"names":["VectorTile","BinaryVectorTile","flatGeojsonToBinary","Protobuf","parseMVT","arrayBuffer","options","normalizeOptions","features","binary","gis","format","geometryInfo","coordLength","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","byteLength","tile","loaderOptions","mvt","selectedLayers","Array","isArray","layers","Object","keys","forEach","layerName","vectorTileLayer","featureOptions","i","length","vectorTileFeature","feature","decodedFeature","getDecodedFeatureBinary","getDecodedFeature","push","data","wgs84Coordinates","coordinates","tileIndex","hasTileIndex","Number","isFinite","x","y","z","Error","toGeoJSON","transformToLocalCoordinates","layerProperty","properties","toBinaryCoordinates","transformToLocalCoordinatesBinary","line","extent","p","il"],"mappings":"AACA,OAAOA,UAAP,MAAuB,kCAAvB;AACA,OAAOC,gBAAP,MAA6B,kCAA7B;AAEA,SAAQC,mBAAR,QAAkC,iBAAlC;AACA,OAAOC,QAAP,MAAqB,KAArB;AAcA,eAAe,SAASC,QAAT,CAAkBC,WAAlB,EAA4CC,OAA5C,EAAqE;AAClFA,EAAAA,OAAO,GAAGC,gBAAgB,CAACD,OAAD,CAA1B;AACA,QAAME,QAAgD,GAAG,EAAzD;;AAEA,MAAIF,OAAJ,EAAa;AACX,UAAMG,MAAM,GAAGH,OAAO,CAACI,GAAR,CAAYC,MAAZ,KAAuB,QAAtC;AACA,UAA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AG4B,EAAtC,EAA0C,EAAE5B,CAA5C,EAA+C;AAC7CQ,IAAAA,IAAI,CAACR,CAAD,CAAJ,IAAW0B,MAAX;AACD;AACF","sourcesContent":["// import {VectorTile} from '@mapbox/vector-tile';\nimport VectorTile from './mapbox-vector-tile/vector-tile';\nimport BinaryVectorTile from './binary-vector-tile/vector-tile';\n\nimport {flatGeojsonToBinary} from '@loaders.gl/gis';\nimport Protobuf from 'pbf';\nimport type {FlatFeature} from '@loaders.gl/schema';\nimport type {MvtMapboxCoordinates, MvtOptions} from '../lib/types';\nimport VectorTileFeatureBinary from './binary-vector-tile/vector-tile-feature';\nimport VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';\nimport {LoaderOptions} from '@loaders.gl/loader-utils';\n\n/**\n * Parse MVT arrayBuffer and return GeoJSON.\n *\n * @param arrayBuffer A MVT arrayBuffer\n * @param options\n * @returns A GeoJSON geometry object or a binary representation\n */\nexport default function parseMVT(arrayBuffer: ArrayBuffer, options?: LoaderOptions) {\n options = normalizeOptions(options);\n const features: (FlatFeature | MvtMapboxCoordinates)[] = [];\n\n if (options) {\n const binary = options.gis.format === 'binary';\n const geometryInfo = {\n coordLength: 2,\n pointPositionsCount: 0,\n pointFeaturesCount: 0,\n linePositionsCount: 0,\n linePathsCount: 0,\n lineFeaturesCount: 0,\n polygonPositionsCount: 0,\n polygonObjectsCount: 0,\n polygonRingsCount: 0,\n polygonFeaturesCount: 0\n };\n\n if (arrayBuffer.byteLength > 0) {\n const tile = binary\n ? new BinaryVectorTile(new Protobuf(arrayBuffer))\n : new VectorTile(new Protobuf(arrayBuffer));\n const loaderOptions = options.mvt;\n\n const selectedLayers = Array.isArray(loaderOptions.layers)\n ? loaderOptions.layers\n : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n const featureOptions = {...loaderOptions, layerName};\n\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);\n\n const decodedFeature = binary\n ? getDecodedFeatureBinary(vectorTileFeature as VectorTileFeatureBinary, featureOptions)\n : getDecodedFeature(vectorTileFeature as VectorTileFeatureMapBox, featureOptions);\n features.push(decodedFeature);\n }\n });\n }\n\n if (binary) {\n const data = flatGeojsonToBinary(features as FlatFeature[], geometryInfo);\n // Add the original byteLength (as a reasonable approximation of the size of the binary data)\n // TODO decide where to store extra fields like byteLength (header etc) and document\n // @ts-ignore\n data.byteLength = arrayBuffer.byteLength;\n return data;\n }\n }\n return features;\n}\n\n/**\n * @param options\n * @returns options\n */\nfunction normalizeOptions(options: LoaderOptions | undefined) {\n if (options) {\n options = {\n ...options,\n mvt: options.mvt || {},\n gis: options.gis || {}\n };\n\n // Validate\n const wgs84Coordinates = options.coordinates === 'wgs84';\n const {tileIndex} = options;\n const hasTileIndex =\n tileIndex &&\n Number.isFinite(tileIndex.x) &&\n Number.isFinite(tileIndex.y) &&\n Number.isFinite(tileIndex.z);\n\n if (wgs84Coordinates && !hasTileIndex) {\n throw new Error(\n 'MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.'\n );\n }\n }\n return options;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded feature\n */\nfunction getDecodedFeature(\n feature: VectorTileFeatureMapBox,\n options: MvtOptions\n): MvtMapboxCoordinates {\n const decodedFeature = feature.toGeoJSON(\n options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates\n );\n\n // Add layer name to GeoJSON properties\n if (options.layerProperty) {\n decodedFeature.properties[options.layerProperty] = options.layerName;\n }\n\n return decodedFeature;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded binary feature\n */\nfunction getDecodedFeatureBinary(\n feature: VectorTileFeatureBinary,\n options: MvtOptions\n): FlatFeature {\n const decodedFeature = feature.toBinaryCoordinates(\n options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary\n );\n\n // Add layer name to GeoJSON properties\n if (options.layerProperty && decodedFeature.properties) {\n decodedFeature.properties[options.layerProperty] = options.layerName;\n }\n\n return decodedFeature;\n}\n\n/**\n * @param line\n * @param feature\n */\nfunction transformToLocalCoordinates(line: number[], feature: {extent: any}): void {\n // This function transforms local coordinates in a\n // [0 - bufferSize, this.extent + bufferSize] range to a\n // [0 - (bufferSize / this.extent), 1 + (bufferSize / this.extent)] range.\n // The resulting extent would be 1.\n const {extent} = feature;\n for (let i = 0; i < line.length; i++) {\n const p = line[i];\n p[0] /= extent;\n p[1] /= extent;\n }\n}\n\nfunction transformToLocalCoordinatesBinary(data: number[], feature: {extent: any}) {\n // For the binary code path, the feature data is just\n // one big flat array, so we just divide each value\n const {extent} = feature;\n for (let i = 0, il = data.length; i < il; ++i) {\n data[i] /= extent;\n }\n}\n"],"file":"parse-mvt.js"}
|
package/dist/esm/lib/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
|
package/dist/esm/mvt-loader.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import parseMVT from './lib/parse-mvt';
|
|
2
|
-
const VERSION = typeof "3.1.3" !== 'undefined' ? "3.1.3" : 'latest';
|
|
3
|
-
export const MVTWorkerLoader = {
|
|
4
|
-
name: 'Mapbox Vector Tile',
|
|
5
|
-
id: 'mvt',
|
|
6
|
-
module: 'mvt',
|
|
7
|
-
version: VERSION,
|
|
8
|
-
extensions: ['mvt', 'pbf'],
|
|
9
|
-
mimeTypes: ['application/vnd.mapbox-vector-tile', 'application/x-protobuf'],
|
|
10
|
-
worker: true,
|
|
11
|
-
category: 'geometry',
|
|
12
|
-
options: {
|
|
13
|
-
mvt: {
|
|
14
|
-
coordinates: 'local',
|
|
15
|
-
layerProperty: 'layerName',
|
|
16
|
-
layers: null,
|
|
17
|
-
tileIndex: null
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
export const MVTLoader = { ...MVTWorkerLoader,
|
|
22
|
-
parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),
|
|
23
|
-
parseSync: parseMVT,
|
|
24
|
-
binary: true
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=mvt-loader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mvt-loader.ts"],"names":["parseMVT","VERSION","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","mvt","coordinates","layerProperty","layers","tileIndex","MVTLoader","parse","arrayBuffer","parseSync","binary"],"mappings":"AACA,OAAOA,QAAP,MAAqB,iBAArB;AAIA,MAAMC,OAAO,GAAG,mBAAuB,WAAvB,aAAmD,QAAnE;AAKA,OAAO,MAAMC,eAAuB,GAAG;AACrCC,EAAAA,IAAI,EAAE,oBAD+B;AAErCC,EAAAA,EAAE,EAAE,KAFiC;AAGrCC,EAAAA,MAAM,EAAE,KAH6B;AAIrCC,EAAAA,OAAO,EAAEL,OAJ4B;AAMrCM,EAAAA,UAAU,EAAE,CAAC,KAAD,EAAQ,KAAR,CANyB;AAOrCC,EAAAA,SAAS,EAAE,CACT,oCADS,EAET,wBAFS,CAP0B;AAYrCC,EAAAA,MAAM,EAAE,IAZ6B;AAarCC,EAAAA,QAAQ,EAAE,UAb2B;AAcrCC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AACHC,MAAAA,WAAW,EAAE,OADV;AAEHC,MAAAA,aAAa,EAAE,WAFZ;AAGHC,MAAAA,MAAM,EAAE,IAHL;AAIHC,MAAAA,SAAS,EAAE;AAJR;AADE;AAd4B,CAAhC;AA2BP,OAAO,MAAMC,SAA2B,GAAG,EACzC,GAAGf,eADsC;AAEzCgB,EAAAA,KAAK,EAAE,OAAOC,WAAP,EAAoBR,OAApB,KAAgCX,QAAQ,CAACmB,WAAD,EAAcR,OAAd,CAFN;AAGzCS,EAAAA,SAAS,EAAEpB,QAH8B;AAIzCqB,EAAAA,MAAM,EAAE;AAJiC,CAApC","sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport parseMVT from './lib/parse-mvt';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for the Mapbox Vector Tile format\n */\nexport const MVTWorkerLoader: Loader = {\n name: 'Mapbox Vector Tile',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'\n extensions: ['mvt', 'pbf'],\n mimeTypes: [\n 'application/vnd.mapbox-vector-tile',\n 'application/x-protobuf'\n // 'application/octet-stream'\n ],\n worker: true,\n category: 'geometry',\n options: {\n mvt: {\n coordinates: 'local',\n layerProperty: 'layerName',\n layers: null,\n tileIndex: null\n }\n }\n};\n\n/**\n * Loader for the Mapbox Vector Tile format\n */\nexport const MVTLoader: LoaderWithParser = {\n ...MVTWorkerLoader,\n parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),\n parseSync: parseMVT,\n binary: true\n};\n"],"file":"mvt-loader.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/workers/mvt-worker.ts"],"names":["MVTLoader","createLoaderWorker"],"mappings":"AAAA,SAAQA,SAAR,QAAwB,eAAxB;AACA,SAAQC,kBAAR,QAAiC,0BAAjC;AAEAA,kBAAkB,CAACD,SAAD,CAAlB","sourcesContent":["import {MVTLoader} from '../mvt-loader';\nimport {createLoaderWorker} from '@loaders.gl/loader-utils';\n\ncreateLoaderWorker(MVTLoader);\n"],"file":"mvt-worker.js"}
|