@loaders.gl/mvt 3.1.0-beta.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/bundle.js +17 -13
  2. package/dist/es5/bundle.js +1 -1
  3. package/dist/es5/bundle.js.map +1 -1
  4. package/dist/es5/helpers/binary-util-functions.js +18 -18
  5. package/dist/es5/helpers/binary-util-functions.js.map +1 -1
  6. package/dist/es5/helpers/mapbox-util-functions.js +11 -11
  7. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -1
  8. package/dist/es5/index.js +2 -2
  9. package/dist/es5/lib/binary-vector-tile/features-to-binary.js +187 -136
  10. package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +1 -1
  11. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +131 -104
  12. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  13. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +23 -15
  14. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  15. package/dist/es5/lib/binary-vector-tile/vector-tile.js +8 -8
  16. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -1
  17. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +157 -147
  18. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
  19. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +23 -15
  20. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -1
  21. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +8 -8
  22. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -1
  23. package/dist/es5/lib/parse-mvt.js +35 -33
  24. package/dist/es5/lib/parse-mvt.js.map +1 -1
  25. package/dist/es5/mvt-loader.js +38 -5
  26. package/dist/es5/mvt-loader.js.map +1 -1
  27. package/dist/esm/lib/binary-vector-tile/features-to-binary.js +18 -14
  28. package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +1 -1
  29. package/dist/esm/mvt-loader.js +1 -1
  30. package/dist/esm/mvt-loader.js.map +1 -1
  31. package/dist/lib/binary-vector-tile/features-to-binary.d.ts +0 -8
  32. package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +1 -1
  33. package/dist/lib/binary-vector-tile/features-to-binary.js +21 -16
  34. package/dist/lib/types.d.ts +4 -0
  35. package/dist/lib/types.d.ts.map +1 -1
  36. package/dist/mvt-worker.js +17 -13
  37. package/package.json +4 -4
  38. package/src/lib/binary-vector-tile/features-to-binary.ts +25 -16
  39. package/src/lib/types.ts +6 -0
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = parseMVT;
9
9
 
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
10
12
  var _vectorTile = _interopRequireDefault(require("./mapbox-vector-tile/vector-tile"));
11
13
 
12
14
  var _vectorTile2 = _interopRequireDefault(require("./binary-vector-tile/vector-tile"));
@@ -15,13 +17,17 @@ var _featuresToBinary = require("./binary-vector-tile/features-to-binary");
15
17
 
16
18
  var _pbf = _interopRequireDefault(require("pbf"));
17
19
 
20
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
21
+
22
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
+
18
24
  function parseMVT(arrayBuffer, options) {
19
25
  options = normalizeOptions(options);
20
- const features = [];
26
+ var features = [];
21
27
 
22
28
  if (options) {
23
- const binary = options.gis.format === 'binary';
24
- const firstPassData = {
29
+ var binary = options.gis.format === 'binary';
30
+ var firstPassData = {
25
31
  pointPositionsCount: 0,
26
32
  pointFeaturesCount: 0,
27
33
  linePositionsCount: 0,
@@ -34,29 +40,30 @@ function parseMVT(arrayBuffer, options) {
34
40
  };
35
41
 
36
42
  if (arrayBuffer.byteLength > 0) {
37
- const tile = binary ? new _vectorTile2.default(new _pbf.default(arrayBuffer)) : new _vectorTile.default(new _pbf.default(arrayBuffer));
38
- const loaderOptions = options.mvt;
39
- const selectedLayers = Array.isArray(loaderOptions.layers) ? loaderOptions.layers : Object.keys(tile.layers);
40
- selectedLayers.forEach(layerName => {
41
- const vectorTileLayer = tile.layers[layerName];
42
- const featureOptions = { ...loaderOptions,
43
- layerName
44
- };
43
+ var tile = binary ? new _vectorTile2.default(new _pbf.default(arrayBuffer)) : new _vectorTile.default(new _pbf.default(arrayBuffer));
44
+ var loaderOptions = options.mvt;
45
+ var selectedLayers = Array.isArray(loaderOptions.layers) ? loaderOptions.layers : Object.keys(tile.layers);
46
+ selectedLayers.forEach(function (layerName) {
47
+ var vectorTileLayer = tile.layers[layerName];
48
+
49
+ var featureOptions = _objectSpread(_objectSpread({}, loaderOptions), {}, {
50
+ layerName: layerName
51
+ });
45
52
 
46
53
  if (!vectorTileLayer) {
47
54
  return;
48
55
  }
49
56
 
50
- for (let i = 0; i < vectorTileLayer.length; i++) {
51
- const vectorTileFeature = vectorTileLayer.feature(i, firstPassData);
52
- const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
57
+ for (var i = 0; i < vectorTileLayer.length; i++) {
58
+ var vectorTileFeature = vectorTileLayer.feature(i, firstPassData);
59
+ var decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
53
60
  features.push(decodedFeature);
54
61
  }
55
62
  });
56
63
  }
57
64
 
58
65
  if (binary) {
59
- const data = (0, _featuresToBinary.featuresToBinary)(features, firstPassData);
66
+ var data = (0, _featuresToBinary.featuresToBinary)(features, firstPassData);
60
67
  data.byteLength = arrayBuffer.byteLength;
61
68
  return data;
62
69
  }
@@ -67,15 +74,14 @@ function parseMVT(arrayBuffer, options) {
67
74
 
68
75
  function normalizeOptions(options) {
69
76
  if (options) {
70
- options = { ...options,
77
+ options = _objectSpread(_objectSpread({}, options), {}, {
71
78
  mvt: options.mvt || {},
72
79
  gis: options.gis || {}
73
- };
74
- const wgs84Coordinates = options.coordinates === 'wgs84';
75
- const {
76
- tileIndex
77
- } = options;
78
- const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
80
+ });
81
+ var wgs84Coordinates = options.coordinates === 'wgs84';
82
+ var _options = options,
83
+ tileIndex = _options.tileIndex;
84
+ var hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
79
85
 
80
86
  if (wgs84Coordinates && !hasTileIndex) {
81
87
  throw new Error('MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.');
@@ -86,7 +92,7 @@ function normalizeOptions(options) {
86
92
  }
87
93
 
88
94
  function getDecodedFeature(feature, options) {
89
- const decodedFeature = feature.toGeoJSON(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
95
+ var decodedFeature = feature.toGeoJSON(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
90
96
 
91
97
  if (options.layerProperty) {
92
98
  decodedFeature.properties[options.layerProperty] = options.layerName;
@@ -96,7 +102,7 @@ function getDecodedFeature(feature, options) {
96
102
  }
97
103
 
98
104
  function getDecodedFeatureBinary(feature, options) {
99
- const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
105
+ var decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
100
106
 
101
107
  if (options.layerProperty) {
102
108
  decodedFeature.properties[options.layerProperty] = options.layerName;
@@ -106,23 +112,19 @@ function getDecodedFeatureBinary(feature, options) {
106
112
  }
107
113
 
108
114
  function transformToLocalCoordinates(line, feature) {
109
- const {
110
- extent
111
- } = feature;
115
+ var extent = feature.extent;
112
116
 
113
- for (let i = 0; i < line.length; i++) {
114
- const p = line[i];
117
+ for (var i = 0; i < line.length; i++) {
118
+ var p = line[i];
115
119
  p[0] /= extent;
116
120
  p[1] /= extent;
117
121
  }
118
122
  }
119
123
 
120
124
  function transformToLocalCoordinatesBinary(data, feature) {
121
- const {
122
- extent
123
- } = feature;
125
+ var extent = feature.extent;
124
126
 
125
- for (let i = 0, il = data.length; i < il; ++i) {
127
+ for (var i = 0, il = data.length; i < il; ++i) {
126
128
  data[i] /= extent;
127
129
  }
128
130
  }
@@ -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,QAA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B,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":["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,CAA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IAA3C,EAA2DL,OAA3D,EAAmF;AAGjF,MAAOuB,MAAP,GAAiBvB,OAAjB,CAAOuB,MAAP;;AACA,OAAK,IAAI1B,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"}
@@ -7,10 +7,20 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.MVTLoader = exports.MVTWorkerLoader = void 0;
9
9
 
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
+
10
16
  var _parseMvt = _interopRequireDefault(require("./lib/parse-mvt"));
11
17
 
12
- const VERSION = typeof "3.1.0-beta.2" !== 'undefined' ? "3.1.0-beta.2" : 'latest';
13
- const MVTWorkerLoader = {
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
19
+
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
21
+
22
+ var VERSION = typeof "3.1.0" !== 'undefined' ? "3.1.0" : 'latest';
23
+ var MVTWorkerLoader = {
14
24
  name: 'Mapbox Vector Tile',
15
25
  id: 'mvt',
16
26
  module: 'mvt',
@@ -29,10 +39,33 @@ const MVTWorkerLoader = {
29
39
  }
30
40
  };
31
41
  exports.MVTWorkerLoader = MVTWorkerLoader;
32
- const MVTLoader = { ...MVTWorkerLoader,
33
- parse: async (arrayBuffer, options) => (0, _parseMvt.default)(arrayBuffer, options),
42
+
43
+ var MVTLoader = _objectSpread(_objectSpread({}, MVTWorkerLoader), {}, {
44
+ parse: function () {
45
+ var _parse = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, options) {
46
+ return _regenerator.default.wrap(function _callee$(_context) {
47
+ while (1) {
48
+ switch (_context.prev = _context.next) {
49
+ case 0:
50
+ return _context.abrupt("return", (0, _parseMvt.default)(arrayBuffer, options));
51
+
52
+ case 1:
53
+ case "end":
54
+ return _context.stop();
55
+ }
56
+ }
57
+ }, _callee);
58
+ }));
59
+
60
+ function parse(_x, _x2) {
61
+ return _parse.apply(this, arguments);
62
+ }
63
+
64
+ return parse;
65
+ }(),
34
66
  parseSync: _parseMvt.default,
35
67
  binary: true
36
- };
68
+ });
69
+
37
70
  exports.MVTLoader = MVTLoader;
38
71
  //# sourceMappingURL=mvt-loader.js.map
@@ -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,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
+ {"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,IAAMA,OAAO,GAAG,mBAAuB,WAAvB,aAAmD,QAAnE;AAKO,IAAMC,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,IAAMC,SAA2B,mCACnCf,eADmC;AAEtCgB,EAAAA,KAAK;AAAA,2EAAE,iBAAOC,WAAP,EAAoBR,OAApB;AAAA;AAAA;AAAA;AAAA;AAAA,+CAAgC,uBAASQ,WAAT,EAAsBR,OAAtB,CAAhC;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAAF;;AAAA;AAAA;AAAA;;AAAA;AAAA,KAFiC;AAGtCS,EAAAA,SAAS,EAAEC,iBAH2B;AAItCC,EAAAA,MAAM,EAAE;AAJ8B,EAAjC","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,32 +1,30 @@
1
1
  import { earcut } from '@math.gl/polygon';
2
2
  export function featuresToBinary(features, firstPassData, options) {
3
+ const propArrayTypes = extractNumericPropTypes(features);
4
+ const numericPropKeys = Object.keys(propArrayTypes).filter(k => propArrayTypes[k] !== Array);
3
5
  return fillArrays(features, firstPassData, {
4
- numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),
6
+ numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
7
+ propArrayTypes,
5
8
  PositionDataType: options ? options.PositionDataType : Float32Array
6
9
  });
7
10
  }
8
11
  export const TEST_EXPORTS = {
9
- extractNumericPropKeys,
10
12
  fillArrays
11
13
  };
12
14
 
13
- function extractNumericPropKeys(features) {
14
- const numericPropKeys = {};
15
+ function extractNumericPropTypes(features) {
16
+ const propArrayTypes = {};
15
17
 
16
18
  for (const feature of features) {
17
19
  if (feature.properties) {
18
20
  for (const key in feature.properties) {
19
- const numericSoFar = numericPropKeys[key];
20
-
21
- if (numericSoFar || numericSoFar === undefined) {
22
- const val = feature.properties[key];
23
- numericPropKeys[key] = isNumeric(val);
24
- }
21
+ const val = feature.properties[key];
22
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
25
23
  }
26
24
  }
27
25
  }
28
26
 
29
- return Object.keys(numericPropKeys).filter(k => numericPropKeys[k]);
27
+ return propArrayTypes;
30
28
  }
31
29
 
32
30
  function fillArrays(features, firstPassData, options) {
@@ -43,6 +41,7 @@ function fillArrays(features, firstPassData, options) {
43
41
  } = firstPassData;
44
42
  const {
45
43
  numericPropKeys,
44
+ propArrayTypes,
46
45
  PositionDataType = Float32Array
47
46
  } = options;
48
47
  const hasGlobalId = features[0] && 'id' in features[0];
@@ -79,7 +78,8 @@ function fillArrays(features, firstPassData, options) {
79
78
 
80
79
  for (const object of [points, lines, polygons]) {
81
80
  for (const propName of numericPropKeys) {
82
- object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
81
+ const TypedArray = propArrayTypes[propName];
82
+ object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
83
83
  }
84
84
  }
85
85
 
@@ -321,7 +321,11 @@ function keepStringProperties(properties, numericKeys) {
321
321
  return props;
322
322
  }
323
323
 
324
- function isNumeric(x) {
325
- return Number.isFinite(x);
324
+ function deduceArrayType(x, constructor) {
325
+ if (constructor === Array || !Number.isFinite(x)) {
326
+ return Array;
327
+ }
328
+
329
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
326
330
  }
327
331
  //# sourceMappingURL=features-to-binary.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":["earcut","featuresToBinary","features","firstPassData","options","fillArrays","numericPropKeys","extractNumericPropKeys","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","numericSoFar","undefined","val","isNumeric","Object","keys","filter","k","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","hasGlobalId","coordLength","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","type","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","start","end","l","ll","startPosition","areas","nextLines","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","indices","t","tl","returnObj","value","size","geomType","numericProp","index","numericPropName","numericKeys","props","includes","x","Number","isFinite"],"mappings":"AACA,SAAQA,MAAR,QAAqB,kBAArB;AAwBA,OAAO,SAASC,gBAAT,CACLC,QADK,EAELC,aAFK,EAGLC,OAHK,EAIL;AACA,SAAOC,UAAU,CAACH,QAAD,EAAWC,aAAX,EAA0B;AACzCG,IAAAA,eAAe,EAAEF,OAAO,GAAGA,OAAO,CAACE,eAAX,GAA6BC,sBAAsB,CAACL,QAAD,CADlC;AAEzCM,IAAAA,gBAAgB,EAAEJ,OAAO,GAAGA,O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BinaryCoordinates,\n MvtBinaryGeometry,\n MvtBinaryOptions,\n MvtFirstPassedData,\n MvtLines,\n MvtPoints,\n MvtPolygons\n} from '../types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns filled arrays\n */\nexport function featuresToBinary(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options?: MvtBinaryOptions\n) {\n return fillArrays(features, firstPassData, {\n numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),\n PositionDataType: options ? options.PositionDataType : Float32Array\n });\n}\n\nexport const TEST_EXPORTS = {\n extractNumericPropKeys,\n fillArrays\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric keys\n */\nfunction extractNumericPropKeys(features: MvtBinaryCoordinates[]): string[] {\n const numericPropKeys = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, false is stored to prevent rechecking in the future\n const numericSoFar = numericPropKeys[key];\n if (numericSoFar || numericSoFar === undefined) {\n const val = feature.properties[key];\n numericPropKeys[key] = isNumeric(val);\n }\n }\n }\n }\n\n return Object.keys(numericPropKeys).filter((k) => numericPropKeys[k]);\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options: MvtBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n } = firstPassData;\n const {numericPropKeys, PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const coordLength = 2;\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: MvtPoints = {\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: MvtLines = {\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: MvtPolygons = {\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n case 'MultiPoint':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n case 'MultiLineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n case 'MultiPolygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: MvtBinaryGeometry,\n points: MvtPoints,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: MvtBinaryGeometry,\n lines: MvtLines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.lines.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.lines[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.lines[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: MvtBinaryGeometry,\n polygons: MvtPolygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.lines is a 2D array\n for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas![l];\n const lines = geometry.lines[l];\n const nextLines = geometry.lines[l + 1];\n\n for (let i = 0, il = lines.length; i < il; ++i) {\n const start = lines[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextLines === undefined\n ? geometry.data.length // end of data (no next lines)\n : nextLines[0] // start of first line in nextLines\n : lines[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, lines, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param lines\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: MvtPolygons,\n areas: number,\n lines: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = lines[0];\n const holes = lines.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const indices = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = indices.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + indices[t]);\n }\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: MvtPoints,\n lines: MvtLines,\n polygons: MvtPolygons,\n coordLength: number\n) {\n const returnObj = {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1}\n },\n lines: {\n ...lines,\n pathIndices: {value: lines.pathIndices, size: 1},\n positions: {value: lines.positions, size: coordLength},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1}\n },\n polygons: {\n ...polygons,\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n positions: {value: polygons.positions, size: coordLength},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1}\n }\n };\n\n for (const geomType in returnObj) {\n for (const numericProp in returnObj[geomType].numericProps) {\n returnObj[geomType].numericProps[numericProp] = {\n value: returnObj[geomType].numericProps[numericProp],\n size: 1\n };\n }\n }\n return returnObj;\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: MvtPoints,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\nfunction isNumeric(x: unknown) {\n return Number.isFinite(x);\n}\n"],"file":"features-to-binary.js"}
1
+ {"version":3,"sources":["../../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":["earcut","featuresToBinary","features","firstPassData","options","propArrayTypes","extractNumericPropTypes","numericPropKeys","Object","keys","filter","k","Array","fillArrays","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","val","deduceArrayType","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","hasGlobalId","coordLength","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","TypedArray","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","type","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","start","end","l","ll","startPosition","areas","nextLines","undefined","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","indices","t","tl","returnObj","value","size","geomType","numericProp","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"mappings":"AACA,SAAQA,MAAR,QAAqB,kBAArB;AAyBA,OAAO,SAASC,gBAAT,CACLC,QADK,EAELC,aAFK,EAGLC,OAHK,EAIL;AACA,QAAMC,cAAc,GAAGC,uBAAuB,CAACJ,QAAD,CAA9C;AACA,QAAMK,eAAe,GAAGC,MAAM,CAACC,IAAP,CAAYJ,cAAZ,EAA4BK,MAA5B,CAAoCC,CAAD,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jC,EAAgG;AAC9F,MAAIA,WAAW,KAAKlG,KAAhB,IAAyB,CAACmG,MAAM,CAACC,QAAP,CAAgBH,CAAhB,CAA9B,EAAkD;AAChD,WAAOjG,KAAP;AACD;;AAGD,SAAOkG,WAAW,KAAKG,YAAhB,IAAgCC,IAAI,CAACC,MAAL,CAAYN,CAAZ,MAAmBA,CAAnD,GAAuDI,YAAvD,GAAsElG,YAA7E;AACD","sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport {\n MvtBinaryCoordinates,\n MvtBinaryGeometry,\n MvtBinaryOptions,\n MvtPropArrayConstructor,\n MvtFirstPassedData,\n MvtLines,\n MvtPoints,\n MvtPolygons\n} from '../types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns filled arrays\n */\nexport function featuresToBinary(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options?: MvtBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(features, firstPassData, {\n numericPropKeys: options ? options.numericPropKeys : numericPropKeys,\n propArrayTypes,\n PositionDataType: options ? options.PositionDataType : Float32Array\n });\n}\n\nexport const TEST_EXPORTS = {\n fillArrays\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: MvtBinaryCoordinates[]): {\n [key: string]: MvtPropArrayConstructor;\n} {\n const propArrayTypes = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, Array is stored to prevent rechecking in the future\n // Additionally, detects if 64 bit precision is required\n const val = feature.properties[key];\n propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);\n }\n }\n }\n\n return propArrayTypes;\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options: MvtBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n } = firstPassData;\n const {numericPropKeys, propArrayTypes, PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const coordLength = 2;\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: MvtPoints = {\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: MvtLines = {\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: MvtPolygons = {\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n const TypedArray = propArrayTypes[propName];\n object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n case 'MultiPoint':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n case 'MultiLineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n case 'MultiPolygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: MvtBinaryGeometry,\n points: MvtPoints,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: MvtBinaryGeometry,\n lines: MvtLines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.lines.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.lines[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.lines[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: MvtBinaryGeometry,\n polygons: MvtPolygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.lines is a 2D array\n for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas![l];\n const lines = geometry.lines[l];\n const nextLines = geometry.lines[l + 1];\n\n for (let i = 0, il = lines.length; i < il; ++i) {\n const start = lines[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextLines === undefined\n ? geometry.data.length // end of data (no next lines)\n : nextLines[0] // start of first line in nextLines\n : lines[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, lines, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param lines\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: MvtPolygons,\n areas: number,\n lines: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = lines[0];\n const holes = lines.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const indices = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = indices.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + indices[t]);\n }\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: MvtPoints,\n lines: MvtLines,\n polygons: MvtPolygons,\n coordLength: number\n) {\n const returnObj = {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1}\n },\n lines: {\n ...lines,\n pathIndices: {value: lines.pathIndices, size: 1},\n positions: {value: lines.positions, size: coordLength},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1}\n },\n polygons: {\n ...polygons,\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n positions: {value: polygons.positions, size: coordLength},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1}\n }\n };\n\n for (const geomType in returnObj) {\n for (const numericProp in returnObj[geomType].numericProps) {\n returnObj[geomType].numericProps[numericProp] = {\n value: returnObj[geomType].numericProps[numericProp],\n size: 1\n };\n }\n }\n return returnObj;\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: MvtPoints,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\nfunction deduceArrayType(x: any, constructor: MvtPropArrayConstructor): MvtPropArrayConstructor {\n if (constructor === Array || !Number.isFinite(x)) {\n return Array;\n }\n\n // If this or previous value required 64bits use Float64Array\n return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;\n}\n"],"file":"features-to-binary.js"}
@@ -1,5 +1,5 @@
1
1
  import parseMVT from './lib/parse-mvt';
2
- const VERSION = typeof "3.1.0-beta.2" !== 'undefined' ? "3.1.0-beta.2" : 'latest';
2
+ const VERSION = typeof "3.1.0" !== 'undefined' ? "3.1.0" : '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,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"}
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"}
@@ -88,16 +88,8 @@ export declare function featuresToBinary(features: MvtBinaryCoordinates[], first
88
88
  };
89
89
  };
90
90
  export declare const TEST_EXPORTS: {
91
- extractNumericPropKeys: typeof extractNumericPropKeys;
92
91
  fillArrays: typeof fillArrays;
93
92
  };
94
- /**
95
- * Extracts properties that are always numeric
96
- *
97
- * @param features
98
- * @returns object with numeric keys
99
- */
100
- declare function extractNumericPropKeys(features: MvtBinaryCoordinates[]): string[];
101
93
  /**
102
94
  * Fills coordinates into pre-allocated typed arrays
103
95
  *
@@ -1 +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"}
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,EAEhB,kBAAkB,EAInB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,CAAC,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAS3B;AAED,eAAO,MAAM,YAAY;;CAExB,CAAC;AA4BF;;;;;;;GAOG;AAEH,iBAAS,UAAU,CACjB,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqI1B"}
@@ -17,39 +17,39 @@ const polygon_1 = require("@math.gl/polygon");
17
17
  * @returns filled arrays
18
18
  */
19
19
  function featuresToBinary(features, firstPassData, options) {
20
+ const propArrayTypes = extractNumericPropTypes(features);
21
+ const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
20
22
  return fillArrays(features, firstPassData, {
21
- numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),
23
+ numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
24
+ propArrayTypes,
22
25
  PositionDataType: options ? options.PositionDataType : Float32Array
23
26
  });
24
27
  }
25
28
  exports.featuresToBinary = featuresToBinary;
26
29
  exports.TEST_EXPORTS = {
27
- extractNumericPropKeys,
28
30
  fillArrays
29
31
  };
30
32
  /**
31
33
  * Extracts properties that are always numeric
32
34
  *
33
35
  * @param features
34
- * @returns object with numeric keys
36
+ * @returns object with numeric types
35
37
  */
36
- function extractNumericPropKeys(features) {
37
- const numericPropKeys = {};
38
+ function extractNumericPropTypes(features) {
39
+ const propArrayTypes = {};
38
40
  for (const feature of features) {
39
41
  if (feature.properties) {
40
42
  for (const key in feature.properties) {
41
43
  // If property has not been seen before, or if property has been numeric
42
44
  // in all previous features, check if numeric in this feature
43
- // If not numeric, false is stored to prevent rechecking in the future
44
- const numericSoFar = numericPropKeys[key];
45
- if (numericSoFar || numericSoFar === undefined) {
46
- const val = feature.properties[key];
47
- numericPropKeys[key] = isNumeric(val);
48
- }
45
+ // If not numeric, Array is stored to prevent rechecking in the future
46
+ // Additionally, detects if 64 bit precision is required
47
+ const val = feature.properties[key];
48
+ propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
49
49
  }
50
50
  }
51
51
  }
52
- return Object.keys(numericPropKeys).filter((k) => numericPropKeys[k]);
52
+ return propArrayTypes;
53
53
  }
54
54
  /**
55
55
  * Fills coordinates into pre-allocated typed arrays
@@ -62,7 +62,7 @@ function extractNumericPropKeys(features) {
62
62
  // eslint-disable-next-line complexity
63
63
  function fillArrays(features, firstPassData, options) {
64
64
  const { pointPositionsCount, pointFeaturesCount, linePositionsCount, linePathsCount, lineFeaturesCount, polygonPositionsCount, polygonObjectsCount, polygonRingsCount, polygonFeaturesCount } = firstPassData;
65
- const { numericPropKeys, PositionDataType = Float32Array } = options;
65
+ const { numericPropKeys, propArrayTypes, PositionDataType = Float32Array } = options;
66
66
  const hasGlobalId = features[0] && 'id' in features[0];
67
67
  const coordLength = 2;
68
68
  const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
@@ -111,7 +111,8 @@ function fillArrays(features, firstPassData, options) {
111
111
  for (const propName of numericPropKeys) {
112
112
  // If property has been numeric in all previous features in which the property existed, check
113
113
  // if numeric in this feature
114
- object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
114
+ const TypedArray = propArrayTypes[propName];
115
+ object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
115
116
  }
116
117
  }
117
118
  // Set last element of path/polygon indices as positions length
@@ -348,6 +349,10 @@ function keepStringProperties(properties, numericKeys) {
348
349
  }
349
350
  return props;
350
351
  }
351
- function isNumeric(x) {
352
- return Number.isFinite(x);
352
+ function deduceArrayType(x, constructor) {
353
+ if (constructor === Array || !Number.isFinite(x)) {
354
+ return Array;
355
+ }
356
+ // If this or previous value required 64bits use Float64Array
357
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
353
358
  }