@loaders.gl/mvt 3.1.0-alpha.5 → 3.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +1 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2277 -0
- package/dist/es5/lib/parse-mvt.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.map +1 -1
- package/dist/esm/mvt-loader.js +1 -1
- package/dist/esm/mvt-loader.js.map +1 -1
- package/dist/helpers/binary-util-functions.d.ts +1 -0
- package/dist/helpers/binary-util-functions.d.ts.map +1 -0
- package/dist/helpers/binary-util-functions.js +116 -0
- package/dist/helpers/mapbox-util-functions.d.ts +1 -0
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
- package/dist/helpers/mapbox-util-functions.js +82 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts +1 -0
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/features-to-binary.js +353 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +159 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +91 -0
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +1 -0
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile.js +29 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +170 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +89 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.js +29 -0
- package/dist/lib/parse-mvt.d.ts +2 -1
- package/dist/lib/parse-mvt.d.ts.map +1 -0
- package/dist/lib/parse-mvt.js +142 -0
- package/dist/lib/types.d.ts +1 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/dist/mvt-loader.d.ts +1 -0
- package/dist/mvt-loader.d.ts.map +1 -0
- package/dist/mvt-loader.js +45 -0
- package/dist/mvt-worker.js +2286 -3
- package/dist/workers/mvt-worker.d.ts +1 -0
- package/dist/workers/mvt-worker.d.ts.map +1 -0
- package/dist/workers/mvt-worker.js +5 -0
- package/package.json +6 -7
- package/src/lib/parse-mvt.ts +1 -1
- package/dist/dist.min.js +0 -4
- package/dist/dist.min.js.map +0 -1
- package/dist/mvt-worker.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/parse-mvt.ts"],"names":["parseMVT","arrayBuffer","options","normalizeOptions","features","binary","gis","format","firstPassData","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","byteLength","tile","BinaryVectorTile","Protobuf","VectorTile","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;;AACA;;AAEA;;AACA;;AAae,SAASA,QAAT,CAAkBC,WAAlB,EAA4CC,OAA5C,EAAqE;AAClFA,EAAAA,OAAO,GAAGC,gBAAgB,CAACD,OAAD,CAA1B;AACA,QAAME,QAAyD,GAAG,EAAlE;;AAEA,MAAIF,OAAJ,EAAa;AACX,UAAMG,MAAM,GAAGH,OAAO,CAACI,GAAR,CAAYC,MAAZ,KAAuB,QAAtC;AACA,UAAMC,aAAa,GAAG;AACpBC,MAAAA,mBAAmB,EAAE,CADD;AAEpBC,MAAAA,kBAAkB,EAAE,CAFA;AAGpBC,MAAAA,kBAAkB,EAAE,CAHA;AAIpBC,MAAAA,cAAc,EAAE,CAJI;AAKpBC,MAAAA,iBAAiB,EAAE,CALC;AAMpBC,MAAAA,qBAAqB,EAAE,CANH;AAOpBC,MAAAA,mBAAmB,EAAE,CAPD;AAQpBC,MAAAA,iBAAiB,EAAE,CARC;AASpBC,MAAAA,oBAAoB,EAAE;AATF,KAAtB;;AAYA,QAAIhB,WAAW,CAACiB,UAAZ,GAAyB,CAA7B,EAAgC;AAC9B,YAAMC,IAAI,GAAGd,MAAM,GACf,IAAIe,oBAAJ,CAAqB,IAAIC,YAAJ,CAAapB,WAAb,CAArB,CADe,GAEf,IAAIqB,mBAAJ,CAAe,IAAID,YAAJ,CAAapB,WAAb,CAAf,CAFJ;AAGA,YAAMsB,aAAa,GAAGrB,OAAO,CAACsB,GAA9B;AAEA,YAAMC,cAAc,GAAGC,KAAK,CAACC,OAAN,CAAcJ,aAAa,CAACK,MAA5B,IACnBL,aAAa,CAACK,MADK,GAEnBC,MAAM,CAACC,IAAP,CAAYX,IAAI,CAACS,MAAjB,CAFJ;AAIAH,MAAAA,cAAc,CAACM,OAAf,CAAwBC,SAAD,IAAuB;AAC5C,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F,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 {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
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/parse-mvt.ts"],"names":["parseMVT","arrayBuffer","options","normalizeOptions","features","binary","gis","format","firstPassData","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","byteLength","tile","BinaryVectorTile","Protobuf","VectorTile","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;;AACA;;AAEA;;AACA;;AAae,SAASA,QAAT,CAAkBC,WAAlB,EAA4CC,OAA5C,EAAqE;AAClFA,EAAAA,OAAO,GAAGC,gBAAgB,CAACD,OAAD,CAA1B;AACA,QAAME,QAAyD,GAAG,EAAlE;;AAEA,MAAIF,OAAJ,EAAa;AACX,UAAMG,MAAM,GAAGH,OAAO,CAACI,GAAR,CAAYC,MAAZ,KAAuB,QAAtC;AACA,UAAMC,aAAa,GAAG;AACpBC,MAAAA,mBAAmB,EAAE,CADD;AAEpBC,MAAAA,kBAAkB,EAAE,CAFA;AAGpBC,MAAAA,kBAAkB,EAAE,CAHA;AAIpBC,MAAAA,cAAc,EAAE,CAJI;AAKpBC,MAAAA,iBAAiB,EAAE,CALC;AAMpBC,MAAAA,qBAAqB,EAAE,CANH;AAOpBC,MAAAA,mBAAmB,EAAE,CAPD;AAQpBC,MAAAA,iBAAiB,EAAE,CARC;AASpBC,MAAAA,oBAAoB,EAAE;AATF,KAAtB;;AAYA,QAAIhB,WAAW,CAACiB,UAAZ,GAAyB,CAA7B,EAAgC;AAC9B,YAAMC,IAAI,GAAGd,MAAM,GACf,IAAIe,oBAAJ,CAAqB,IAAIC,YAAJ,CAAapB,WAAb,CAArB,CADe,GAEf,IAAIqB,mBAAJ,CAAe,IAAID,YAAJ,CAAapB,WAAb,CAAf,CAFJ;AAGA,YAAMsB,aAAa,GAAGrB,OAAO,CAACsB,GAA9B;AAEA,YAAMC,cAAc,GAAGC,KAAK,CAACC,OAAN,CAAcJ,aAAa,CAACK,MAA5B,IACnBL,aAAa,CAACK,MADK,GAEnBC,MAAM,CAACC,IAAP,CAAYX,IAAI,CAACS,MAAjB,CAFJ;AAIAH,MAAAA,cAAc,CAACM,OAAf,CAAwBC,SAAD,IAAuB;AAC5C,cAAMC,eAAe,GAAGd,IAAI,CAACS,MAAL,CA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,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"}
|
package/dist/es5/mvt-loader.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.MVTLoader = exports.MVTWorkerLoader = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _parseMvt = _interopRequireDefault(require("./lib/parse-mvt"));
|
|
11
11
|
|
|
12
|
-
const VERSION = typeof "3.1.0-
|
|
12
|
+
const VERSION = typeof "3.1.0-beta.5" !== 'undefined' ? "3.1.0-beta.5" : 'latest';
|
|
13
13
|
const MVTWorkerLoader = {
|
|
14
14
|
name: 'Mapbox Vector Tile',
|
|
15
15
|
id: 'mvt',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mvt-loader.ts"],"names":["VERSION","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","mvt","coordinates","layerProperty","layers","tileIndex","MVTLoader","parse","arrayBuffer","parseSync","parseMVT","binary"],"mappings":";;;;;;;;;AACA;;AAIA,MAAMA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"sources":["../../src/mvt-loader.ts"],"names":["VERSION","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","mvt","coordinates","layerProperty","layers","tileIndex","MVTLoader","parse","arrayBuffer","parseSync","parseMVT","binary"],"mappings":";;;;;;;;;AACA;;AAIA,MAAMA,OAAO,GAAG,0BAAuB,WAAvB,oBAAmD,QAAnE;AAKO,MAAMC,eAAuB,GAAG;AACrCC,EAAAA,IAAI,EAAE,oBAD+B;AAErCC,EAAAA,EAAE,EAAE,KAFiC;AAGrCC,EAAAA,MAAM,EAAE,KAH6B;AAIrCC,EAAAA,OAAO,EAAEL,OAJ4B;AAMrCM,EAAAA,UAAU,EAAE,CAAC,KAAD,EAAQ,KAAR,CANyB;AAOrCC,EAAAA,SAAS,EAAE,CACT,oCADS,EAET,wBAFS,CAP0B;AAYrCC,EAAAA,MAAM,EAAE,IAZ6B;AAarCC,EAAAA,QAAQ,EAAE,UAb2B;AAcrCC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AACHC,MAAAA,WAAW,EAAE,OADV;AAEHC,MAAAA,aAAa,EAAE,WAFZ;AAGHC,MAAAA,MAAM,EAAE,IAHL;AAIHC,MAAAA,SAAS,EAAE;AAJR;AADE;AAd4B,CAAhC;;AA2BA,MAAMC,SAA2B,GAAG,EACzC,GAAGf,eADsC;AAEzCgB,EAAAA,KAAK,EAAE,OAAOC,WAAP,EAAoBR,OAApB,KAAgC,uBAASQ,WAAT,EAAsBR,OAAtB,CAFE;AAGzCS,EAAAA,SAAS,EAAEC,iBAH8B;AAIzCC,EAAAA,MAAM,EAAE;AAJiC,CAApC","sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport parseMVT from './lib/parse-mvt';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for the Mapbox Vector Tile format\n */\nexport const MVTWorkerLoader: Loader = {\n name: 'Mapbox Vector Tile',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'\n extensions: ['mvt', 'pbf'],\n mimeTypes: [\n 'application/vnd.mapbox-vector-tile',\n 'application/x-protobuf'\n // 'application/octet-stream'\n ],\n worker: true,\n category: 'geometry',\n options: {\n mvt: {\n coordinates: 'local',\n layerProperty: 'layerName',\n layers: null,\n tileIndex: null\n }\n }\n};\n\n/**\n * Loader for the Mapbox Vector Tile format\n */\nexport const MVTLoader: LoaderWithParser = {\n ...MVTWorkerLoader,\n parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),\n parseSync: parseMVT,\n binary: true\n};\n"],"file":"mvt-loader.js"}
|
|
@@ -1 +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":"AACA,OAAOA,UAAP,MAAuB,kCAA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AAC,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","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":"AACA,OAAOA,UAAP,MAAuB,kCAAvB;AACA,OAAOC,gBAAP,MAA6B,kCAA7B;AAEA,SAAQC,gBAAR,QAA+B,yCAA/B;AACA,OAAOC,QAAP,MAAqB,KAArB;AAaA,eAAe,SAASC,QAAT,CAAkBC,WAAlB,EAA4CC,OAA5C,EAAqE;AAClFA,EAAAA,OAAO,GAAGC,gBAAgB,CAACD,OAAD,CAA1B;AACA,QAAME,QAAyD,GAAG,EAAlE;;AAEA,MAAIF,OAAJ,EAAa;AACX,UAAMG,MAAM,GAAGH,OAAO,CAACI,GAAR,CAAYC,MAAZ,KAAuB,QAAtC;AACA,UAAMC,aAAa,GAAG;AACpBC,MAAAA,mBAAmB,EAAE,CADD;AAEpBC,MAAAA,kBAAkB,EAAE,CAFA;AAGpBC,MAAAA,kBAAkB,EAAE,CAHA;AAIpBC,MAAAA,cAAc,EAAE,CAJI;AAKpBC,MAAAA,iBAAiB,EAAE,CALC;AAMpBC,MAAAA,qBAAqB,EAAE,CANH;AAOpBC,MAAAA,mBAAmB,EAAE,CAPD;AAQpBC,MAAAA,iBAAiB,EAAE,CARC;AASpBC,MAAAA,oBAAoB,EAAE;AATF,KAAtB;;AAYA,QAAIhB,WAAW,CAACiB,UAAZ,GAAyB,CAA7B,EAAgC;AAC9B,YAAMC,IAAI,GAAGd,MAAM,GACf,IAAIR,gBAAJ,CAAqB,IAAIE,QAAJ,CAAaE,WAAb,CAArB,CADe,GAEf,IAAIL,UAAJ,CAAe,IAAIG,QAAJ,CAAaE,WAAb,CAAf,CAFJ;AAGA,YAAMmB,aAAa,GAAGlB,OAAO,CAACmB,GAA9B;AAEA,YAAMC,cAAc,GAAGC,KAAK,CAACC,OAAN,CAAcJ,aAAa,CAACK,MAA5B,IACnBL,aAAa,CAACK,MADK,GAEnBC,MAAM,CAACC,IAAP,CAAYR,IAAI,CAACM,MAAjB,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xB,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 {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"}
|
package/dist/esm/mvt-loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import parseMVT from './lib/parse-mvt';
|
|
2
|
-
const VERSION = typeof "3.1.0-
|
|
2
|
+
const VERSION = typeof "3.1.0-beta.5" !== 'undefined' ? "3.1.0-beta.5" : 'latest';
|
|
3
3
|
export const MVTWorkerLoader = {
|
|
4
4
|
name: 'Mapbox Vector Tile',
|
|
5
5
|
id: 'mvt',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mvt-loader.ts"],"names":["parseMVT","VERSION","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","mvt","coordinates","layerProperty","layers","tileIndex","MVTLoader","parse","arrayBuffer","parseSync","binary"],"mappings":"AACA,OAAOA,QAAP,MAAqB,iBAArB;AAIA,MAAMC,OAAO,GAAG,
|
|
1
|
+
{"version":3,"sources":["../../src/mvt-loader.ts"],"names":["parseMVT","VERSION","MVTWorkerLoader","name","id","module","version","extensions","mimeTypes","worker","category","options","mvt","coordinates","layerProperty","layers","tileIndex","MVTLoader","parse","arrayBuffer","parseSync","binary"],"mappings":"AACA,OAAOA,QAAP,MAAqB,iBAArB;AAIA,MAAMC,OAAO,GAAG,0BAAuB,WAAvB,oBAAmD,QAAnE;AAKA,OAAO,MAAMC,eAAuB,GAAG;AACrCC,EAAAA,IAAI,EAAE,oBAD+B;AAErCC,EAAAA,EAAE,EAAE,KAFiC;AAGrCC,EAAAA,MAAM,EAAE,KAH6B;AAIrCC,EAAAA,OAAO,EAAEL,OAJ4B;AAMrCM,EAAAA,UAAU,EAAE,CAAC,KAAD,EAAQ,KAAR,CANyB;AAOrCC,EAAAA,SAAS,EAAE,CACT,oCADS,EAET,wBAFS,CAP0B;AAYrCC,EAAAA,MAAM,EAAE,IAZ6B;AAarCC,EAAAA,QAAQ,EAAE,UAb2B;AAcrCC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AACHC,MAAAA,WAAW,EAAE,OADV;AAEHC,MAAAA,aAAa,EAAE,WAFZ;AAGHC,MAAAA,MAAM,EAAE,IAHL;AAIHC,MAAAA,SAAS,EAAE;AAJR;AADE;AAd4B,CAAhC;AA2BP,OAAO,MAAMC,SAA2B,GAAG,EACzC,GAAGf,eADsC;AAEzCgB,EAAAA,KAAK,EAAE,OAAOC,WAAP,EAAoBR,OAApB,KAAgCX,QAAQ,CAACmB,WAAD,EAAcR,OAAd,CAFN;AAGzCS,EAAAA,SAAS,EAAEpB,QAH8B;AAIzCqB,EAAAA,MAAM,EAAE;AAJiC,CAApC","sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport parseMVT from './lib/parse-mvt';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for the Mapbox Vector Tile format\n */\nexport const MVTWorkerLoader: Loader = {\n name: 'Mapbox Vector Tile',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'\n extensions: ['mvt', 'pbf'],\n mimeTypes: [\n 'application/vnd.mapbox-vector-tile',\n 'application/x-protobuf'\n // 'application/octet-stream'\n ],\n worker: true,\n category: 'geometry',\n options: {\n mvt: {\n coordinates: 'local',\n layerProperty: 'layerName',\n layers: null,\n tileIndex: null\n }\n }\n};\n\n/**\n * Loader for the Mapbox Vector Tile format\n */\nexport const MVTLoader: LoaderWithParser = {\n ...MVTWorkerLoader,\n parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),\n parseSync: parseMVT,\n binary: true\n};\n"],"file":"mvt-loader.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-util-functions.d.ts","sourceRoot":"","sources":["../../src/helpers/binary-util-functions.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAC/C,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAE9E;;;;;;;;GAQG;AAEH,wBAAgB,aAAa,CAAC,IAAI,EAAE,iBAAiB;;;;EA0DpD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAMlF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAO1F;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAQvE"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readTag = exports.readFeature = exports.project = exports.classifyRings = void 0;
|
|
4
|
+
const polygon_1 = require("@math.gl/polygon");
|
|
5
|
+
/**
|
|
6
|
+
* Classifies an array of rings into polygons with outer rings and holes
|
|
7
|
+
* The function also detects holes which have zero area and
|
|
8
|
+
* removes them. In doing so it modifies the input
|
|
9
|
+
* `geom.data` array to remove the unneeded data
|
|
10
|
+
*
|
|
11
|
+
* @param geometry
|
|
12
|
+
* @returns object
|
|
13
|
+
*/
|
|
14
|
+
// eslint-disable-next-line max-statements
|
|
15
|
+
function classifyRings(geom) {
|
|
16
|
+
const len = geom.lines.length;
|
|
17
|
+
if (len <= 1) {
|
|
18
|
+
return {
|
|
19
|
+
data: geom.data,
|
|
20
|
+
areas: [[(0, polygon_1.getPolygonSignedArea)(geom.data)]],
|
|
21
|
+
lines: [geom.lines]
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const areas = [];
|
|
25
|
+
const polygons = [];
|
|
26
|
+
let ringAreas = [];
|
|
27
|
+
let polygon = [];
|
|
28
|
+
let ccw;
|
|
29
|
+
let offset = 0;
|
|
30
|
+
for (let endIndex, i = 0, startIndex; i < len; i++) {
|
|
31
|
+
startIndex = geom.lines[i] - offset;
|
|
32
|
+
endIndex = geom.lines[i + 1] - offset || geom.data.length;
|
|
33
|
+
const shape = geom.data.slice(startIndex, endIndex);
|
|
34
|
+
const area = (0, polygon_1.getPolygonSignedArea)(shape);
|
|
35
|
+
if (area === 0) {
|
|
36
|
+
// This polygon has no area, so remove it from the shape
|
|
37
|
+
// Remove the section from the data array
|
|
38
|
+
const before = geom.data.slice(0, startIndex);
|
|
39
|
+
const after = geom.data.slice(endIndex);
|
|
40
|
+
geom.data = before.concat(after);
|
|
41
|
+
// Need to offset any remaining indices as we have
|
|
42
|
+
// modified the data buffer
|
|
43
|
+
offset += endIndex - startIndex;
|
|
44
|
+
// Do not add this index to the output and process next shape
|
|
45
|
+
continue; // eslint-disable-line no-continue
|
|
46
|
+
}
|
|
47
|
+
if (ccw === undefined)
|
|
48
|
+
ccw = area < 0;
|
|
49
|
+
if (ccw === area < 0) {
|
|
50
|
+
if (polygon.length) {
|
|
51
|
+
areas.push(ringAreas);
|
|
52
|
+
polygons.push(polygon);
|
|
53
|
+
}
|
|
54
|
+
polygon = [startIndex];
|
|
55
|
+
ringAreas = [area];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
ringAreas.push(area);
|
|
59
|
+
polygon.push(startIndex);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (ringAreas)
|
|
63
|
+
areas.push(ringAreas);
|
|
64
|
+
if (polygon.length)
|
|
65
|
+
polygons.push(polygon);
|
|
66
|
+
return { areas, lines: polygons, data: geom.data };
|
|
67
|
+
}
|
|
68
|
+
exports.classifyRings = classifyRings;
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param data
|
|
72
|
+
* @param x0
|
|
73
|
+
* @param y0
|
|
74
|
+
* @param size
|
|
75
|
+
*/
|
|
76
|
+
function project(data, x0, y0, size) {
|
|
77
|
+
for (let j = 0, jl = data.length; j < jl; j += 2) {
|
|
78
|
+
data[j] = ((data[j] + x0) * 360) / size - 180;
|
|
79
|
+
const y2 = 180 - ((data[j + 1] + y0) * 360) / size;
|
|
80
|
+
data[j + 1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.project = project;
|
|
84
|
+
/**
|
|
85
|
+
* All code below is unchanged from the original Mapbox implemenation
|
|
86
|
+
*
|
|
87
|
+
* @param tag
|
|
88
|
+
* @param feature
|
|
89
|
+
* @param pbf
|
|
90
|
+
*/
|
|
91
|
+
function readFeature(tag, feature, pbf) {
|
|
92
|
+
if (feature && pbf) {
|
|
93
|
+
if (tag === 1)
|
|
94
|
+
feature.id = pbf.readVarint();
|
|
95
|
+
else if (tag === 2)
|
|
96
|
+
readTag(pbf, feature);
|
|
97
|
+
else if (tag === 3)
|
|
98
|
+
feature.type = pbf.readVarint();
|
|
99
|
+
else if (tag === 4)
|
|
100
|
+
feature._geometry = pbf.pos;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.readFeature = readFeature;
|
|
104
|
+
/**
|
|
105
|
+
* @param pbf
|
|
106
|
+
* @param feature
|
|
107
|
+
*/
|
|
108
|
+
function readTag(pbf, feature) {
|
|
109
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
110
|
+
while (pbf.pos < end) {
|
|
111
|
+
const key = feature._keys[pbf.readVarint()];
|
|
112
|
+
const value = feature._values[pbf.readVarint()];
|
|
113
|
+
feature.properties[key] = value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.readTag = readTag;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapbox-util-functions.d.ts","sourceRoot":"","sources":["../../src/helpers/mapbox-util-functions.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAC/C,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAE9E;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,sCAuBrD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,UAQ1C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAO1F;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAQvE"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readTag = exports.readFeature = exports.signedArea = exports.classifyRings = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Classifies an array of rings into polygons with outer rings and holes
|
|
6
|
+
* @param rings
|
|
7
|
+
* @returns polygons
|
|
8
|
+
*/
|
|
9
|
+
function classifyRings(rings) {
|
|
10
|
+
const len = rings.length;
|
|
11
|
+
if (len <= 1)
|
|
12
|
+
return [rings];
|
|
13
|
+
const polygons = [];
|
|
14
|
+
let polygon;
|
|
15
|
+
let ccw;
|
|
16
|
+
for (let i = 0; i < len; i++) {
|
|
17
|
+
const area = signedArea(rings[i]);
|
|
18
|
+
if (area === 0)
|
|
19
|
+
continue; // eslint-disable-line no-continue
|
|
20
|
+
if (ccw === undefined)
|
|
21
|
+
ccw = area < 0;
|
|
22
|
+
if (ccw === area < 0) {
|
|
23
|
+
if (polygon)
|
|
24
|
+
polygons.push(polygon);
|
|
25
|
+
polygon = [rings[i]];
|
|
26
|
+
}
|
|
27
|
+
else if (polygon)
|
|
28
|
+
polygon.push(rings[i]);
|
|
29
|
+
}
|
|
30
|
+
if (polygon)
|
|
31
|
+
polygons.push(polygon);
|
|
32
|
+
return polygons;
|
|
33
|
+
}
|
|
34
|
+
exports.classifyRings = classifyRings;
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param ring
|
|
38
|
+
* @returns sum
|
|
39
|
+
*/
|
|
40
|
+
function signedArea(ring) {
|
|
41
|
+
let sum = 0;
|
|
42
|
+
for (let i = 0, j = ring.length - 1, p1, p2; i < ring.length; j = i++) {
|
|
43
|
+
p1 = ring[i];
|
|
44
|
+
p2 = ring[j];
|
|
45
|
+
sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
|
|
46
|
+
}
|
|
47
|
+
return sum;
|
|
48
|
+
}
|
|
49
|
+
exports.signedArea = signedArea;
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @param tag
|
|
53
|
+
* @param feature
|
|
54
|
+
* @param pbf
|
|
55
|
+
*/
|
|
56
|
+
function readFeature(tag, feature, pbf) {
|
|
57
|
+
if (feature && pbf) {
|
|
58
|
+
if (tag === 1)
|
|
59
|
+
feature.id = pbf.readVarint();
|
|
60
|
+
else if (tag === 2)
|
|
61
|
+
readTag(pbf, feature);
|
|
62
|
+
else if (tag === 3)
|
|
63
|
+
feature.type = pbf.readVarint();
|
|
64
|
+
else if (tag === 4)
|
|
65
|
+
feature._geometry = pbf.pos;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.readFeature = readFeature;
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param pbf
|
|
72
|
+
* @param feature
|
|
73
|
+
*/
|
|
74
|
+
function readTag(pbf, feature) {
|
|
75
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
76
|
+
while (pbf.pos < end) {
|
|
77
|
+
const key = feature._keys[pbf.readVarint()];
|
|
78
|
+
const value = feature._values[pbf.readVarint()];
|
|
79
|
+
feature.properties[key] = value;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.readTag = readTag;
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MVTWorkerLoader = exports.MVTLoader = void 0;
|
|
4
|
+
var mvt_loader_1 = require("./mvt-loader");
|
|
5
|
+
Object.defineProperty(exports, "MVTLoader", { enumerable: true, get: function () { return mvt_loader_1.MVTLoader; } });
|
|
6
|
+
Object.defineProperty(exports, "MVTWorkerLoader", { enumerable: true, get: function () { return mvt_loader_1.MVTWorkerLoader; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features-to-binary.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EAEpB,gBAAgB,EAChB,kBAAkB,EAInB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,CAAC,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAM3B;AAED,eAAO,MAAM,YAAY;;;CAGxB,CAAC;AAEF;;;;;GAKG;AACH,iBAAS,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,CAkB1E;AAED;;;;;;;GAOG;AAEH,iBAAS,UAAU,CACjB,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoI1B"}
|