@loaders.gl/mvt 4.0.0-alpha.24 → 4.0.0-alpha.25
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.min.js +6 -5
- package/dist/es5/lib/parse-mvt.js +6 -5
- package/dist/es5/lib/parse-mvt.js.map +1 -1
- package/dist/es5/lib/types.js.map +1 -1
- package/dist/es5/mvt-loader.js +1 -1
- package/dist/es5/mvt-loader.js.map +1 -1
- package/dist/esm/lib/parse-mvt.js +6 -5
- package/dist/esm/lib/parse-mvt.js.map +1 -1
- package/dist/esm/lib/types.js.map +1 -1
- package/dist/esm/mvt-loader.js +1 -1
- package/dist/esm/mvt-loader.js.map +1 -1
- package/dist/lib/parse-mvt.d.ts +2 -2
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/types.d.ts +2 -2
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/mvt-loader.d.ts +2 -2
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-worker.js +7 -6
- package/package.json +5 -5
- package/src/lib/parse-mvt.ts +8 -7
- package/src/lib/types.ts +2 -2
- package/src/mvt-loader.ts +3 -3
package/dist/dist.min.js
CHANGED
|
@@ -2179,15 +2179,16 @@
|
|
|
2179
2179
|
switch (shape) {
|
|
2180
2180
|
case "columnar-table":
|
|
2181
2181
|
return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
|
|
2182
|
-
case "geojson-
|
|
2182
|
+
case "geojson-table": {
|
|
2183
2183
|
const table = {
|
|
2184
|
-
shape: "geojson-
|
|
2185
|
-
|
|
2184
|
+
shape: "geojson-table",
|
|
2185
|
+
type: "FeatureCollection",
|
|
2186
|
+
features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)
|
|
2186
2187
|
};
|
|
2187
2188
|
return table;
|
|
2188
2189
|
}
|
|
2189
2190
|
case "geojson":
|
|
2190
|
-
return
|
|
2191
|
+
return parseToGeojsonFeatures(arrayBuffer, mvtOptions);
|
|
2191
2192
|
case "binary-geometry":
|
|
2192
2193
|
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2193
2194
|
case "binary":
|
|
@@ -2234,7 +2235,7 @@
|
|
|
2234
2235
|
});
|
|
2235
2236
|
return [features, geometryInfo];
|
|
2236
2237
|
}
|
|
2237
|
-
function
|
|
2238
|
+
function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
2238
2239
|
if (arrayBuffer.byteLength <= 0) {
|
|
2239
2240
|
return [];
|
|
2240
2241
|
}
|
|
@@ -20,16 +20,17 @@ function parseMVT(arrayBuffer, options) {
|
|
|
20
20
|
shape: 'columnar-table',
|
|
21
21
|
data: parseToBinary(arrayBuffer, mvtOptions)
|
|
22
22
|
};
|
|
23
|
-
case 'geojson-
|
|
23
|
+
case 'geojson-table':
|
|
24
24
|
{
|
|
25
25
|
var table = {
|
|
26
|
-
shape: 'geojson-
|
|
27
|
-
|
|
26
|
+
shape: 'geojson-table',
|
|
27
|
+
type: 'FeatureCollection',
|
|
28
|
+
features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)
|
|
28
29
|
};
|
|
29
30
|
return table;
|
|
30
31
|
}
|
|
31
32
|
case 'geojson':
|
|
32
|
-
return
|
|
33
|
+
return parseToGeojsonFeatures(arrayBuffer, mvtOptions);
|
|
33
34
|
case 'binary-geometry':
|
|
34
35
|
return parseToBinary(arrayBuffer, mvtOptions);
|
|
35
36
|
case 'binary':
|
|
@@ -79,7 +80,7 @@ function parseToFlatGeoJson(arrayBuffer, options) {
|
|
|
79
80
|
});
|
|
80
81
|
return [features, geometryInfo];
|
|
81
82
|
}
|
|
82
|
-
function
|
|
83
|
+
function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
83
84
|
if (arrayBuffer.byteLength <= 0) {
|
|
84
85
|
return [];
|
|
85
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-mvt.js","names":["_gis","require","_pbf","_interopRequireDefault","_vectorTile","_vectorTile2","parseMVT","arrayBuffer","options","_options$gis","_options$mvt","mvtOptions","normalizeOptions","shape","gis","format","mvt","data","parseToBinary","table","parseToGeojson","Error","_parseToFlatGeoJson","parseToFlatGeoJson","_parseToFlatGeoJson2","_slicedToArray2","default","flatGeoJsonFeatures","geometryInfo","binaryData","flatGeojsonToBinary","byteLength","features","coordLength","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","tile","BinaryVectorTile","Protobuf","selectedLayers","Array","isArray","layers","Object","keys","forEach","layerName","vectorTileLayer","i","length","vectorTileFeature","feature","decodedFeature","getDecodedFeatureBinary","push","VectorTile","getDecodedFeature","_options$mvt2","wgs84Coordinates","coordinates","tileIndex","hasTileIndex","Number","isFinite","x","y","z","toGeoJSON","transformToLocalCoordinates","layerProperty","properties","toBinaryCoordinates","transformToLocalCoordinatesBinary","line","extent","p","il"],"sources":["../../../src/lib/parse-mvt.ts"],"sourcesContent":["import {flatGeojsonToBinary} from '@loaders.gl/gis';\nimport type {\n FlatFeature,\n Feature,\n GeojsonGeometryInfo,\n BinaryFeatureCollection,\n GeoJSONRowTable\n} from '@loaders.gl/schema';\nimport Protobuf from 'pbf';\n\nimport type {MVTMapboxCoordinates, MVTOptions, MVTLoaderOptions} from '../lib/types';\n\nimport VectorTile from './mapbox-vector-tile/vector-tile';\nimport BinaryVectorTile from './binary-vector-tile/vector-tile';\nimport VectorTileFeatureBinary from './binary-vector-tile/vector-tile-feature';\nimport VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';\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?: MVTLoaderOptions) {\n const mvtOptions = normalizeOptions(options);\n\n const shape = options?.gis?.format || options?.mvt?.shape;\n switch (shape) {\n case 'columnar-table': // binary + some JS arrays\n return {shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions)};\n case 'geojson-row-table': {\n const table: GeoJSONRowTable = {\n shape: 'geojson-row-table',\n data: parseToGeojson(arrayBuffer, mvtOptions)\n };\n return table;\n }\n case 'geojson':\n return parseToGeojson(arrayBuffer, mvtOptions);\n case 'binary-geometry':\n return parseToBinary(arrayBuffer, mvtOptions);\n case 'binary':\n return parseToBinary(arrayBuffer, mvtOptions);\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseToBinary(arrayBuffer: ArrayBuffer, options: MVTOptions): BinaryFeatureCollection {\n const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);\n\n const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, 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 binaryData.byteLength = arrayBuffer.byteLength;\n return binaryData;\n}\n\nfunction parseToFlatGeoJson(\n arrayBuffer: ArrayBuffer,\n options: MVTOptions\n): [FlatFeature[], GeojsonGeometryInfo] {\n const features: FlatFeature[] = [];\n const geometryInfo: GeojsonGeometryInfo = {\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 return [features, geometryInfo];\n }\n\n const tile = new BinaryVectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers =\n options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);\n const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return [features, geometryInfo];\n}\n\nfunction parseToGeojson(arrayBuffer: ArrayBuffer, options: MVTOptions): Feature[] {\n if (arrayBuffer.byteLength <= 0) {\n return [];\n }\n\n const features: MVTMapboxCoordinates[] = [];\n const tile = new VectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i);\n const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return features as Feature[];\n}\n\nfunction normalizeOptions(options?: MVTLoaderOptions): MVTOptions {\n if (!options?.mvt) {\n throw new Error('mvt options required');\n }\n\n // Validate\n const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';\n const {tileIndex} = options.mvt;\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('MVT Loader: WGS84 coordinates need tileIndex property');\n }\n\n return options.mvt;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded feature\n */\nfunction getDecodedFeature(\n feature: VectorTileFeatureMapBox,\n options: MVTOptions,\n layerName: string\n): MVTMapboxCoordinates {\n const decodedFeature = feature.toGeoJSON(\n // @ts-expect-error What is going on here?\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] = 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 layerName: string\n): FlatFeature {\n const decodedFeature = feature.toBinaryCoordinates(\n // @ts-expect-error What is going on here?\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] = 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"],"mappings":";;;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA;AAQA,IAAAC,IAAA,GAAAC,sBAAA,CAAAF,OAAA;AAIA,IAAAG,WAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,YAAA,GAAAF,sBAAA,CAAAF,OAAA;AAWe,SAASK,QAAQA,CAACC,WAAwB,EAAEC,OAA0B,EAAE;EAAA,IAAAC,YAAA,EAAAC,YAAA;EACrF,IAAMC,UAAU,GAAGC,gBAAgB,CAACJ,OAAO,CAAC;EAE5C,IAAMK,KAAK,GAAG,CAAAL,OAAO,aAAPA,OAAO,wBAAAC,YAAA,GAAPD,OAAO,CAAEM,GAAG,cAAAL,YAAA,uBAAZA,YAAA,CAAcM,MAAM,MAAIP,OAAO,aAAPA,OAAO,wBAAAE,YAAA,GAAPF,OAAO,CAAEQ,GAAG,cAAAN,YAAA,uBAAZA,YAAA,CAAcG,K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CAAC,CAAC;IACjB2B,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;IACdC,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;EAChB;AACF;AAEA,SAASF,iCAAiCA,CAAC9D,IAAc,EAAEyC,OAAsB,EAAE;EAGjF,IAAOuB,MAAM,GAAIvB,OAAO,CAAjBuB,MAAM;EACb,KAAK,IAAI1B,CAAC,GAAG,CAAC,EAAE4B,EAAE,GAAGlE,IAAI,CAACuC,MAAM,EAAED,CAAC,GAAG4B,EAAE,EAAE,EAAE5B,CAAC,EAAE;IAC7CtC,IAAI,CAACsC,CAAC,CAAC,IAAI0B,MAAM;EACnB;AACF"}
|
|
1
|
+
{"version":3,"file":"parse-mvt.js","names":["_gis","require","_pbf","_interopRequireDefault","_vectorTile","_vectorTile2","parseMVT","arrayBuffer","options","_options$gis","_options$mvt","mvtOptions","normalizeOptions","shape","gis","format","mvt","data","parseToBinary","table","type","features","parseToGeojsonFeatures","Error","_parseToFlatGeoJson","parseToFlatGeoJson","_parseToFlatGeoJson2","_slicedToArray2","default","flatGeoJsonFeatures","geometryInfo","binaryData","flatGeojsonToBinary","byteLength","coordLength","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","tile","BinaryVectorTile","Protobuf","selectedLayers","Array","isArray","layers","Object","keys","forEach","layerName","vectorTileLayer","i","length","vectorTileFeature","feature","decodedFeature","getDecodedFeatureBinary","push","VectorTile","getDecodedFeature","_options$mvt2","wgs84Coordinates","coordinates","tileIndex","hasTileIndex","Number","isFinite","x","y","z","toGeoJSON","transformToLocalCoordinates","layerProperty","properties","toBinaryCoordinates","transformToLocalCoordinatesBinary","line","extent","p","il"],"sources":["../../../src/lib/parse-mvt.ts"],"sourcesContent":["import {flatGeojsonToBinary} from '@loaders.gl/gis';\nimport type {\n FlatFeature,\n Feature,\n GeojsonGeometryInfo,\n BinaryFeatureCollection,\n GeoJSONTable\n} from '@loaders.gl/schema';\nimport Protobuf from 'pbf';\n\nimport type {MVTMapboxCoordinates, MVTOptions, MVTLoaderOptions} from '../lib/types';\n\nimport VectorTile from './mapbox-vector-tile/vector-tile';\nimport BinaryVectorTile from './binary-vector-tile/vector-tile';\nimport VectorTileFeatureBinary from './binary-vector-tile/vector-tile-feature';\nimport VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';\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?: MVTLoaderOptions) {\n const mvtOptions = normalizeOptions(options);\n\n const shape = options?.gis?.format || options?.mvt?.shape;\n switch (shape) {\n case 'columnar-table': // binary + some JS arrays\n return {shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions)};\n case 'geojson-table': {\n const table: GeoJSONTable = {\n shape: 'geojson-table',\n type: 'FeatureCollection',\n features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)\n };\n return table;\n }\n case 'geojson':\n return parseToGeojsonFeatures(arrayBuffer, mvtOptions);\n case 'binary-geometry':\n return parseToBinary(arrayBuffer, mvtOptions);\n case 'binary':\n return parseToBinary(arrayBuffer, mvtOptions);\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseToBinary(arrayBuffer: ArrayBuffer, options: MVTOptions): BinaryFeatureCollection {\n const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);\n\n const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, 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 binaryData.byteLength = arrayBuffer.byteLength;\n return binaryData;\n}\n\nfunction parseToFlatGeoJson(\n arrayBuffer: ArrayBuffer,\n options: MVTOptions\n): [FlatFeature[], GeojsonGeometryInfo] {\n const features: FlatFeature[] = [];\n const geometryInfo: GeojsonGeometryInfo = {\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 return [features, geometryInfo];\n }\n\n const tile = new BinaryVectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers =\n options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);\n const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return [features, geometryInfo];\n}\n\nfunction parseToGeojsonFeatures(arrayBuffer: ArrayBuffer, options: MVTOptions): Feature[] {\n if (arrayBuffer.byteLength <= 0) {\n return [];\n }\n\n const features: MVTMapboxCoordinates[] = [];\n const tile = new VectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i);\n const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return features as Feature[];\n}\n\nfunction normalizeOptions(options?: MVTLoaderOptions): MVTOptions {\n if (!options?.mvt) {\n throw new Error('mvt options required');\n }\n\n // Validate\n const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';\n const {tileIndex} = options.mvt;\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('MVT Loader: WGS84 coordinates need tileIndex property');\n }\n\n return options.mvt;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded feature\n */\nfunction getDecodedFeature(\n feature: VectorTileFeatureMapBox,\n options: MVTOptions,\n layerName: string\n): MVTMapboxCoordinates {\n const decodedFeature = feature.toGeoJSON(\n // @ts-expect-error What is going on here?\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] = 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 layerName: string\n): FlatFeature {\n const decodedFeature = feature.toBinaryCoordinates(\n // @ts-expect-error What is going on here?\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] = 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"],"mappings":";;;;;;;;AAAA,IAAAA,IAAA,GAAAC,OAAA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cAAc,GAAGD,OAAO,CAACoB,mBAAmB,CAEhDvE,OAAO,CAAC2D,WAAW,KAAK,OAAO,GAAG3D,OAAO,CAAC4D,SAAS,GAAGY,iCACxD,CAAC;EAGD,IAAIxE,OAAO,CAACqE,aAAa,IAAIjB,cAAc,CAACkB,UAAU,EAAE;IACtDlB,cAAc,CAACkB,UAAU,CAACtE,OAAO,CAACqE,aAAa,CAAC,GAAGvB,SAAS;EAC9D;EAEA,OAAOM,cAAc;AACvB;AAMA,SAASgB,2BAA2BA,CAACK,IAAc,EAAEtB,OAAsB,EAAQ;EAKjF,IAAOuB,MAAM,GAAIvB,OAAO,CAAjBuB,MAAM;EACb,KAAK,IAAI1B,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGyB,IAAI,CAACxB,MAAM,EAAED,CAAC,EAAE,EAAE;IACpC,IAAM2B,CAAC,GAAGF,IAAI,CAACzB,CAAC,CAAC;IACjB2B,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;IACdC,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;EAChB;AACF;AAEA,SAASF,iCAAiCA,CAAC/D,IAAc,EAAE0C,OAAsB,EAAE;EAGjF,IAAOuB,MAAM,GAAIvB,OAAO,CAAjBuB,MAAM;EACb,KAAK,IAAI1B,CAAC,GAAG,CAAC,EAAE4B,EAAE,GAAGnE,IAAI,CAACwC,MAAM,EAAED,CAAC,GAAG4B,EAAE,EAAE,EAAE5B,CAAC,EAAE;IAC7CvC,IAAI,CAACuC,CAAC,CAAC,IAAI0B,MAAM;EACnB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/lib/types.ts"],"sourcesContent":["import type {LoaderOptions} from '@loaders.gl/loader-utils';\n\n/** For local coordinates, the tileIndex is not required */\ntype MVTLocalCoordinatesOptions = {\n /**\n * When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.\n */\n coordinates: 'local';\n tileIndex: null;\n};\n\n/** In WGS84 coordinates, the tileIndex is required */\ntype MVTWgs84CoordinatesOptions = {\n /**\n * 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.\n */\n coordinates?: 'wgs84';\n\n /**\n * Mandatory with `wgs84` coordinates option. An object containing tile index values (`x`, `y`,\n * `z`) to reproject features' coordinates into WGS84.\n */\n tileIndex?: {x: number; y: number; z: number};\n};\n\nexport type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {\n /**\n * When non-`null`, the layer name of each feature is added to\n * `feature.properties[layerProperty]`. (A `feature.properties` object is created if the feature\n * has no existing properties). If set to `null`, a layer name property will not be added.\n */\n layerProperty?: string | number;\n\n /**\n * Optional list of layer names. If not `null`, only features belonging to the named layers will\n * be included in the output. If `null`, features from all layers are returned.\n */\n layers?: string[];\n shape?: 'geojson-
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/lib/types.ts"],"sourcesContent":["import type {LoaderOptions} from '@loaders.gl/loader-utils';\n\n/** For local coordinates, the tileIndex is not required */\ntype MVTLocalCoordinatesOptions = {\n /**\n * When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.\n */\n coordinates: 'local';\n tileIndex: null;\n};\n\n/** In WGS84 coordinates, the tileIndex is required */\ntype MVTWgs84CoordinatesOptions = {\n /**\n * 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.\n */\n coordinates?: 'wgs84';\n\n /**\n * Mandatory with `wgs84` coordinates option. An object containing tile index values (`x`, `y`,\n * `z`) to reproject features' coordinates into WGS84.\n */\n tileIndex?: {x: number; y: number; z: number};\n};\n\nexport type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {\n /**\n * When non-`null`, the layer name of each feature is added to\n * `feature.properties[layerProperty]`. (A `feature.properties` object is created if the feature\n * has no existing properties). If set to `null`, a layer name property will not be added.\n */\n layerProperty?: string | number;\n\n /**\n * Optional list of layer names. If not `null`, only features belonging to the named layers will\n * be included in the output. If `null`, features from all layers are returned.\n */\n layers?: string[];\n shape?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';\n};\n\nexport type MVTMapboxGeometry = {\n type?: string;\n id?: number;\n length: number;\n coordinates?: any[];\n};\n\nexport type MVTMapboxCoordinates = {\n type: string;\n geometry: {\n type: string;\n coordinates: MVTMapboxGeometry;\n };\n properties: {[x: string]: string | number | boolean | null};\n id?: number;\n};\n\nexport type MVTLoaderOptions = LoaderOptions & {\n mvt?: MVTOptions;\n gis?: {\n /**\n * 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).\n */\n binary?: boolean;\n /** @deprecated. Use options.mvt.shape */\n format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';\n };\n};\n"],"mappings":""}
|
package/dist/es5/mvt-loader.js
CHANGED
|
@@ -11,7 +11,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
11
11
|
var _parseMvt = _interopRequireDefault(require("./lib/parse-mvt"));
|
|
12
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
var VERSION = typeof "4.0.0-alpha.
|
|
14
|
+
var VERSION = typeof "4.0.0-alpha.25" !== 'undefined' ? "4.0.0-alpha.25" : 'latest';
|
|
15
15
|
var MVTWorkerLoader = {
|
|
16
16
|
name: 'Mapbox Vector Tile',
|
|
17
17
|
id: 'mvt',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mvt-loader.js","names":["_parseMvt","_interopRequireDefault","require","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","VERSION","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","mvt","shape","coordinates","layerProperty","layers","undefined","tileIndex","exports","MVTLoader","parse","_parse","_asyncToGenerator2","_regenerator","mark","_callee","arrayBuffer","wrap","_callee$","_context","prev","next","abrupt","parseMVT","stop","_x","_x2","parseSync","binary"],"sources":["../../src/mvt-loader.ts"],"sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {MVTLoaderOptions} from './lib/types';\n// import type {\n// Feature,\n// BinaryFeatureCollection,\n//
|
|
1
|
+
{"version":3,"file":"mvt-loader.js","names":["_parseMvt","_interopRequireDefault","require","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","VERSION","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","mvt","shape","coordinates","layerProperty","layers","undefined","tileIndex","exports","MVTLoader","parse","_parse","_asyncToGenerator2","_regenerator","mark","_callee","arrayBuffer","wrap","_callee$","_context","prev","next","abrupt","parseMVT","stop","_x","_x2","parseSync","binary"],"sources":["../../src/mvt-loader.ts"],"sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {MVTLoaderOptions} from './lib/types';\n// import type {\n// Feature,\n// BinaryFeatureCollection,\n// GeoJSONTable,\n// Geometry,\n// GeoJsonProperties\n// } from '@loaders.gl/schema';\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 any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,\n never,\n MVTLoaderOptions\n> = {\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 shape: 'geojson',\n coordinates: 'local',\n layerProperty: 'layerName',\n layers: undefined,\n tileIndex: null\n }\n }\n};\n\n/**\n * Loader for the Mapbox Vector Tile format\n */\nexport const MVTLoader: LoaderWithParser<\n any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,\n never,\n MVTLoaderOptions\n> = {\n ...MVTWorkerLoader,\n parse: async (arrayBuffer, options?: MVTLoaderOptions) => parseMVT(arrayBuffer, options),\n parseSync: parseMVT,\n binary: true\n};\n"],"mappings":";;;;;;;;;;AASA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuC,SAAAC,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA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C,KAAK,EAAE,SAAS;MAChBC,WAAW,EAAE,OAAO;MACpBC,aAAa,EAAE,WAAW;MAC1BC,MAAM,EAAEC,SAAS;MACjBC,SAAS,EAAE;IACb;EACF;AACF,CAAC;AAACC,OAAA,CAAAjB,eAAA,GAAAA,eAAA;AAKK,IAAMkB,SAIZ,GAAAhC,aAAA,CAAAA,aAAA,KACIc,eAAe;EAClBmB,KAAK;IAAA,IAAAC,MAAA,OAAAC,kBAAA,CAAA1B,OAAA,EAAA2B,YAAA,CAAA3B,OAAA,CAAA4B,IAAA,CAAE,SAAAC,QAAOC,WAAW,EAAEhB,OAA0B;MAAA,OAAAa,YAAA,CAAA3B,OAAA,CAAA+B,IAAA,UAAAC,SAAAC,QAAA;QAAA,kBAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAE,IAAA;UAAA;YAAA,OAAAF,QAAA,CAAAG,MAAA,WAAK,IAAAC,iBAAQ,EAACP,WAAW,EAAEhB,OAAO,CAAC;UAAA;UAAA;YAAA,OAAAmB,QAAA,CAAAK,IAAA;QAAA;MAAA,GAAAT,OAAA;IAAA;IAAA,SAAAL,MAAAe,EAAA,EAAAC,GAAA;MAAA,OAAAf,MAAA,CAAAnC,KAAA,OAAAI,SAAA;IAAA;IAAA,OAAA8B,KAAA;EAAA;EACxFiB,SAAS,EAAEJ,iBAAQ;EACnBK,MAAM,EAAE;AAAI,EACb;AAACpB,OAAA,CAAAC,SAAA,GAAAA,SAAA"}
|
|
@@ -12,16 +12,17 @@ export default function parseMVT(arrayBuffer, options) {
|
|
|
12
12
|
shape: 'columnar-table',
|
|
13
13
|
data: parseToBinary(arrayBuffer, mvtOptions)
|
|
14
14
|
};
|
|
15
|
-
case 'geojson-
|
|
15
|
+
case 'geojson-table':
|
|
16
16
|
{
|
|
17
17
|
const table = {
|
|
18
|
-
shape: 'geojson-
|
|
19
|
-
|
|
18
|
+
shape: 'geojson-table',
|
|
19
|
+
type: 'FeatureCollection',
|
|
20
|
+
features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)
|
|
20
21
|
};
|
|
21
22
|
return table;
|
|
22
23
|
}
|
|
23
24
|
case 'geojson':
|
|
24
|
-
return
|
|
25
|
+
return parseToGeojsonFeatures(arrayBuffer, mvtOptions);
|
|
25
26
|
case 'binary-geometry':
|
|
26
27
|
return parseToBinary(arrayBuffer, mvtOptions);
|
|
27
28
|
case 'binary':
|
|
@@ -68,7 +69,7 @@ function parseToFlatGeoJson(arrayBuffer, options) {
|
|
|
68
69
|
});
|
|
69
70
|
return [features, geometryInfo];
|
|
70
71
|
}
|
|
71
|
-
function
|
|
72
|
+
function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
72
73
|
if (arrayBuffer.byteLength <= 0) {
|
|
73
74
|
return [];
|
|
74
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-mvt.js","names":["flatGeojsonToBinary","Protobuf","VectorTile","BinaryVectorTile","parseMVT","arrayBuffer","options","_options$gis","_options$mvt","mvtOptions","normalizeOptions","shape","gis","format","mvt","data","parseToBinary","table","parseToGeojson","Error","flatGeoJsonFeatures","geometryInfo","parseToFlatGeoJson","binaryData","byteLength","features","coordLength","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","tile","selectedLayers","Array","isArray","layers","Object","keys","forEach","layerName","vectorTileLayer","i","length","vectorTileFeature","feature","decodedFeature","getDecodedFeatureBinary","push","getDecodedFeature","_options$mvt2","wgs84Coordinates","coordinates","tileIndex","hasTileIndex","Number","isFinite","x","y","z","toGeoJSON","transformToLocalCoordinates","layerProperty","properties","toBinaryCoordinates","transformToLocalCoordinatesBinary","line","extent","p","il"],"sources":["../../../src/lib/parse-mvt.ts"],"sourcesContent":["import {flatGeojsonToBinary} from '@loaders.gl/gis';\nimport type {\n FlatFeature,\n Feature,\n GeojsonGeometryInfo,\n BinaryFeatureCollection,\n GeoJSONRowTable\n} from '@loaders.gl/schema';\nimport Protobuf from 'pbf';\n\nimport type {MVTMapboxCoordinates, MVTOptions, MVTLoaderOptions} from '../lib/types';\n\nimport VectorTile from './mapbox-vector-tile/vector-tile';\nimport BinaryVectorTile from './binary-vector-tile/vector-tile';\nimport VectorTileFeatureBinary from './binary-vector-tile/vector-tile-feature';\nimport VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';\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?: MVTLoaderOptions) {\n const mvtOptions = normalizeOptions(options);\n\n const shape = options?.gis?.format || options?.mvt?.shape;\n switch (shape) {\n case 'columnar-table': // binary + some JS arrays\n return {shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions)};\n case 'geojson-row-table': {\n const table: GeoJSONRowTable = {\n shape: 'geojson-row-table',\n data: parseToGeojson(arrayBuffer, mvtOptions)\n };\n return table;\n }\n case 'geojson':\n return parseToGeojson(arrayBuffer, mvtOptions);\n case 'binary-geometry':\n return parseToBinary(arrayBuffer, mvtOptions);\n case 'binary':\n return parseToBinary(arrayBuffer, mvtOptions);\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseToBinary(arrayBuffer: ArrayBuffer, options: MVTOptions): BinaryFeatureCollection {\n const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);\n\n const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, 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 binaryData.byteLength = arrayBuffer.byteLength;\n return binaryData;\n}\n\nfunction parseToFlatGeoJson(\n arrayBuffer: ArrayBuffer,\n options: MVTOptions\n): [FlatFeature[], GeojsonGeometryInfo] {\n const features: FlatFeature[] = [];\n const geometryInfo: GeojsonGeometryInfo = {\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 return [features, geometryInfo];\n }\n\n const tile = new BinaryVectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers =\n options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);\n const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return [features, geometryInfo];\n}\n\nfunction parseToGeojson(arrayBuffer: ArrayBuffer, options: MVTOptions): Feature[] {\n if (arrayBuffer.byteLength <= 0) {\n return [];\n }\n\n const features: MVTMapboxCoordinates[] = [];\n const tile = new VectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i);\n const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return features as Feature[];\n}\n\nfunction normalizeOptions(options?: MVTLoaderOptions): MVTOptions {\n if (!options?.mvt) {\n throw new Error('mvt options required');\n }\n\n // Validate\n const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';\n const {tileIndex} = options.mvt;\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('MVT Loader: WGS84 coordinates need tileIndex property');\n }\n\n return options.mvt;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded feature\n */\nfunction getDecodedFeature(\n feature: VectorTileFeatureMapBox,\n options: MVTOptions,\n layerName: string\n): MVTMapboxCoordinates {\n const decodedFeature = feature.toGeoJSON(\n // @ts-expect-error What is going on here?\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] = 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 layerName: string\n): FlatFeature {\n const decodedFeature = feature.toBinaryCoordinates(\n // @ts-expect-error What is going on here?\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] = 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"],"mappings":"AAAA,SAAQA,mBAAmB,QAAO,iBAAiB;AAQnD,OAAOC,QAAQ,MAAM,KAAK;A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c,CAACiB,UAAU,CAAC7D,OAAO,CAAC4D,aAAa,CAAC,GAAGtB,SAAS;EAC9D;EAEA,OAAOM,cAAc;AACvB;AAMA,SAASe,2BAA2BA,CAACK,IAAc,EAAErB,OAAsB,EAAQ;EAKjF,MAAM;IAACsB;EAAM,CAAC,GAAGtB,OAAO;EACxB,KAAK,IAAIH,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGwB,IAAI,CAACvB,MAAM,EAAED,CAAC,EAAE,EAAE;IACpC,MAAM0B,CAAC,GAAGF,IAAI,CAACxB,CAAC,CAAC;IACjB0B,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;IACdC,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;EAChB;AACF;AAEA,SAASF,iCAAiCA,CAACtD,IAAc,EAAEkC,OAAsB,EAAE;EAGjF,MAAM;IAACsB;EAAM,CAAC,GAAGtB,OAAO;EACxB,KAAK,IAAIH,CAAC,GAAG,CAAC,EAAE2B,EAAE,GAAG1D,IAAI,CAACgC,MAAM,EAAED,CAAC,GAAG2B,EAAE,EAAE,EAAE3B,CAAC,EAAE;IAC7C/B,IAAI,CAAC+B,CAAC,CAAC,IAAIyB,MAAM;EACnB;AACF"}
|
|
1
|
+
{"version":3,"file":"parse-mvt.js","names":["flatGeojsonToBinary","Protobuf","VectorTile","BinaryVectorTile","parseMVT","arrayBuffer","options","_options$gis","_options$mvt","mvtOptions","normalizeOptions","shape","gis","format","mvt","data","parseToBinary","table","type","features","parseToGeojsonFeatures","Error","flatGeoJsonFeatures","geometryInfo","parseToFlatGeoJson","binaryData","byteLength","coordLength","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","tile","selectedLayers","Array","isArray","layers","Object","keys","forEach","layerName","vectorTileLayer","i","length","vectorTileFeature","feature","decodedFeature","getDecodedFeatureBinary","push","getDecodedFeature","_options$mvt2","wgs84Coordinates","coordinates","tileIndex","hasTileIndex","Number","isFinite","x","y","z","toGeoJSON","transformToLocalCoordinates","layerProperty","properties","toBinaryCoordinates","transformToLocalCoordinatesBinary","line","extent","p","il"],"sources":["../../../src/lib/parse-mvt.ts"],"sourcesContent":["import {flatGeojsonToBinary} from '@loaders.gl/gis';\nimport type {\n FlatFeature,\n Feature,\n GeojsonGeometryInfo,\n BinaryFeatureCollection,\n GeoJSONTable\n} from '@loaders.gl/schema';\nimport Protobuf from 'pbf';\n\nimport type {MVTMapboxCoordinates, MVTOptions, MVTLoaderOptions} from '../lib/types';\n\nimport VectorTile from './mapbox-vector-tile/vector-tile';\nimport BinaryVectorTile from './binary-vector-tile/vector-tile';\nimport VectorTileFeatureBinary from './binary-vector-tile/vector-tile-feature';\nimport VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';\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?: MVTLoaderOptions) {\n const mvtOptions = normalizeOptions(options);\n\n const shape = options?.gis?.format || options?.mvt?.shape;\n switch (shape) {\n case 'columnar-table': // binary + some JS arrays\n return {shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions)};\n case 'geojson-table': {\n const table: GeoJSONTable = {\n shape: 'geojson-table',\n type: 'FeatureCollection',\n features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)\n };\n return table;\n }\n case 'geojson':\n return parseToGeojsonFeatures(arrayBuffer, mvtOptions);\n case 'binary-geometry':\n return parseToBinary(arrayBuffer, mvtOptions);\n case 'binary':\n return parseToBinary(arrayBuffer, mvtOptions);\n default:\n throw new Error(shape);\n }\n}\n\nfunction parseToBinary(arrayBuffer: ArrayBuffer, options: MVTOptions): BinaryFeatureCollection {\n const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);\n\n const binaryData = flatGeojsonToBinary(flatGeoJsonFeatures, 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 binaryData.byteLength = arrayBuffer.byteLength;\n return binaryData;\n}\n\nfunction parseToFlatGeoJson(\n arrayBuffer: ArrayBuffer,\n options: MVTOptions\n): [FlatFeature[], GeojsonGeometryInfo] {\n const features: FlatFeature[] = [];\n const geometryInfo: GeojsonGeometryInfo = {\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 return [features, geometryInfo];\n }\n\n const tile = new BinaryVectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers =\n options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);\n const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return [features, geometryInfo];\n}\n\nfunction parseToGeojsonFeatures(arrayBuffer: ArrayBuffer, options: MVTOptions): Feature[] {\n if (arrayBuffer.byteLength <= 0) {\n return [];\n }\n\n const features: MVTMapboxCoordinates[] = [];\n const tile = new VectorTile(new Protobuf(arrayBuffer));\n\n const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);\n\n selectedLayers.forEach((layerName: string) => {\n const vectorTileLayer = tile.layers[layerName];\n if (!vectorTileLayer) {\n return;\n }\n\n for (let i = 0; i < vectorTileLayer.length; i++) {\n const vectorTileFeature = vectorTileLayer.feature(i);\n const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);\n features.push(decodedFeature);\n }\n });\n\n return features as Feature[];\n}\n\nfunction normalizeOptions(options?: MVTLoaderOptions): MVTOptions {\n if (!options?.mvt) {\n throw new Error('mvt options required');\n }\n\n // Validate\n const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';\n const {tileIndex} = options.mvt;\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('MVT Loader: WGS84 coordinates need tileIndex property');\n }\n\n return options.mvt;\n}\n\n/**\n * @param feature\n * @param options\n * @returns decoded feature\n */\nfunction getDecodedFeature(\n feature: VectorTileFeatureMapBox,\n options: MVTOptions,\n layerName: string\n): MVTMapboxCoordinates {\n const decodedFeature = feature.toGeoJSON(\n // @ts-expect-error What is going on here?\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] = 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 layerName: string\n): FlatFeature {\n const decodedFeature = feature.toBinaryCoordinates(\n // @ts-expect-error What is going on here?\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] = 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"],"mappings":"AAAA,SAAQA,mBAAmB,QAAO,iBAAiB;AAQnD,OAAOC,QAAQ,MAAM,KAAK;AAI1B,OAAOC,UAAU,MAAM,kCAAkC;AACzD,OAAOC,gBAAgB,MAAM,kCAAkC;AAW/D,eAAe,SAASC,QAAQA,CAACC,WAAwB,EAAEC,OAA0B,EAAE;EAAA,IAAAC,YAAA,EAAAC,YAAA;EACrF,MAAMC,UAAU,GAAGC,gBAAgB,CAACJ,OAAO,CAAC;EAE5C,MAAMK,KAAK,GAAG,CAAAL,OAAO,aAAPA,OAAO,wBAAAC,YAAA,GAAPD,OAAO,CAAEM,GAAG,cAAAL,YAAA,uBAAZA,YAAA,CAAcM,MAAM,MAAIP,OAAO,aAAPA,OAAO,wBAAAE,YAAA,GAAPF,OAAO,CAAEQ,GAAG,cAAAN,YAAA,uBAAZA,YAAA,CAAcG,KAAK;EACzD,QAAQA,KAAK;IACX,KAAK,gBAAgB;MACnB,OAAO;QAACA,KAAK,EAAE,gBAAgB;QAAEI,IAAI,EAAEC,aAAa,CAACX,WAAW,EAAEI,UAAU;MAAC,CAAC;IAChF,KAAK,eAAe;MAAE;QACpB,MAAMQ,KAAmB,GAAG;UAC1BN,KAAK,EAAE,eAAe;UACtBO,IAAI,EAAE,mBAAmB;UACzBC,QAAQ,EAAEC,sBAAsB,CAACf,WAAW,EAAEI,UAAU;QAC1D,CAAC;QACD,OAAOQ,KAAK;MACd;IACA,KAAK,SAAS;MACZ,OAAOG,sBAAsB,CAACf,WAAW,EAAEI,UAAU,CAAC;IACxD,KAAK,iBAAiB;MACpB,OAAOO,aAAa,CAACX,WAAW,EAAEI,UAAU,CAAC;IAC/C,KAA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AAc;AACvB;AAOA,SAASC,uBAAuBA,CAC9BF,OAAgC,EAChC5C,OAAmB,EACnBuC,SAAiB,EACJ;EACb,MAAMM,cAAc,GAAGD,OAAO,CAACmB,mBAAmB,CAEhD/D,OAAO,CAACmD,WAAW,KAAK,OAAO,GAAGnD,OAAO,CAACoD,SAAS,GAAGY,iCACxD,CAAC;EAGD,IAAIhE,OAAO,CAAC6D,aAAa,IAAIhB,cAAc,CAACiB,UAAU,EAAE;IACtDjB,cAAc,CAACiB,UAAU,CAAC9D,OAAO,CAAC6D,aAAa,CAAC,GAAGtB,SAAS;EAC9D;EAEA,OAAOM,cAAc;AACvB;AAMA,SAASe,2BAA2BA,CAACK,IAAc,EAAErB,OAAsB,EAAQ;EAKjF,MAAM;IAACsB;EAAM,CAAC,GAAGtB,OAAO;EACxB,KAAK,IAAIH,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGwB,IAAI,CAACvB,MAAM,EAAED,CAAC,EAAE,EAAE;IACpC,MAAM0B,CAAC,GAAGF,IAAI,CAACxB,CAAC,CAAC;IACjB0B,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;IACdC,CAAC,CAAC,CAAC,CAAC,IAAID,MAAM;EAChB;AACF;AAEA,SAASF,iCAAiCA,CAACvD,IAAc,EAAEmC,OAAsB,EAAE;EAGjF,MAAM;IAACsB;EAAM,CAAC,GAAGtB,OAAO;EACxB,KAAK,IAAIH,CAAC,GAAG,CAAC,EAAE2B,EAAE,GAAG3D,IAAI,CAACiC,MAAM,EAAED,CAAC,GAAG2B,EAAE,EAAE,EAAE3B,CAAC,EAAE;IAC7ChC,IAAI,CAACgC,CAAC,CAAC,IAAIyB,MAAM;EACnB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/lib/types.ts"],"sourcesContent":["import type {LoaderOptions} from '@loaders.gl/loader-utils';\n\n/** For local coordinates, the tileIndex is not required */\ntype MVTLocalCoordinatesOptions = {\n /**\n * When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.\n */\n coordinates: 'local';\n tileIndex: null;\n};\n\n/** In WGS84 coordinates, the tileIndex is required */\ntype MVTWgs84CoordinatesOptions = {\n /**\n * 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.\n */\n coordinates?: 'wgs84';\n\n /**\n * Mandatory with `wgs84` coordinates option. An object containing tile index values (`x`, `y`,\n * `z`) to reproject features' coordinates into WGS84.\n */\n tileIndex?: {x: number; y: number; z: number};\n};\n\nexport type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {\n /**\n * When non-`null`, the layer name of each feature is added to\n * `feature.properties[layerProperty]`. (A `feature.properties` object is created if the feature\n * has no existing properties). If set to `null`, a layer name property will not be added.\n */\n layerProperty?: string | number;\n\n /**\n * Optional list of layer names. If not `null`, only features belonging to the named layers will\n * be included in the output. If `null`, features from all layers are returned.\n */\n layers?: string[];\n shape?: 'geojson-
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/lib/types.ts"],"sourcesContent":["import type {LoaderOptions} from '@loaders.gl/loader-utils';\n\n/** For local coordinates, the tileIndex is not required */\ntype MVTLocalCoordinatesOptions = {\n /**\n * When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.\n */\n coordinates: 'local';\n tileIndex: null;\n};\n\n/** In WGS84 coordinates, the tileIndex is required */\ntype MVTWgs84CoordinatesOptions = {\n /**\n * 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.\n */\n coordinates?: 'wgs84';\n\n /**\n * Mandatory with `wgs84` coordinates option. An object containing tile index values (`x`, `y`,\n * `z`) to reproject features' coordinates into WGS84.\n */\n tileIndex?: {x: number; y: number; z: number};\n};\n\nexport type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {\n /**\n * When non-`null`, the layer name of each feature is added to\n * `feature.properties[layerProperty]`. (A `feature.properties` object is created if the feature\n * has no existing properties). If set to `null`, a layer name property will not be added.\n */\n layerProperty?: string | number;\n\n /**\n * Optional list of layer names. If not `null`, only features belonging to the named layers will\n * be included in the output. If `null`, features from all layers are returned.\n */\n layers?: string[];\n shape?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';\n};\n\nexport type MVTMapboxGeometry = {\n type?: string;\n id?: number;\n length: number;\n coordinates?: any[];\n};\n\nexport type MVTMapboxCoordinates = {\n type: string;\n geometry: {\n type: string;\n coordinates: MVTMapboxGeometry;\n };\n properties: {[x: string]: string | number | boolean | null};\n id?: number;\n};\n\nexport type MVTLoaderOptions = LoaderOptions & {\n mvt?: MVTOptions;\n gis?: {\n /**\n * 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).\n */\n binary?: boolean;\n /** @deprecated. Use options.mvt.shape */\n format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';\n };\n};\n"],"mappings":""}
|
package/dist/esm/mvt-loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import parseMVT from './lib/parse-mvt';
|
|
2
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
2
|
+
const VERSION = typeof "4.0.0-alpha.25" !== 'undefined' ? "4.0.0-alpha.25" : 'latest';
|
|
3
3
|
export const MVTWorkerLoader = {
|
|
4
4
|
name: 'Mapbox Vector Tile',
|
|
5
5
|
id: 'mvt',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mvt-loader.js","names":["parseMVT","VERSION","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","mvt","shape","coordinates","layerProperty","layers","undefined","tileIndex","MVTLoader","parse","arrayBuffer","parseSync","binary"],"sources":["../../src/mvt-loader.ts"],"sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {MVTLoaderOptions} from './lib/types';\n// import type {\n// Feature,\n// BinaryFeatureCollection,\n//
|
|
1
|
+
{"version":3,"file":"mvt-loader.js","names":["parseMVT","VERSION","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","mvt","shape","coordinates","layerProperty","layers","undefined","tileIndex","MVTLoader","parse","arrayBuffer","parseSync","binary"],"sources":["../../src/mvt-loader.ts"],"sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {MVTLoaderOptions} from './lib/types';\n// import type {\n// Feature,\n// BinaryFeatureCollection,\n// GeoJSONTable,\n// Geometry,\n// GeoJsonProperties\n// } from '@loaders.gl/schema';\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 any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,\n never,\n MVTLoaderOptions\n> = {\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 shape: 'geojson',\n coordinates: 'local',\n layerProperty: 'layerName',\n layers: undefined,\n tileIndex: null\n }\n }\n};\n\n/**\n * Loader for the Mapbox Vector Tile format\n */\nexport const MVTLoader: LoaderWithParser<\n any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,\n never,\n MVTLoaderOptions\n> = {\n ...MVTWorkerLoader,\n parse: async (arrayBuffer, options?: MVTLoaderOptions) => parseMVT(arrayBuffer, options),\n parseSync: parseMVT,\n binary: true\n};\n"],"mappings":"AASA,OAAOA,QAAQ,MAAM,iBAAiB;AAItC,MAAMC,OAAO,GAAG,uBAAkB,KAAK,WAAW,sBAAiB,QAAQ;AAK3E,OAAO,MAAMC,eAIZ,GAAG;EACFC,IAAI,EAAE,oBAAoB;EAC1BC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EACbC,OAAO,EAAEL,OAAO;EAEhBM,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;EAC1BC,SAAS,EAAE,CACT,oCAAoC,EACpC,wBAAwB,CAEzB;EACDC,MAAM,EAAE,IAAI;EACZC,QAAQ,EAAE,UAAU;EACpBC,OAAO,EAAE;IACPC,GAAG,EAAE;MACHC,KAAK,EAAE,SAAS;MAChBC,WAAW,EAAE,OAAO;MACpBC,aAAa,EAAE,WAAW;MAC1BC,MAAM,EAAEC,SAAS;MACjBC,SAAS,EAAE;IACb;EACF;AACF,CAAC;AAKD,OAAO,MAAMC,SAIZ,GAAG;EACF,GAAGjB,eAAe;EAClBkB,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEV,OAA0B,KAAKX,QAAQ,CAACqB,WAAW,EAAEV,OAAO,CAAC;EACxFW,SAAS,EAAEtB,QAAQ;EACnBuB,MAAM,EAAE;AACV,CAAC"}
|
package/dist/lib/parse-mvt.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Feature, BinaryFeatureCollection,
|
|
1
|
+
import type { Feature, BinaryFeatureCollection, GeoJSONTable } from '@loaders.gl/schema';
|
|
2
2
|
import type { MVTLoaderOptions } from '../lib/types';
|
|
3
3
|
/**
|
|
4
4
|
* Parse MVT arrayBuffer and return GeoJSON.
|
|
@@ -7,7 +7,7 @@ import type { MVTLoaderOptions } from '../lib/types';
|
|
|
7
7
|
* @param options
|
|
8
8
|
* @returns A GeoJSON geometry object or a binary representation
|
|
9
9
|
*/
|
|
10
|
-
export default function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions): BinaryFeatureCollection |
|
|
10
|
+
export default function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions): BinaryFeatureCollection | GeoJSONTable | Feature<import("geojson").Geometry, import("geojson").GeoJsonProperties>[] | {
|
|
11
11
|
shape: string;
|
|
12
12
|
data: BinaryFeatureCollection;
|
|
13
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,OAAO,EAEP,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,OAAO,EAEP,uBAAuB,EACvB,YAAY,EACb,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAmC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAOrF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,gBAAgB;;;EAwBpF"}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOption
|
|
|
35
35
|
* be included in the output. If `null`, features from all layers are returned.
|
|
36
36
|
*/
|
|
37
37
|
layers?: string[];
|
|
38
|
-
shape?: 'geojson-
|
|
38
|
+
shape?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
39
39
|
};
|
|
40
40
|
export type MVTMapboxGeometry = {
|
|
41
41
|
type?: string;
|
|
@@ -62,7 +62,7 @@ export type MVTLoaderOptions = LoaderOptions & {
|
|
|
62
62
|
*/
|
|
63
63
|
binary?: boolean;
|
|
64
64
|
/** @deprecated. Use options.mvt.shape */
|
|
65
|
-
format?: 'geojson-
|
|
65
|
+
format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
66
66
|
};
|
|
67
67
|
};
|
|
68
68
|
export {};
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +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,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,SAAS,CAAC,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;CAC/C,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,
|
|
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,CAAC,EAAE,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ACH,CAAC"}
|
package/dist/mvt-loader.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import type { MVTLoaderOptions } from './lib/types';
|
|
|
3
3
|
/**
|
|
4
4
|
* Worker loader for the Mapbox Vector Tile format
|
|
5
5
|
*/
|
|
6
|
-
export declare const MVTWorkerLoader: Loader<any, // BinaryFeatureCollection |
|
|
6
|
+
export declare const MVTWorkerLoader: Loader<any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
|
|
7
7
|
never, MVTLoaderOptions>;
|
|
8
8
|
/**
|
|
9
9
|
* Loader for the Mapbox Vector Tile format
|
|
10
10
|
*/
|
|
11
|
-
export declare const MVTLoader: LoaderWithParser<any, // BinaryFeatureCollection |
|
|
11
|
+
export declare const MVTLoader: LoaderWithParser<any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
|
|
12
12
|
never, MVTLoaderOptions>;
|
|
13
13
|
//# sourceMappingURL=mvt-loader.d.ts.map
|
package/dist/mvt-loader.d.ts.map
CHANGED
|
@@ -1 +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;AACvE,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAclD;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC,GAAG,EAAE,
|
|
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;AACvE,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAclD;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC,GAAG,EAAE,iFAAiF;AACtF,KAAK,EACL,gBAAgB,CAwBjB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAAgB,CACtC,GAAG,EAAE,iFAAiF;AACtF,KAAK,EACL,gBAAgB,CAMjB,CAAC"}
|
package/dist/mvt-worker.js
CHANGED
|
@@ -2037,15 +2037,16 @@
|
|
|
2037
2037
|
switch (shape) {
|
|
2038
2038
|
case "columnar-table":
|
|
2039
2039
|
return { shape: "columnar-table", data: parseToBinary(arrayBuffer, mvtOptions) };
|
|
2040
|
-
case "geojson-
|
|
2040
|
+
case "geojson-table": {
|
|
2041
2041
|
const table = {
|
|
2042
|
-
shape: "geojson-
|
|
2043
|
-
|
|
2042
|
+
shape: "geojson-table",
|
|
2043
|
+
type: "FeatureCollection",
|
|
2044
|
+
features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)
|
|
2044
2045
|
};
|
|
2045
2046
|
return table;
|
|
2046
2047
|
}
|
|
2047
2048
|
case "geojson":
|
|
2048
|
-
return
|
|
2049
|
+
return parseToGeojsonFeatures(arrayBuffer, mvtOptions);
|
|
2049
2050
|
case "binary-geometry":
|
|
2050
2051
|
return parseToBinary(arrayBuffer, mvtOptions);
|
|
2051
2052
|
case "binary":
|
|
@@ -2092,7 +2093,7 @@
|
|
|
2092
2093
|
});
|
|
2093
2094
|
return [features, geometryInfo];
|
|
2094
2095
|
}
|
|
2095
|
-
function
|
|
2096
|
+
function parseToGeojsonFeatures(arrayBuffer, options) {
|
|
2096
2097
|
if (arrayBuffer.byteLength <= 0) {
|
|
2097
2098
|
return [];
|
|
2098
2099
|
}
|
|
@@ -2154,7 +2155,7 @@
|
|
|
2154
2155
|
}
|
|
2155
2156
|
|
|
2156
2157
|
// src/mvt-loader.ts
|
|
2157
|
-
var VERSION = true ? "4.0.0-alpha.
|
|
2158
|
+
var VERSION = true ? "4.0.0-alpha.25" : "latest";
|
|
2158
2159
|
var MVTWorkerLoader = {
|
|
2159
2160
|
name: "Mapbox Vector Tile",
|
|
2160
2161
|
id: "mvt",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/mvt",
|
|
3
3
|
"description": "Loader for Mapbox Vector Tiles",
|
|
4
|
-
"version": "4.0.0-alpha.
|
|
4
|
+
"version": "4.0.0-alpha.25",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@loaders.gl/gis": "4.0.0-alpha.
|
|
36
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
37
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
35
|
+
"@loaders.gl/gis": "4.0.0-alpha.25",
|
|
36
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.25",
|
|
37
|
+
"@loaders.gl/schema": "4.0.0-alpha.25",
|
|
38
38
|
"@math.gl/polygon": "^3.5.1",
|
|
39
39
|
"pbf": "^3.2.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/pbf": "^3.0.2"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "40135f391b869388dbbcd615bbe51178d0c370be"
|
|
45
45
|
}
|
package/src/lib/parse-mvt.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
Feature,
|
|
5
5
|
GeojsonGeometryInfo,
|
|
6
6
|
BinaryFeatureCollection,
|
|
7
|
-
|
|
7
|
+
GeoJSONTable
|
|
8
8
|
} from '@loaders.gl/schema';
|
|
9
9
|
import Protobuf from 'pbf';
|
|
10
10
|
|
|
@@ -29,15 +29,16 @@ export default function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOp
|
|
|
29
29
|
switch (shape) {
|
|
30
30
|
case 'columnar-table': // binary + some JS arrays
|
|
31
31
|
return {shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions)};
|
|
32
|
-
case 'geojson-
|
|
33
|
-
const table:
|
|
34
|
-
shape: 'geojson-
|
|
35
|
-
|
|
32
|
+
case 'geojson-table': {
|
|
33
|
+
const table: GeoJSONTable = {
|
|
34
|
+
shape: 'geojson-table',
|
|
35
|
+
type: 'FeatureCollection',
|
|
36
|
+
features: parseToGeojsonFeatures(arrayBuffer, mvtOptions)
|
|
36
37
|
};
|
|
37
38
|
return table;
|
|
38
39
|
}
|
|
39
40
|
case 'geojson':
|
|
40
|
-
return
|
|
41
|
+
return parseToGeojsonFeatures(arrayBuffer, mvtOptions);
|
|
41
42
|
case 'binary-geometry':
|
|
42
43
|
return parseToBinary(arrayBuffer, mvtOptions);
|
|
43
44
|
case 'binary':
|
|
@@ -101,7 +102,7 @@ function parseToFlatGeoJson(
|
|
|
101
102
|
return [features, geometryInfo];
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
function
|
|
105
|
+
function parseToGeojsonFeatures(arrayBuffer: ArrayBuffer, options: MVTOptions): Feature[] {
|
|
105
106
|
if (arrayBuffer.byteLength <= 0) {
|
|
106
107
|
return [];
|
|
107
108
|
}
|
package/src/lib/types.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOption
|
|
|
36
36
|
* be included in the output. If `null`, features from all layers are returned.
|
|
37
37
|
*/
|
|
38
38
|
layers?: string[];
|
|
39
|
-
shape?: 'geojson-
|
|
39
|
+
shape?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export type MVTMapboxGeometry = {
|
|
@@ -64,6 +64,6 @@ export type MVTLoaderOptions = LoaderOptions & {
|
|
|
64
64
|
*/
|
|
65
65
|
binary?: boolean;
|
|
66
66
|
/** @deprecated. Use options.mvt.shape */
|
|
67
|
-
format?: 'geojson-
|
|
67
|
+
format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
68
68
|
};
|
|
69
69
|
};
|
package/src/mvt-loader.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type {MVTLoaderOptions} from './lib/types';
|
|
|
3
3
|
// import type {
|
|
4
4
|
// Feature,
|
|
5
5
|
// BinaryFeatureCollection,
|
|
6
|
-
//
|
|
6
|
+
// GeoJSONTable,
|
|
7
7
|
// Geometry,
|
|
8
8
|
// GeoJsonProperties
|
|
9
9
|
// } from '@loaders.gl/schema';
|
|
@@ -17,7 +17,7 @@ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
|
17
17
|
* Worker loader for the Mapbox Vector Tile format
|
|
18
18
|
*/
|
|
19
19
|
export const MVTWorkerLoader: Loader<
|
|
20
|
-
any, // BinaryFeatureCollection |
|
|
20
|
+
any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
|
|
21
21
|
never,
|
|
22
22
|
MVTLoaderOptions
|
|
23
23
|
> = {
|
|
@@ -49,7 +49,7 @@ export const MVTWorkerLoader: Loader<
|
|
|
49
49
|
* Loader for the Mapbox Vector Tile format
|
|
50
50
|
*/
|
|
51
51
|
export const MVTLoader: LoaderWithParser<
|
|
52
|
-
any, // BinaryFeatureCollection |
|
|
52
|
+
any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
|
|
53
53
|
never,
|
|
54
54
|
MVTLoaderOptions
|
|
55
55
|
> = {
|