@loaders.gl/mvt 3.1.0-beta.5 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +5 -2277
- package/dist/dist.min.js +2289 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/helpers/binary-util-functions.js +25 -22
- package/dist/es5/helpers/binary-util-functions.js.map +1 -1
- package/dist/es5/helpers/mapbox-util-functions.js +11 -11
- package/dist/es5/helpers/mapbox-util-functions.js.map +1 -1
- package/dist/es5/index.js +2 -2
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +137 -108
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +23 -15
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +8 -8
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +157 -147
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +23 -15
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +8 -8
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -1
- package/dist/es5/lib/parse-mvt.js +38 -35
- package/dist/es5/lib/parse-mvt.js.map +1 -1
- package/dist/es5/mvt-loader.js +38 -5
- package/dist/es5/mvt-loader.js.map +1 -1
- package/dist/esm/helpers/binary-util-functions.js +8 -5
- package/dist/esm/helpers/binary-util-functions.js.map +1 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +31 -30
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +2 -2
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.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/mvt-loader.js +1 -1
- package/dist/esm/mvt-loader.js.map +1 -1
- package/dist/helpers/binary-util-functions.d.ts +2 -6
- package/dist/helpers/binary-util-functions.d.ts.map +1 -1
- package/dist/helpers/binary-util-functions.js +7 -5
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +12 -7
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +32 -39
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +3 -3
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +3 -3
- package/dist/lib/parse-mvt.d.ts +8 -76
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +6 -5
- package/dist/lib/types.d.ts +0 -64
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/mvt-worker.js +102 -97
- package/package.json +6 -5
- package/src/helpers/binary-util-functions.ts +9 -7
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +36 -44
- package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
- package/src/lib/parse-mvt.ts +10 -8
- package/src/lib/types.ts +0 -69
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js +0 -338
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js +0 -327
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +0 -1
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts +0 -185
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +0 -1
- package/dist/lib/binary-vector-tile/features-to-binary.js +0 -353
- package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":["VectorTileFeature","VectorTileLayer","constructor","pbf","end","version","name","extent","length","_pbf","_keys","_values","_features","readFields","readLayer","feature","i","
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":["VectorTileFeature","VectorTileLayer","constructor","pbf","end","version","name","extent","length","_pbf","_keys","_values","_features","readFields","readLayer","feature","i","geometryInfo","Error","pos","readVarint","tag","layer","readString","push","readValueMessage","value","readFloat","readDouble","readVarint64","readSVarint","readBoolean"],"mappings":";AAGA,OAAOA,iBAAP,MAA8B,uBAA9B;AAIA,eAAe,MAAMC,eAAN,CAAsB;AASnCC,EAAAA,WAAW,CAACC,GAAD,EAAgBC,GAAhB,EAA6B;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAEtC,SAAKC,OAAL,GAAe,CAAf;AACA,SAAKC,IAAL,GAAY,EAAZ;AACA,SAAKC,MAAL,GAAc,IAAd;AACA,SAAKC,MAAL,GAAc,CAAd;AAGA,SAAKC,IAAL,GAAYN,GAAZ;AACA,SAAKO,KAAL,GAAa,EAAb;AACA,SAAKC,OAAL,GAAe,EAAf;AACA,SAAKC,SAAL,GAAiB,EAAjB;AAEAT,IAAAA,GAAG,CAACU,UAAJ,CAAeC,SAAf,EAA0B,IAA1B,EAAgCV,GAAhC;AAEA,SAAKI,MAAL,GAAc,KAAKI,SAAL,CAAeJ,MAA7B;AACD;;AASDO,EAAAA,OAAO,CAACC,CAAD,EAAYC,YAAZ,EAAkE;AACvE,QAAID,CAAC,GAAG,CAAJ,IAASA,CAAC,IAAI,KAAKJ,SAAL,CAAeJ,MAAjC,EAAyC;AACvC,YAAM,IAAIU,KAAJ,CAAU,6BAAV,CAAN;AACD;;AAED,SAAKT,IAAL,CAAUU,GAAV,GAAgB,KAAKP,SAAL,CAAeI,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MiB,GAAG,GAAGlB,GAAG,CAACiB,UAAJ,MAAoB,CAAhC;AAEAM,IAAAA,KAAK,GACHL,GAAG,KAAK,CAAR,GACIlB,GAAG,CAACoB,UAAJ,EADJ,GAEIF,GAAG,KAAK,CAAR,GACAlB,GAAG,CAACwB,SAAJ,EADA,GAEAN,GAAG,KAAK,CAAR,GACAlB,GAAG,CAACyB,UAAJ,EADA,GAEAP,GAAG,KAAK,CAAR,GACAlB,GAAG,CAAC0B,YAAJ,EADA,GAEAR,GAAG,KAAK,CAAR,GACAlB,GAAG,CAACiB,UAAJ,EADA,GAEAC,GAAG,KAAK,CAAR,GACAlB,GAAG,CAAC2B,WAAJ,EADA,GAEAT,GAAG,KAAK,CAAR,GACAlB,GAAG,CAAC4B,WAAJ,EADA,GAEA,IAfN;AAgBD;;AAED,SAAOL,KAAP;AACD","sourcesContent":["/* eslint-disable indent */\n// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport VectorTileFeature from './vector-tile-feature';\nimport Protobuf from 'pbf';\nimport {GeojsonGeometryInfo} from '@loaders.gl/schema';\n\nexport default class VectorTileLayer {\n version: number;\n name: string;\n extent: number;\n length: number;\n _pbf: Protobuf;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n _features: number[];\n constructor(pbf: Protobuf, end: number) {\n // Public\n this.version = 1;\n this.name = '';\n this.extent = 4096;\n this.length = 0;\n\n // Private\n this._pbf = pbf;\n this._keys = [];\n this._values = [];\n this._features = [];\n\n pbf.readFields(readLayer, this, end);\n\n this.length = this._features.length;\n }\n\n /**\n * return feature `i` from this layer as a `VectorTileFeature`\n *\n * @param index\n * @param geometryInfo\n * @returns {VectorTileFeature}\n */\n feature(i: number, geometryInfo: GeojsonGeometryInfo): VectorTileFeature {\n if (i < 0 || i >= this._features.length) {\n throw new Error('feature index out of bounds');\n }\n\n this._pbf.pos = this._features[i];\n\n const end = this._pbf.readVarint() + this._pbf.pos;\n return new VectorTileFeature(\n this._pbf,\n end,\n this.extent,\n this._keys,\n this._values,\n geometryInfo\n );\n }\n}\n\n/**\n *\n * @param tag\n * @param layer\n * @param pbf\n */\nfunction readLayer(tag: number, layer?: VectorTileLayer, pbf?: Protobuf): void {\n if (layer && pbf) {\n if (tag === 15) layer.version = pbf.readVarint();\n else if (tag === 1) layer.name = pbf.readString();\n else if (tag === 5) layer.extent = pbf.readVarint();\n else if (tag === 2) layer._features.push(pbf.pos);\n else if (tag === 3) layer._keys.push(pbf.readString());\n else if (tag === 4) layer._values.push(readValueMessage(pbf));\n }\n}\n\n/**\n *\n * @param pbf\n * @returns value\n */\nfunction readValueMessage(pbf: Protobuf) {\n let value: string | number | boolean | null = null;\n const end = pbf.readVarint() + pbf.pos;\n\n while (pbf.pos < end) {\n const tag = pbf.readVarint() >> 3;\n\n value =\n tag === 1\n ? pbf.readString()\n : tag === 2\n ? pbf.readFloat()\n : tag === 3\n ? pbf.readDouble()\n : tag === 4\n ? pbf.readVarint64()\n : tag === 5\n ? pbf.readVarint()\n : tag === 6\n ? pbf.readSVarint()\n : tag === 7\n ? pbf.readBoolean()\n : null;\n }\n\n return value;\n}\n"],"file":"vector-tile-layer.js"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import VectorTile from './mapbox-vector-tile/vector-tile';
|
|
2
2
|
import BinaryVectorTile from './binary-vector-tile/vector-tile';
|
|
3
|
-
import {
|
|
3
|
+
import { flatGeojsonToBinary } from '@loaders.gl/gis';
|
|
4
4
|
import Protobuf from 'pbf';
|
|
5
5
|
export default function parseMVT(arrayBuffer, options) {
|
|
6
6
|
options = normalizeOptions(options);
|
|
@@ -8,7 +8,8 @@ export default function parseMVT(arrayBuffer, options) {
|
|
|
8
8
|
|
|
9
9
|
if (options) {
|
|
10
10
|
const binary = options.gis.format === 'binary';
|
|
11
|
-
const
|
|
11
|
+
const geometryInfo = {
|
|
12
|
+
coordLength: 2,
|
|
12
13
|
pointPositionsCount: 0,
|
|
13
14
|
pointFeaturesCount: 0,
|
|
14
15
|
linePositionsCount: 0,
|
|
@@ -35,7 +36,7 @@ export default function parseMVT(arrayBuffer, options) {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
38
|
-
const vectorTileFeature = vectorTileLayer.feature(i,
|
|
39
|
+
const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
|
|
39
40
|
const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
|
|
40
41
|
features.push(decodedFeature);
|
|
41
42
|
}
|
|
@@ -43,7 +44,7 @@ export default function parseMVT(arrayBuffer, options) {
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
if (binary) {
|
|
46
|
-
const data =
|
|
47
|
+
const data = flatGeojsonToBinary(features, geometryInfo);
|
|
47
48
|
data.byteLength = arrayBuffer.byteLength;
|
|
48
49
|
return data;
|
|
49
50
|
}
|
|
@@ -85,7 +86,7 @@ function getDecodedFeature(feature, options) {
|
|
|
85
86
|
function getDecodedFeatureBinary(feature, options) {
|
|
86
87
|
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
87
88
|
|
|
88
|
-
if (options.layerProperty) {
|
|
89
|
+
if (options.layerProperty && decodedFeature.properties) {
|
|
89
90
|
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
90
91
|
}
|
|
91
92
|
|
|
@@ -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,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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DtB,OAArD,EAAmF;AAKjF,QAAM;AAACuB,IAAAA;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 {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,C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,UAA5C,EAAwD;AACtDlB,IAAAA,cAAc,CAACkB,UAAf,CAA0BrD,OAAO,CAACoD,aAAlC,IAAmDpD,OAAO,CAAC4B,SAA3D;AACD;;AAED,SAAOO,cAAP;AACD;;AAMD,SAASgB,2BAAT,CAAqCK,IAArC,EAAqDtB,OAArD,EAAmF;AAKjF,QAAM;AAACuB,IAAAA;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"}
|
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.
|
|
2
|
+
const VERSION = typeof "3.1.2" !== 'undefined' ? "3.1.2" : '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,mBAAuB,WAAvB,aAAmD,QAAnE;AAKA,OAAO,MAAMC,eAAuB,GAAG;AACrCC,EAAAA,IAAI,EAAE,oBAD+B;AAErCC,EAAAA,EAAE,EAAE,KAFiC;AAGrCC,EAAAA,MAAM,EAAE,KAH6B;AAIrCC,EAAAA,OAAO,EAAEL,OAJ4B;AAMrCM,EAAAA,UAAU,EAAE,CAAC,KAAD,EAAQ,KAAR,CANyB;AAOrCC,EAAAA,SAAS,EAAE,CACT,oCADS,EAET,wBAFS,CAP0B;AAYrCC,EAAAA,MAAM,EAAE,IAZ6B;AAarCC,EAAAA,QAAQ,EAAE,UAb2B;AAcrCC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AACHC,MAAAA,WAAW,EAAE,OADV;AAEHC,MAAAA,aAAa,EAAE,WAFZ;AAGHC,MAAAA,MAAM,EAAE,IAHL;AAIHC,MAAAA,SAAS,EAAE;AAJR;AADE;AAd4B,CAAhC;AA2BP,OAAO,MAAMC,SAA2B,GAAG,EACzC,GAAGf,eADsC;AAEzCgB,EAAAA,KAAK,EAAE,OAAOC,WAAP,EAAoBR,OAApB,KAAgCX,QAAQ,CAACmB,WAAD,EAAcR,OAAd,CAFN;AAGzCS,EAAAA,SAAS,EAAEpB,QAH8B;AAIzCqB,EAAAA,MAAM,EAAE;AAJiC,CAApC","sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport parseMVT from './lib/parse-mvt';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for the Mapbox Vector Tile format\n */\nexport const MVTWorkerLoader: Loader = {\n name: 'Mapbox Vector Tile',\n id: 'mvt',\n module: 'mvt',\n version: VERSION,\n // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'\n extensions: ['mvt', 'pbf'],\n mimeTypes: [\n 'application/vnd.mapbox-vector-tile',\n 'application/x-protobuf'\n // 'application/octet-stream'\n ],\n worker: true,\n category: 'geometry',\n options: {\n mvt: {\n coordinates: 'local',\n layerProperty: 'layerName',\n layers: null,\n tileIndex: null\n }\n }\n};\n\n/**\n * Loader for the Mapbox Vector Tile format\n */\nexport const MVTLoader: LoaderWithParser = {\n ...MVTWorkerLoader,\n parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),\n parseSync: parseMVT,\n binary: true\n};\n"],"file":"mvt-loader.js"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Protobuf from 'pbf';
|
|
2
|
-
import {
|
|
2
|
+
import { FlatIndexedGeometry, FlatPolygon } from '@loaders.gl/schema';
|
|
3
3
|
import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
|
|
4
4
|
/**
|
|
5
5
|
* Classifies an array of rings into polygons with outer rings and holes
|
|
@@ -10,11 +10,7 @@ import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
|
|
|
10
10
|
* @param geometry
|
|
11
11
|
* @returns object
|
|
12
12
|
*/
|
|
13
|
-
export declare function classifyRings(geom:
|
|
14
|
-
areas: any[];
|
|
15
|
-
lines: any[];
|
|
16
|
-
data: number[];
|
|
17
|
-
};
|
|
13
|
+
export declare function classifyRings(geom: FlatIndexedGeometry): FlatPolygon;
|
|
18
14
|
/**
|
|
19
15
|
*
|
|
20
16
|
* @param data
|
|
@@ -1 +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,
|
|
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,mBAAmB,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AACpE,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAE9E;;;;;;;;GAQG;AAEH,wBAAgB,aAAa,CAAC,IAAI,EAAE,mBAAmB,GAAG,WAAW,CA4DpE;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"}
|
|
@@ -13,12 +13,14 @@ const polygon_1 = require("@math.gl/polygon");
|
|
|
13
13
|
*/
|
|
14
14
|
// eslint-disable-next-line max-statements
|
|
15
15
|
function classifyRings(geom) {
|
|
16
|
-
const len = geom.
|
|
16
|
+
const len = geom.indices.length;
|
|
17
|
+
const type = 'Polygon';
|
|
17
18
|
if (len <= 1) {
|
|
18
19
|
return {
|
|
20
|
+
type,
|
|
19
21
|
data: geom.data,
|
|
20
22
|
areas: [[(0, polygon_1.getPolygonSignedArea)(geom.data)]],
|
|
21
|
-
|
|
23
|
+
indices: [geom.indices]
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
26
|
const areas = [];
|
|
@@ -28,8 +30,8 @@ function classifyRings(geom) {
|
|
|
28
30
|
let ccw;
|
|
29
31
|
let offset = 0;
|
|
30
32
|
for (let endIndex, i = 0, startIndex; i < len; i++) {
|
|
31
|
-
startIndex = geom.
|
|
32
|
-
endIndex = geom.
|
|
33
|
+
startIndex = geom.indices[i] - offset;
|
|
34
|
+
endIndex = geom.indices[i + 1] - offset || geom.data.length;
|
|
33
35
|
const shape = geom.data.slice(startIndex, endIndex);
|
|
34
36
|
const area = (0, polygon_1.getPolygonSignedArea)(shape);
|
|
35
37
|
if (area === 0) {
|
|
@@ -63,7 +65,7 @@ function classifyRings(geom) {
|
|
|
63
65
|
areas.push(ringAreas);
|
|
64
66
|
if (polygon.length)
|
|
65
67
|
polygons.push(polygon);
|
|
66
|
-
return { areas,
|
|
68
|
+
return { type, areas, indices: polygons, data: geom.data };
|
|
67
69
|
}
|
|
68
70
|
exports.classifyRings = classifyRings;
|
|
69
71
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Protobuf from 'pbf';
|
|
2
|
-
import {
|
|
2
|
+
import { FlatFeature, FlatIndexedGeometry, GeojsonGeometryInfo } from '@loaders.gl/schema';
|
|
3
3
|
import { classifyRings } from '../../helpers/binary-util-functions';
|
|
4
4
|
export declare const TEST_EXPORTS: {
|
|
5
5
|
classifyRings: typeof classifyRings;
|
|
@@ -15,22 +15,27 @@ export default class VectorTileFeature {
|
|
|
15
15
|
_geometry: number;
|
|
16
16
|
_keys: string[];
|
|
17
17
|
_values: (string | number | boolean | null)[];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
loadGeometry(): MvtBinaryGeometry;
|
|
18
|
+
_geometryInfo: GeojsonGeometryInfo;
|
|
19
|
+
constructor(pbf: Protobuf, end: number, extent: any, keys: string[], values: (string | number | boolean | null)[], geometryInfo: GeojsonGeometryInfo);
|
|
20
|
+
loadGeometry(): FlatIndexedGeometry;
|
|
22
21
|
/**
|
|
23
22
|
*
|
|
24
23
|
* @param transform
|
|
25
24
|
* @returns result
|
|
26
25
|
*/
|
|
27
|
-
_toBinaryCoordinates(transform: any):
|
|
26
|
+
_toBinaryCoordinates(transform: any): {
|
|
27
|
+
type: "Feature";
|
|
28
|
+
geometry: import("@loaders.gl/schema").FlatGeometry;
|
|
29
|
+
id?: string | number | undefined;
|
|
30
|
+
properties: import("geojson").GeoJsonProperties;
|
|
31
|
+
bbox?: import("geojson").BBox | undefined;
|
|
32
|
+
};
|
|
28
33
|
toBinaryCoordinates(options: {
|
|
29
34
|
x: number;
|
|
30
35
|
y: number;
|
|
31
36
|
z: number;
|
|
32
37
|
} | ((data: number[], feature: {
|
|
33
38
|
extent: any;
|
|
34
|
-
}) => void)):
|
|
39
|
+
}) => void)): FlatFeature;
|
|
35
40
|
}
|
|
36
41
|
//# sourceMappingURL=vector-tile-feature.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,
|
|
1
|
+
{"version":3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AAE,OAAO,EAAE;QAAC,MAAM,EAAE,GAAG,CAAA;KAAC,KAAK,IAAI,CAAC,GAC9F,WAAW;CAMf"}
|
|
@@ -16,7 +16,7 @@ exports.TEST_EXPORTS = {
|
|
|
16
16
|
};
|
|
17
17
|
class VectorTileFeature {
|
|
18
18
|
// eslint-disable-next-line max-params
|
|
19
|
-
constructor(pbf, end, extent, keys, values,
|
|
19
|
+
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
20
20
|
// Public
|
|
21
21
|
this.properties = {};
|
|
22
22
|
this.extent = extent;
|
|
@@ -27,12 +27,9 @@ class VectorTileFeature {
|
|
|
27
27
|
this._geometry = -1;
|
|
28
28
|
this._keys = keys;
|
|
29
29
|
this._values = values;
|
|
30
|
-
this.
|
|
30
|
+
this._geometryInfo = geometryInfo;
|
|
31
31
|
pbf.readFields(binary_util_functions_1.readFeature, this, end);
|
|
32
32
|
}
|
|
33
|
-
static get types() {
|
|
34
|
-
return ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
35
|
-
}
|
|
36
33
|
// eslint-disable-next-line complexity, max-statements
|
|
37
34
|
loadGeometry() {
|
|
38
35
|
const pbf = this._pbf;
|
|
@@ -48,7 +45,7 @@ class VectorTileFeature {
|
|
|
48
45
|
// `set()` and direct index access. Also, we cannot
|
|
49
46
|
// know how large the buffer should be, so it would
|
|
50
47
|
// increase memory usage
|
|
51
|
-
const
|
|
48
|
+
const indices = []; // Indices where geometries start
|
|
52
49
|
const data = []; // Flat array of coordinate data
|
|
53
50
|
while (pbf.pos < endPos) {
|
|
54
51
|
if (length <= 0) {
|
|
@@ -62,7 +59,7 @@ class VectorTileFeature {
|
|
|
62
59
|
y += pbf.readSVarint();
|
|
63
60
|
if (cmd === 1) {
|
|
64
61
|
// New line
|
|
65
|
-
|
|
62
|
+
indices.push(i);
|
|
66
63
|
}
|
|
67
64
|
data.push(x, y);
|
|
68
65
|
i += 2;
|
|
@@ -70,7 +67,7 @@ class VectorTileFeature {
|
|
|
70
67
|
else if (cmd === 7) {
|
|
71
68
|
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
72
69
|
if (i > 0) {
|
|
73
|
-
const start =
|
|
70
|
+
const start = indices[indices.length - 1]; // start index of polygon
|
|
74
71
|
data.push(data[start], data[start + 1]); // closePolygon
|
|
75
72
|
i += 2;
|
|
76
73
|
}
|
|
@@ -79,7 +76,7 @@ class VectorTileFeature {
|
|
|
79
76
|
throw new Error(`unknown command ${cmd}`);
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
|
-
return { data,
|
|
79
|
+
return { data, indices };
|
|
83
80
|
}
|
|
84
81
|
/**
|
|
85
82
|
*
|
|
@@ -87,63 +84,59 @@ class VectorTileFeature {
|
|
|
87
84
|
* @returns result
|
|
88
85
|
*/
|
|
89
86
|
_toBinaryCoordinates(transform) {
|
|
90
|
-
// Expands the protobuf data to an intermediate
|
|
87
|
+
// Expands the protobuf data to an intermediate Flat GeoJSON
|
|
91
88
|
// data format, which maps closely to the binary data buffers.
|
|
92
89
|
// It is similar to GeoJSON, but rather than storing the coordinates
|
|
93
90
|
// in multidimensional arrays, we have a 1D `data` with all the
|
|
94
|
-
// coordinates, and then index into this using the `
|
|
91
|
+
// coordinates, and then index into this using the `indices`
|
|
95
92
|
// parameter, e.g.
|
|
96
93
|
//
|
|
97
94
|
// geometry: {
|
|
98
|
-
// type: 'Point', data: [1,2],
|
|
95
|
+
// type: 'Point', data: [1,2], indices: [0]
|
|
99
96
|
// }
|
|
100
97
|
// geometry: {
|
|
101
|
-
// type: 'LineString', data: [1,2,3,4,...],
|
|
98
|
+
// type: 'LineString', data: [1,2,3,4,...], indices: [0]
|
|
102
99
|
// }
|
|
103
100
|
// geometry: {
|
|
104
|
-
// type: 'Polygon', data: [1,2,3,4,...],
|
|
101
|
+
// type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
|
|
105
102
|
// }
|
|
106
|
-
// Thus the
|
|
103
|
+
// Thus the indices member lets us look up the relevant range
|
|
107
104
|
// from the data array.
|
|
108
105
|
// The Multi* versions of the above types share the same data
|
|
109
|
-
// structure, just with multiple elements in the
|
|
110
|
-
|
|
106
|
+
// structure, just with multiple elements in the indices array
|
|
107
|
+
const geom = this.loadGeometry();
|
|
108
|
+
let geometry;
|
|
111
109
|
// Apply the supplied transformation to data
|
|
112
110
|
transform(geom.data, this);
|
|
113
111
|
const coordLength = 2;
|
|
114
112
|
// eslint-disable-next-line default-case
|
|
115
113
|
switch (this.type) {
|
|
116
114
|
case 1: // Point
|
|
117
|
-
this.
|
|
118
|
-
this.
|
|
115
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
116
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
117
|
+
geometry = { type: 'Point', ...geom };
|
|
119
118
|
break;
|
|
120
119
|
case 2: // LineString
|
|
121
|
-
this.
|
|
122
|
-
this.
|
|
123
|
-
this.
|
|
120
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
121
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
122
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
123
|
+
geometry = { type: 'LineString', ...geom };
|
|
124
124
|
break;
|
|
125
125
|
case 3: // Polygon
|
|
126
|
-
|
|
127
|
-
// Unlike Point & LineString geom.
|
|
126
|
+
geometry = (0, binary_util_functions_1.classifyRings)(geom);
|
|
127
|
+
// Unlike Point & LineString geom.indices is a 2D array, thanks
|
|
128
128
|
// to the classifyRings method
|
|
129
|
-
this.
|
|
130
|
-
this.
|
|
131
|
-
for (const
|
|
132
|
-
this.
|
|
129
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
130
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
131
|
+
for (const indices of geometry.indices) {
|
|
132
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
133
133
|
}
|
|
134
|
-
this.
|
|
135
|
-
geom = classified;
|
|
134
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
136
135
|
break;
|
|
136
|
+
default:
|
|
137
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
137
138
|
}
|
|
138
|
-
|
|
139
|
-
if (geom.lines.length > 1) {
|
|
140
|
-
geom.type = `Multi${geom.type}`;
|
|
141
|
-
}
|
|
142
|
-
const result = {
|
|
143
|
-
type: 'Feature',
|
|
144
|
-
geometry: geom,
|
|
145
|
-
properties: this.properties
|
|
146
|
-
};
|
|
139
|
+
const result = { type: 'Feature', geometry, properties: this.properties };
|
|
147
140
|
if (this.id !== null) {
|
|
148
141
|
result.id = this.id;
|
|
149
142
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import VectorTileFeature from './vector-tile-feature';
|
|
2
2
|
import Protobuf from 'pbf';
|
|
3
|
-
import {
|
|
3
|
+
import { GeojsonGeometryInfo } from '@loaders.gl/schema';
|
|
4
4
|
export default class VectorTileLayer {
|
|
5
5
|
version: number;
|
|
6
6
|
name: string;
|
|
@@ -15,9 +15,9 @@ export default class VectorTileLayer {
|
|
|
15
15
|
* return feature `i` from this layer as a `VectorTileFeature`
|
|
16
16
|
*
|
|
17
17
|
* @param index
|
|
18
|
-
* @param
|
|
18
|
+
* @param geometryInfo
|
|
19
19
|
* @returns {VectorTileFeature}
|
|
20
20
|
*/
|
|
21
|
-
feature(i: number,
|
|
21
|
+
feature(i: number, geometryInfo: GeojsonGeometryInfo): VectorTileFeature;
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=vector-tile-layer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AACtD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AACtD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,SAAS,EAAE,MAAM,EAAE,CAAC;gBACR,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM;IAkBtC;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,mBAAmB,GAAG,iBAAiB;CAiBzE"}
|
|
@@ -25,16 +25,16 @@ class VectorTileLayer {
|
|
|
25
25
|
* return feature `i` from this layer as a `VectorTileFeature`
|
|
26
26
|
*
|
|
27
27
|
* @param index
|
|
28
|
-
* @param
|
|
28
|
+
* @param geometryInfo
|
|
29
29
|
* @returns {VectorTileFeature}
|
|
30
30
|
*/
|
|
31
|
-
feature(i,
|
|
31
|
+
feature(i, geometryInfo) {
|
|
32
32
|
if (i < 0 || i >= this._features.length) {
|
|
33
33
|
throw new Error('feature index out of bounds');
|
|
34
34
|
}
|
|
35
35
|
this._pbf.pos = this._features[i];
|
|
36
36
|
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
37
|
-
return new vector_tile_feature_1.default(this._pbf, end, this.extent, this._keys, this._values,
|
|
37
|
+
return new vector_tile_feature_1.default(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
exports.default = VectorTileLayer;
|
package/dist/lib/parse-mvt.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { MvtMapboxCoordinates } from '../lib/types';
|
|
2
2
|
import { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
3
3
|
/**
|
|
4
4
|
* Parse MVT arrayBuffer and return GeoJSON.
|
|
@@ -7,79 +7,11 @@ import { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
|
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?: LoaderOptions): {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
value: Uint16Array | Uint32Array;
|
|
18
|
-
size: number;
|
|
19
|
-
};
|
|
20
|
-
featureIds: {
|
|
21
|
-
value: Uint16Array | Uint32Array;
|
|
22
|
-
size: number;
|
|
23
|
-
};
|
|
24
|
-
numericProps: object;
|
|
25
|
-
properties: {}[];
|
|
26
|
-
fields: {
|
|
27
|
-
id?: number | undefined;
|
|
28
|
-
}[];
|
|
29
|
-
};
|
|
30
|
-
lines: {
|
|
31
|
-
pathIndices: {
|
|
32
|
-
value: Uint16Array | Uint32Array;
|
|
33
|
-
size: number;
|
|
34
|
-
};
|
|
35
|
-
positions: {
|
|
36
|
-
value: Float32Array;
|
|
37
|
-
size: number;
|
|
38
|
-
};
|
|
39
|
-
globalFeatureIds: {
|
|
40
|
-
value: Uint16Array | Uint32Array;
|
|
41
|
-
size: number;
|
|
42
|
-
};
|
|
43
|
-
featureIds: {
|
|
44
|
-
value: Uint16Array | Uint32Array;
|
|
45
|
-
size: number;
|
|
46
|
-
};
|
|
47
|
-
numericProps: object;
|
|
48
|
-
properties: {}[];
|
|
49
|
-
fields: {
|
|
50
|
-
id?: number | undefined;
|
|
51
|
-
}[];
|
|
52
|
-
};
|
|
53
|
-
polygons: {
|
|
54
|
-
polygonIndices: {
|
|
55
|
-
value: Uint16Array | Uint32Array;
|
|
56
|
-
size: number;
|
|
57
|
-
};
|
|
58
|
-
primitivePolygonIndices: {
|
|
59
|
-
value: Uint16Array | Uint32Array;
|
|
60
|
-
size: number;
|
|
61
|
-
};
|
|
62
|
-
positions: {
|
|
63
|
-
value: Float32Array;
|
|
64
|
-
size: number;
|
|
65
|
-
};
|
|
66
|
-
triangles: {
|
|
67
|
-
value: Uint32Array;
|
|
68
|
-
size: number;
|
|
69
|
-
};
|
|
70
|
-
globalFeatureIds: {
|
|
71
|
-
value: Uint16Array | Uint32Array;
|
|
72
|
-
size: number;
|
|
73
|
-
};
|
|
74
|
-
featureIds: {
|
|
75
|
-
value: Uint16Array | Uint32Array;
|
|
76
|
-
size: number;
|
|
77
|
-
};
|
|
78
|
-
numericProps: object;
|
|
79
|
-
properties: {}[];
|
|
80
|
-
fields: {
|
|
81
|
-
id?: number | undefined;
|
|
82
|
-
}[];
|
|
83
|
-
};
|
|
84
|
-
} | (MvtBinaryCoordinates | MvtMapboxCoordinates)[];
|
|
10
|
+
export default function parseMVT(arrayBuffer: ArrayBuffer, options?: LoaderOptions): (MvtMapboxCoordinates | {
|
|
11
|
+
type: "Feature";
|
|
12
|
+
geometry: import("@loaders.gl/schema").FlatGeometry;
|
|
13
|
+
id?: string | number | undefined;
|
|
14
|
+
properties: import("geojson").GeoJsonProperties;
|
|
15
|
+
bbox?: import("geojson").BBox | undefined;
|
|
16
|
+
})[] | import("@loaders.gl/schema").BinaryFeatures;
|
|
85
17
|
//# sourceMappingURL=parse-mvt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,oBAAoB,EAAa,MAAM,cAAc,CAAC;AAGnE,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,aAAa;;;;;;mDA0DjF"}
|
package/dist/lib/parse-mvt.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
// import {VectorTile} from '@mapbox/vector-tile';
|
|
7
7
|
const vector_tile_1 = __importDefault(require("./mapbox-vector-tile/vector-tile"));
|
|
8
8
|
const vector_tile_2 = __importDefault(require("./binary-vector-tile/vector-tile"));
|
|
9
|
-
const
|
|
9
|
+
const gis_1 = require("@loaders.gl/gis");
|
|
10
10
|
const pbf_1 = __importDefault(require("pbf"));
|
|
11
11
|
/**
|
|
12
12
|
* Parse MVT arrayBuffer and return GeoJSON.
|
|
@@ -20,7 +20,8 @@ function parseMVT(arrayBuffer, options) {
|
|
|
20
20
|
const features = [];
|
|
21
21
|
if (options) {
|
|
22
22
|
const binary = options.gis.format === 'binary';
|
|
23
|
-
const
|
|
23
|
+
const geometryInfo = {
|
|
24
|
+
coordLength: 2,
|
|
24
25
|
pointPositionsCount: 0,
|
|
25
26
|
pointFeaturesCount: 0,
|
|
26
27
|
linePositionsCount: 0,
|
|
@@ -46,7 +47,7 @@ function parseMVT(arrayBuffer, options) {
|
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
49
|
for (let i = 0; i < vectorTileLayer.length; i++) {
|
|
49
|
-
const vectorTileFeature = vectorTileLayer.feature(i,
|
|
50
|
+
const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
|
|
50
51
|
const decodedFeature = binary
|
|
51
52
|
? getDecodedFeatureBinary(vectorTileFeature, featureOptions)
|
|
52
53
|
: getDecodedFeature(vectorTileFeature, featureOptions);
|
|
@@ -55,7 +56,7 @@ function parseMVT(arrayBuffer, options) {
|
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
if (binary) {
|
|
58
|
-
const data = (0,
|
|
59
|
+
const data = (0, gis_1.flatGeojsonToBinary)(features, geometryInfo);
|
|
59
60
|
// Add the original byteLength (as a reasonable approximation of the size of the binary data)
|
|
60
61
|
// TODO decide where to store extra fields like byteLength (header etc) and document
|
|
61
62
|
// @ts-ignore
|
|
@@ -111,7 +112,7 @@ function getDecodedFeature(feature, options) {
|
|
|
111
112
|
function getDecodedFeatureBinary(feature, options) {
|
|
112
113
|
const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
|
|
113
114
|
// Add layer name to GeoJSON properties
|
|
114
|
-
if (options.layerProperty) {
|
|
115
|
+
if (options.layerProperty && decodedFeature.properties) {
|
|
115
116
|
decodedFeature.properties[options.layerProperty] = options.layerName;
|
|
116
117
|
}
|
|
117
118
|
return decodedFeature;
|