@loaders.gl/mvt 4.0.0-alpha.4 → 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.
Files changed (48) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/dist.min.js +2289 -0
  4. package/dist/helpers/binary-util-functions.d.ts +35 -0
  5. package/dist/helpers/binary-util-functions.d.ts.map +1 -0
  6. package/dist/helpers/binary-util-functions.js +8 -5
  7. package/dist/helpers/binary-util-functions.js.map +1 -1
  8. package/dist/helpers/mapbox-util-functions.d.ts +29 -0
  9. package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +41 -0
  13. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
  14. package/dist/lib/binary-vector-tile/vector-tile-feature.js +31 -30
  15. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  16. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
  17. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
  18. package/dist/lib/binary-vector-tile/vector-tile-layer.js +2 -2
  19. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  20. package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
  21. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
  22. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +27 -0
  23. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
  24. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
  25. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
  26. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
  27. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
  28. package/dist/lib/parse-mvt.d.ts +17 -0
  29. package/dist/lib/parse-mvt.d.ts.map +1 -0
  30. package/dist/lib/parse-mvt.js +6 -5
  31. package/dist/lib/parse-mvt.js.map +1 -1
  32. package/dist/lib/types.d.ts +28 -0
  33. package/dist/lib/types.d.ts.map +1 -0
  34. package/dist/mvt-loader.d.ts +10 -0
  35. package/dist/mvt-loader.d.ts.map +1 -0
  36. package/dist/mvt-loader.js +1 -1
  37. package/dist/mvt-worker.js +103 -98
  38. package/dist/workers/mvt-worker.d.ts +2 -0
  39. package/dist/workers/mvt-worker.d.ts.map +1 -0
  40. package/package.json +8 -7
  41. package/src/helpers/binary-util-functions.ts +9 -7
  42. package/src/lib/binary-vector-tile/vector-tile-feature.ts +36 -44
  43. package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
  44. package/src/lib/parse-mvt.ts +11 -9
  45. package/src/lib/types.ts +0 -69
  46. package/dist/lib/binary-vector-tile/features-to-binary.js +0 -327
  47. package/dist/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  48. package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/parse-mvt.ts"],"names":["VectorTile","BinaryVectorTile","featuresToBinary","Protobuf","parseMVT","arrayBuffer","options","normalizeOptions","features","binary","gis","format","firstPassData","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":"A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,CAAD,CAAd;AACA2B,IAAAA,CAAC,CAAC,CAAD,CAAD,IAAQD,MAAR;AACAC,IAAAA,CAAC,CAAC,CAAD,CAAD,IAAQD,MAAR;AACD;AACF;;AAED,SAASF,iCAAT,CAA2ChB,IAA3C,EAA2DL,OAA3D,EAAmF;AAGjF,QAAM;AAACuB,IAAAA;AAAD,MAAWvB,OAAjB;;AACA,OAAK,IAAIH,CAAC,GAAG,CAAR,EAAW4B,EAAE,GAAGpB,IAAI,CAACP,MAA1B,EAAkCD,CAAC,GAAG4B,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 {featuresToBinary} from './binary-vector-tile/features-to-binary';\nimport Protobuf from 'pbf';\nimport {MvtBinaryCoordinates, 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: (MvtBinaryCoordinates | MvtMapboxCoordinates)[] = [];\n\n if (options) {\n const binary = options.gis.format === 'binary';\n const firstPassData = {\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, firstPassData);\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 = featuresToBinary(features as MvtBinaryCoordinates[], firstPassData);\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): MvtBinaryCoordinates {\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) {\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"}
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,UAAMC,YAAY,GAAG;AACnBC,MAAAA,WAAW,EAAE,CADM;AAEnBC,MAAAA,mBAAmB,EAAE,CAFF;AAGnBC,MAAAA,kBAAkB,EAAE,CAHD;AAInBC,MAAAA,kBAAkB,EAAE,CAJD;AAKnBC,MAAAA,cAAc,EAAE,CALG;AAMnBC,MAAAA,iBAAiB,EAAE,CANA;AAOnBC,MAAAA,qBAAqB,EAAE,CAPJ;AAQnBC,MAAAA,mBAAmB,EAAE,CARF;AASnBC,MAAAA,iBAAiB,EAAE,CATA;AAUnBC,MAAAA,oBAAoB,EAAE;AAVH,KAArB;;AAaA,QAAIjB,WAAW,CAACkB,UAAZ,GAAyB,CAA7B,EAAgC;AAC9B,YAAMC,IAAI,GAAGf,MAAM,GACf,IAAIR,gBAAJ,CAAqB,IAAIE,QAAJ,CAAaE,WAAb,CAArB,CADe,GAEf,IAAIL,UAAJ,CAAe,IAAIG,QAAJ,CAAaE,WAAb,CAAf,CAFJ;AAGA,YAAMoB,aAAa,GAAGnB,OAAO,CAACoB,GAA9B;AAEA,YAAMC,cAAc,GAAGC,KAAK,CAACC,OAAN,CAAcJ,aAAa,CAACK,MAA5B,IACnBL,aAAa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AA;AAAD,MAAWvB,OAAjB;;AACA,OAAK,IAAIH,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGyB,IAAI,CAACxB,MAAzB,EAAiCD,CAAC,EAAlC,EAAsC;AACpC,UAAM2B,CAAC,GAAGF,IAAI,CAACzB,CAAD,CAAd;AACA2B,IAAAA,CAAC,CAAC,CAAD,CAAD,IAAQD,MAAR;AACAC,IAAAA,CAAC,CAAC,CAAD,CAAD,IAAQD,MAAR;AACD;AACF;;AAED,SAASF,iCAAT,CAA2ChB,IAA3C,EAA2DL,OAA3D,EAAmF;AAGjF,QAAM;AAACuB,IAAAA;AAAD,MAAWvB,OAAjB;;AACA,OAAK,IAAIH,CAAC,GAAG,CAAR,EAAW4B,EAAE,GAAGpB,IAAI,CAACP,MAA1B,EAAkCD,CAAC,GAAG4B,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"}
@@ -0,0 +1,28 @@
1
+ export declare type MvtOptions = {
2
+ coordinates: string | number[];
3
+ tileIndex: {
4
+ x: number;
5
+ y: number;
6
+ z: number;
7
+ };
8
+ layerProperty: string | number;
9
+ layerName: string;
10
+ };
11
+ export declare type MvtMapboxGeometry = {
12
+ type?: string;
13
+ id?: number;
14
+ length: number;
15
+ coordinates?: any[];
16
+ };
17
+ export declare type MvtMapboxCoordinates = {
18
+ type: string;
19
+ geometry: {
20
+ type: string;
21
+ coordinates: MvtMapboxGeometry;
22
+ };
23
+ properties: {
24
+ [x: string]: string | number | boolean | null;
25
+ };
26
+ id?: number;
27
+ };
28
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU,GAAG;IACvB,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC/B,SAAS,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;IAC7C,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oBAAY,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,oBAAY,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"}
@@ -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;AAOvE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAsB7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAKvB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import parseMVT from './lib/parse-mvt';
2
- const VERSION = typeof "4.0.0-alpha.4" !== 'undefined' ? "4.0.0-alpha.4" : 'latest';
2
+ const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
3
3
  export const MVTWorkerLoader = {
4
4
  name: 'Mapbox Vector Tile',
5
5
  id: 'mvt',
@@ -1525,12 +1525,14 @@
1525
1525
 
1526
1526
  // src/helpers/binary-util-functions.ts
1527
1527
  function classifyRings2(geom) {
1528
- const len = geom.lines.length;
1528
+ const len = geom.indices.length;
1529
+ const type = "Polygon";
1529
1530
  if (len <= 1) {
1530
1531
  return {
1532
+ type,
1531
1533
  data: geom.data,
1532
1534
  areas: [[getPolygonSignedArea(geom.data)]],
1533
- lines: [geom.lines]
1535
+ indices: [geom.indices]
1534
1536
  };
1535
1537
  }
1536
1538
  const areas = [];
@@ -1540,8 +1542,8 @@
1540
1542
  let ccw;
1541
1543
  let offset = 0;
1542
1544
  for (let endIndex, i2 = 0, startIndex; i2 < len; i2++) {
1543
- startIndex = geom.lines[i2] - offset;
1544
- endIndex = geom.lines[i2 + 1] - offset || geom.data.length;
1545
+ startIndex = geom.indices[i2] - offset;
1546
+ endIndex = geom.indices[i2 + 1] - offset || geom.data.length;
1545
1547
  const shape = geom.data.slice(startIndex, endIndex);
1546
1548
  const area2 = getPolygonSignedArea(shape);
1547
1549
  if (area2 === 0) {
@@ -1569,7 +1571,7 @@
1569
1571
  areas.push(ringAreas);
1570
1572
  if (polygon.length)
1571
1573
  polygons.push(polygon);
1572
- return { areas, lines: polygons, data: geom.data };
1574
+ return { type, areas, indices: polygons, data: geom.data };
1573
1575
  }
1574
1576
  function project(data, x0, y0, size) {
1575
1577
  for (let j = 0, jl = data.length; j < jl; j += 2) {
@@ -1608,10 +1610,7 @@
1608
1610
  var y;
1609
1611
  var i;
1610
1612
  var VectorTileFeature2 = class {
1611
- static get types() {
1612
- return ["Unknown", "Point", "LineString", "Polygon"];
1613
- }
1614
- constructor(pbf, end, extent, keys, values, firstPassData) {
1613
+ constructor(pbf, end, extent, keys, values, geometryInfo) {
1615
1614
  this.properties = {};
1616
1615
  this.extent = extent;
1617
1616
  this.type = 0;
@@ -1620,7 +1619,7 @@
1620
1619
  this._geometry = -1;
1621
1620
  this._keys = keys;
1622
1621
  this._values = values;
1623
- this._firstPassData = firstPassData;
1622
+ this._geometryInfo = geometryInfo;
1624
1623
  pbf.readFields(readFeature2, this, end);
1625
1624
  }
1626
1625
  loadGeometry() {
@@ -1632,7 +1631,7 @@
1632
1631
  x = 0;
1633
1632
  y = 0;
1634
1633
  i = 0;
1635
- const lines = [];
1634
+ const indices = [];
1636
1635
  const data = [];
1637
1636
  while (pbf.pos < endPos) {
1638
1637
  if (length <= 0) {
@@ -1645,13 +1644,13 @@
1645
1644
  x += pbf.readSVarint();
1646
1645
  y += pbf.readSVarint();
1647
1646
  if (cmd === 1) {
1648
- lines.push(i);
1647
+ indices.push(i);
1649
1648
  }
1650
1649
  data.push(x, y);
1651
1650
  i += 2;
1652
1651
  } else if (cmd === 7) {
1653
1652
  if (i > 0) {
1654
- const start = lines[lines.length - 1];
1653
+ const start = indices[indices.length - 1];
1655
1654
  data.push(data[start], data[start + 1]);
1656
1655
  i += 2;
1657
1656
  }
@@ -1659,42 +1658,38 @@
1659
1658
  throw new Error(`unknown command ${cmd}`);
1660
1659
  }
1661
1660
  }
1662
- return { data, lines };
1661
+ return { data, indices };
1663
1662
  }
1664
1663
  _toBinaryCoordinates(transform) {
1665
- let geom = this.loadGeometry();
1664
+ const geom = this.loadGeometry();
1665
+ let geometry;
1666
1666
  transform(geom.data, this);
1667
1667
  const coordLength = 2;
1668
1668
  switch (this.type) {
1669
1669
  case 1:
1670
- this._firstPassData.pointFeaturesCount++;
1671
- this._firstPassData.pointPositionsCount += geom.lines.length;
1670
+ this._geometryInfo.pointFeaturesCount++;
1671
+ this._geometryInfo.pointPositionsCount += geom.indices.length;
1672
+ geometry = { type: "Point", ...geom };
1672
1673
  break;
1673
1674
  case 2:
1674
- this._firstPassData.lineFeaturesCount++;
1675
- this._firstPassData.linePathsCount += geom.lines.length;
1676
- this._firstPassData.linePositionsCount += geom.data.length / coordLength;
1675
+ this._geometryInfo.lineFeaturesCount++;
1676
+ this._geometryInfo.linePathsCount += geom.indices.length;
1677
+ this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
1678
+ geometry = { type: "LineString", ...geom };
1677
1679
  break;
1678
1680
  case 3:
1679
- const classified = classifyRings2(geom);
1680
- this._firstPassData.polygonFeaturesCount++;
1681
- this._firstPassData.polygonObjectsCount += classified.lines.length;
1682
- for (const lines of classified.lines) {
1683
- this._firstPassData.polygonRingsCount += lines.length;
1681
+ geometry = classifyRings2(geom);
1682
+ this._geometryInfo.polygonFeaturesCount++;
1683
+ this._geometryInfo.polygonObjectsCount += geometry.indices.length;
1684
+ for (const indices of geometry.indices) {
1685
+ this._geometryInfo.polygonRingsCount += indices.length;
1684
1686
  }
1685
- this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;
1686
- geom = classified;
1687
+ this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
1687
1688
  break;
1689
+ default:
1690
+ throw new Error(`Invalid geometry type: ${this.type}`);
1688
1691
  }
1689
- geom.type = VectorTileFeature2.types[this.type];
1690
- if (geom.lines.length > 1) {
1691
- geom.type = `Multi${geom.type}`;
1692
- }
1693
- const result = {
1694
- type: "Feature",
1695
- geometry: geom,
1696
- properties: this.properties
1697
- };
1692
+ const result = { type: "Feature", geometry, properties: this.properties };
1698
1693
  if (this.id !== null) {
1699
1694
  result.id = this.id;
1700
1695
  }
@@ -1722,13 +1717,13 @@
1722
1717
  pbf.readFields(readLayer2, this, end);
1723
1718
  this.length = this._features.length;
1724
1719
  }
1725
- feature(i2, firstPassData) {
1720
+ feature(i2, geometryInfo) {
1726
1721
  if (i2 < 0 || i2 >= this._features.length) {
1727
1722
  throw new Error("feature index out of bounds");
1728
1723
  }
1729
1724
  this._pbf.pos = this._features[i2];
1730
1725
  const end = this._pbf.readVarint() + this._pbf.pos;
1731
- return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, firstPassData);
1726
+ return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
1732
1727
  }
1733
1728
  };
1734
1729
  function readLayer2(tag, layer, pbf) {
@@ -1774,29 +1769,31 @@
1774
1769
  }
1775
1770
  }
1776
1771
 
1777
- // src/lib/binary-vector-tile/features-to-binary.ts
1778
- function featuresToBinary(features, firstPassData, options) {
1779
- return fillArrays(features, firstPassData, {
1780
- numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),
1772
+ // ../gis/src/lib/flat-geojson-to-binary.ts
1773
+ function flatGeojsonToBinary(features, geometryInfo, options) {
1774
+ const propArrayTypes = extractNumericPropTypes(features);
1775
+ const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
1776
+ return fillArrays(features, {
1777
+ propArrayTypes,
1778
+ ...geometryInfo
1779
+ }, {
1780
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
1781
1781
  PositionDataType: options ? options.PositionDataType : Float32Array
1782
1782
  });
1783
1783
  }
1784
- function extractNumericPropKeys(features) {
1785
- const numericPropKeys = {};
1784
+ function extractNumericPropTypes(features) {
1785
+ const propArrayTypes = {};
1786
1786
  for (const feature of features) {
1787
1787
  if (feature.properties) {
1788
1788
  for (const key in feature.properties) {
1789
- const numericSoFar = numericPropKeys[key];
1790
- if (numericSoFar || numericSoFar === void 0) {
1791
- const val = feature.properties[key];
1792
- numericPropKeys[key] = isNumeric(val);
1793
- }
1789
+ const val = feature.properties[key];
1790
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
1794
1791
  }
1795
1792
  }
1796
1793
  }
1797
- return Object.keys(numericPropKeys).filter((k) => numericPropKeys[k]);
1794
+ return propArrayTypes;
1798
1795
  }
1799
- function fillArrays(features, firstPassData, options) {
1796
+ function fillArrays(features, geometryInfo, options) {
1800
1797
  const {
1801
1798
  pointPositionsCount,
1802
1799
  pointFeaturesCount,
@@ -1806,13 +1803,15 @@
1806
1803
  polygonPositionsCount,
1807
1804
  polygonObjectsCount,
1808
1805
  polygonRingsCount,
1809
- polygonFeaturesCount
1810
- } = firstPassData;
1811
- const { numericPropKeys, PositionDataType = Float32Array } = options;
1806
+ polygonFeaturesCount,
1807
+ propArrayTypes,
1808
+ coordLength
1809
+ } = geometryInfo;
1810
+ const { numericPropKeys = [], PositionDataType = Float32Array } = options;
1812
1811
  const hasGlobalId = features[0] && "id" in features[0];
1813
- const coordLength = 2;
1814
1812
  const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
1815
1813
  const points = {
1814
+ type: "Point",
1816
1815
  positions: new PositionDataType(pointPositionsCount * coordLength),
1817
1816
  globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
1818
1817
  featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
@@ -1821,6 +1820,7 @@
1821
1820
  fields: []
1822
1821
  };
1823
1822
  const lines = {
1823
+ type: "LineString",
1824
1824
  pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
1825
1825
  positions: new PositionDataType(linePositionsCount * coordLength),
1826
1826
  globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
@@ -1830,6 +1830,7 @@
1830
1830
  fields: []
1831
1831
  };
1832
1832
  const polygons = {
1833
+ type: "Polygon",
1833
1834
  polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
1834
1835
  primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
1835
1836
  positions: new PositionDataType(polygonPositionsCount * coordLength),
@@ -1842,7 +1843,8 @@
1842
1843
  };
1843
1844
  for (const object of [points, lines, polygons]) {
1844
1845
  for (const propName of numericPropKeys) {
1845
- object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
1846
+ const T = propArrayTypes[propName];
1847
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
1846
1848
  }
1847
1849
  }
1848
1850
  lines.pathIndices[linePathsCount] = linePositionsCount;
@@ -1865,7 +1867,6 @@
1865
1867
  const properties = feature.properties || {};
1866
1868
  switch (geometry.type) {
1867
1869
  case "Point":
1868
- case "MultiPoint":
1869
1870
  handlePoint(geometry, points, indexMap, coordLength, properties);
1870
1871
  points.properties.push(keepStringProperties(properties, numericPropKeys));
1871
1872
  if (hasGlobalId) {
@@ -1874,7 +1875,6 @@
1874
1875
  indexMap.pointFeature++;
1875
1876
  break;
1876
1877
  case "LineString":
1877
- case "MultiLineString":
1878
1878
  handleLineString(geometry, lines, indexMap, coordLength, properties);
1879
1879
  lines.properties.push(keepStringProperties(properties, numericPropKeys));
1880
1880
  if (hasGlobalId) {
@@ -1883,7 +1883,6 @@
1883
1883
  indexMap.lineFeature++;
1884
1884
  break;
1885
1885
  case "Polygon":
1886
- case "MultiPolygon":
1887
1886
  handlePolygon(geometry, polygons, indexMap, coordLength, properties);
1888
1887
  polygons.properties.push(keepStringProperties(properties, numericPropKeys));
1889
1888
  if (hasGlobalId) {
@@ -1912,9 +1911,9 @@
1912
1911
  fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
1913
1912
  lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
1914
1913
  lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
1915
- for (let i2 = 0, il = geometry.lines.length; i2 < il; ++i2) {
1916
- const start = geometry.lines[i2];
1917
- const end = i2 === il - 1 ? geometry.data.length : geometry.lines[i2 + 1];
1914
+ for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
1915
+ const start = geometry.indices[i2];
1916
+ const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
1918
1917
  lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
1919
1918
  indexMap.linePosition += (end - start) / coordLength;
1920
1919
  }
@@ -1925,23 +1924,23 @@
1925
1924
  fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
1926
1925
  polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
1927
1926
  polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
1928
- for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {
1927
+ for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
1929
1928
  const startPosition = indexMap.polygonPosition;
1930
1929
  polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
1931
1930
  const areas = geometry.areas[l];
1932
- const lines = geometry.lines[l];
1933
- const nextLines = geometry.lines[l + 1];
1934
- for (let i2 = 0, il = lines.length; i2 < il; ++i2) {
1935
- const start = lines[i2];
1936
- const end = i2 === il - 1 ? nextLines === void 0 ? geometry.data.length : nextLines[0] : lines[i2 + 1];
1931
+ const indices = geometry.indices[l];
1932
+ const nextIndices = geometry.indices[l + 1];
1933
+ for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
1934
+ const start = indices[i2];
1935
+ const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
1937
1936
  polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
1938
1937
  indexMap.polygonPosition += (end - start) / coordLength;
1939
1938
  }
1940
1939
  const endPosition = indexMap.polygonPosition;
1941
- triangulatePolygon(polygons, areas, lines, { startPosition, endPosition, coordLength });
1940
+ triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
1942
1941
  }
1943
1942
  }
1944
- function triangulatePolygon(polygons, areas, lines, {
1943
+ function triangulatePolygon(polygons, areas, indices, {
1945
1944
  startPosition,
1946
1945
  endPosition,
1947
1946
  coordLength
@@ -1949,52 +1948,54 @@
1949
1948
  const start = startPosition * coordLength;
1950
1949
  const end = endPosition * coordLength;
1951
1950
  const polygonPositions = polygons.positions.subarray(start, end);
1952
- const offset = lines[0];
1953
- const holes = lines.slice(1).map((n) => (n - offset) / coordLength);
1954
- const indices = earcut(polygonPositions, holes, coordLength, areas);
1955
- for (let t = 0, tl = indices.length; t < tl; ++t) {
1956
- polygons.triangles.push(startPosition + indices[t]);
1951
+ const offset = indices[0];
1952
+ const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
1953
+ const triangles = earcut(polygonPositions, holes, coordLength, areas);
1954
+ for (let t = 0, tl = triangles.length; t < tl; ++t) {
1955
+ polygons.triangles.push(startPosition + triangles[t]);
1956
+ }
1957
+ }
1958
+ function wrapProps(obj, size) {
1959
+ const returnObj = {};
1960
+ for (const key in obj) {
1961
+ returnObj[key] = { value: obj[key], size };
1957
1962
  }
1963
+ return returnObj;
1958
1964
  }
1959
1965
  function makeAccessorObjects(points, lines, polygons, coordLength) {
1960
- const returnObj = {
1966
+ return {
1961
1967
  points: {
1962
1968
  ...points,
1963
1969
  positions: { value: points.positions, size: coordLength },
1964
1970
  globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
1965
- featureIds: { value: points.featureIds, size: 1 }
1971
+ featureIds: { value: points.featureIds, size: 1 },
1972
+ numericProps: wrapProps(points.numericProps, 1)
1966
1973
  },
1967
1974
  lines: {
1968
1975
  ...lines,
1969
- pathIndices: { value: lines.pathIndices, size: 1 },
1970
1976
  positions: { value: lines.positions, size: coordLength },
1977
+ pathIndices: { value: lines.pathIndices, size: 1 },
1971
1978
  globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
1972
- featureIds: { value: lines.featureIds, size: 1 }
1979
+ featureIds: { value: lines.featureIds, size: 1 },
1980
+ numericProps: wrapProps(lines.numericProps, 1)
1973
1981
  },
1974
1982
  polygons: {
1975
1983
  ...polygons,
1984
+ positions: { value: polygons.positions, size: coordLength },
1976
1985
  polygonIndices: { value: polygons.polygonIndices, size: 1 },
1977
1986
  primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
1978
- positions: { value: polygons.positions, size: coordLength },
1979
1987
  triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
1980
1988
  globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
1981
- featureIds: { value: polygons.featureIds, size: 1 }
1989
+ featureIds: { value: polygons.featureIds, size: 1 },
1990
+ numericProps: wrapProps(polygons.numericProps, 1)
1982
1991
  }
1983
1992
  };
1984
- for (const geomType in returnObj) {
1985
- for (const numericProp in returnObj[geomType].numericProps) {
1986
- returnObj[geomType].numericProps[numericProp] = {
1987
- value: returnObj[geomType].numericProps[numericProp],
1988
- size: 1
1989
- };
1990
- }
1991
- }
1992
- return returnObj;
1993
1993
  }
1994
1994
  function fillNumericProperties(object, properties, index, length2) {
1995
1995
  for (const numericPropName in object.numericProps) {
1996
1996
  if (numericPropName in properties) {
1997
- object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length2);
1997
+ const value = properties[numericPropName];
1998
+ object.numericProps[numericPropName].fill(value, index, index + length2);
1998
1999
  }
1999
2000
  }
2000
2001
  }
@@ -2007,8 +2008,11 @@
2007
2008
  }
2008
2009
  return props;
2009
2010
  }
2010
- function isNumeric(x2) {
2011
- return Number.isFinite(x2);
2011
+ function deduceArrayType(x2, constructor) {
2012
+ if (constructor === Array || !Number.isFinite(x2)) {
2013
+ return Array;
2014
+ }
2015
+ return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
2012
2016
  }
2013
2017
 
2014
2018
  // src/lib/parse-mvt.ts
@@ -2018,7 +2022,8 @@
2018
2022
  const features = [];
2019
2023
  if (options) {
2020
2024
  const binary = options.gis.format === "binary";
2021
- const firstPassData = {
2025
+ const geometryInfo = {
2026
+ coordLength: 2,
2022
2027
  pointPositionsCount: 0,
2023
2028
  pointFeaturesCount: 0,
2024
2029
  linePositionsCount: 0,
@@ -2040,14 +2045,14 @@
2040
2045
  return;
2041
2046
  }
2042
2047
  for (let i2 = 0; i2 < vectorTileLayer.length; i2++) {
2043
- const vectorTileFeature = vectorTileLayer.feature(i2, firstPassData);
2048
+ const vectorTileFeature = vectorTileLayer.feature(i2, geometryInfo);
2044
2049
  const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
2045
2050
  features.push(decodedFeature);
2046
2051
  }
2047
2052
  });
2048
2053
  }
2049
2054
  if (binary) {
2050
- const data = featuresToBinary(features, firstPassData);
2055
+ const data = flatGeojsonToBinary(features, geometryInfo);
2051
2056
  data.byteLength = arrayBuffer.byteLength;
2052
2057
  return data;
2053
2058
  }
@@ -2079,7 +2084,7 @@
2079
2084
  }
2080
2085
  function getDecodedFeatureBinary(feature, options) {
2081
2086
  const decodedFeature = feature.toBinaryCoordinates(options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary);
2082
- if (options.layerProperty) {
2087
+ if (options.layerProperty && decodedFeature.properties) {
2083
2088
  decodedFeature.properties[options.layerProperty] = options.layerName;
2084
2089
  }
2085
2090
  return decodedFeature;
@@ -2100,7 +2105,7 @@
2100
2105
  }
2101
2106
 
2102
2107
  // src/mvt-loader.ts
2103
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
2108
+ var VERSION = true ? "4.0.0-alpha.5" : "latest";
2104
2109
  var MVTWorkerLoader = {
2105
2110
  name: "Mapbox Vector Tile",
2106
2111
  id: "mvt",
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mvt-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mvt-worker.d.ts","sourceRoot":"","sources":["../../src/workers/mvt-worker.ts"],"names":[],"mappings":""}
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",
4
+ "version": "4.0.0-alpha.5",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -17,7 +17,7 @@
17
17
  "MVT",
18
18
  "Mapbox Vector Tiles"
19
19
  ],
20
- "types": "src/index.ts",
20
+ "types": "dist/index.d.ts",
21
21
  "main": "dist/index.js",
22
22
  "module": "dist/index.js",
23
23
  "sideEffects": false,
@@ -28,17 +28,18 @@
28
28
  ],
29
29
  "scripts": {
30
30
  "pre-build": "npm run build-worker && npm run build-worker --env.dev && npm run build-bundle",
31
- "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js",
32
- "build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js"
31
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js",
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.4",
36
- "@loaders.gl/loader-utils": "4.0.0-alpha.4",
35
+ "@loaders.gl/gis": "4.0.0-alpha.5",
36
+ "@loaders.gl/loader-utils": "4.0.0-alpha.5",
37
+ "@loaders.gl/schema": "4.0.0-alpha.5",
37
38
  "@math.gl/polygon": "^3.5.1",
38
39
  "pbf": "^3.2.1"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@types/pbf": "^3.0.2"
42
43
  },
43
- "gitHead": "53026061b3c8871f7e96d3a5826125cc6613bddc"
44
+ "gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
44
45
  }
@@ -1,6 +1,6 @@
1
1
  import Protobuf from 'pbf';
2
2
  import {getPolygonSignedArea} from '@math.gl/polygon';
3
- import {MvtBinaryGeometry} from '../lib/types';
3
+ import {FlatIndexedGeometry, FlatPolygon} from '@loaders.gl/schema';
4
4
  import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
5
5
 
6
6
  /**
@@ -13,14 +13,16 @@ import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
13
13
  * @returns object
14
14
  */
15
15
  // eslint-disable-next-line max-statements
16
- export function classifyRings(geom: MvtBinaryGeometry) {
17
- const len = geom.lines.length;
16
+ export function classifyRings(geom: FlatIndexedGeometry): FlatPolygon {
17
+ const len = geom.indices.length;
18
+ const type = 'Polygon';
18
19
 
19
20
  if (len <= 1) {
20
21
  return {
22
+ type,
21
23
  data: geom.data,
22
24
  areas: [[getPolygonSignedArea(geom.data)]],
23
- lines: [geom.lines]
25
+ indices: [geom.indices]
24
26
  };
25
27
  }
26
28
 
@@ -32,9 +34,9 @@ export function classifyRings(geom: MvtBinaryGeometry) {
32
34
  let offset = 0;
33
35
 
34
36
  for (let endIndex: number, i = 0, startIndex: number; i < len; i++) {
35
- startIndex = geom.lines[i] - offset;
37
+ startIndex = geom.indices[i] - offset;
36
38
 
37
- endIndex = geom.lines[i + 1] - offset || geom.data.length;
39
+ endIndex = geom.indices[i + 1] - offset || geom.data.length;
38
40
  const shape = geom.data.slice(startIndex, endIndex);
39
41
  const area = getPolygonSignedArea(shape);
40
42
 
@@ -70,7 +72,7 @@ export function classifyRings(geom: MvtBinaryGeometry) {
70
72
  if (ringAreas) areas.push(ringAreas);
71
73
  if (polygon.length) polygons.push(polygon);
72
74
 
73
- return {areas, lines: polygons, data: geom.data};
75
+ return {type, areas, indices: polygons, data: geom.data};
74
76
  }
75
77
 
76
78
  /**