@loaders.gl/mvt 3.1.0 → 3.1.4

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 (49) hide show
  1. package/dist/bundle.js +5 -2281
  2. package/dist/dist.min.js +2289 -0
  3. package/dist/es5/helpers/binary-util-functions.js +8 -5
  4. package/dist/es5/helpers/binary-util-functions.js.map +1 -1
  5. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +33 -31
  6. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  7. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +2 -2
  8. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  9. package/dist/es5/lib/parse-mvt.js +6 -5
  10. package/dist/es5/lib/parse-mvt.js.map +1 -1
  11. package/dist/es5/mvt-loader.js +1 -1
  12. package/dist/esm/helpers/binary-util-functions.js +8 -5
  13. package/dist/esm/helpers/binary-util-functions.js.map +1 -1
  14. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +31 -30
  15. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  16. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +2 -2
  17. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  18. package/dist/esm/lib/parse-mvt.js +6 -5
  19. package/dist/esm/lib/parse-mvt.js.map +1 -1
  20. package/dist/esm/mvt-loader.js +1 -1
  21. package/dist/helpers/binary-util-functions.d.ts +2 -6
  22. package/dist/helpers/binary-util-functions.d.ts.map +1 -1
  23. package/dist/helpers/binary-util-functions.js +7 -5
  24. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +12 -7
  25. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  26. package/dist/lib/binary-vector-tile/vector-tile-feature.js +32 -39
  27. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +3 -3
  28. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
  29. package/dist/lib/binary-vector-tile/vector-tile-layer.js +3 -3
  30. package/dist/lib/parse-mvt.d.ts +8 -76
  31. package/dist/lib/parse-mvt.d.ts.map +1 -1
  32. package/dist/lib/parse-mvt.js +6 -5
  33. package/dist/lib/types.d.ts +0 -68
  34. package/dist/lib/types.d.ts.map +1 -1
  35. package/dist/mvt-worker.js +90 -89
  36. package/package.json +7 -6
  37. package/src/helpers/binary-util-functions.ts +9 -7
  38. package/src/lib/binary-vector-tile/vector-tile-feature.ts +36 -44
  39. package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
  40. package/src/lib/parse-mvt.ts +10 -8
  41. package/src/lib/types.ts +0 -75
  42. package/dist/es5/lib/binary-vector-tile/features-to-binary.js +0 -389
  43. package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  44. package/dist/esm/lib/binary-vector-tile/features-to-binary.js +0 -331
  45. package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  46. package/dist/lib/binary-vector-tile/features-to-binary.d.ts +0 -177
  47. package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +0 -1
  48. package/dist/lib/binary-vector-tile/features-to-binary.js +0 -358
  49. package/src/lib/binary-vector-tile/features-to-binary.ts +0 -527
@@ -11,11 +11,7 @@ export const TEST_EXPORTS = {
11
11
  classifyRings
12
12
  };
13
13
  export default class VectorTileFeature {
14
- static get types() {
15
- return ['Unknown', 'Point', 'LineString', 'Polygon'];
16
- }
17
-
18
- constructor(pbf, end, extent, keys, values, firstPassData) {
14
+ constructor(pbf, end, extent, keys, values, geometryInfo) {
19
15
  _defineProperty(this, "properties", void 0);
20
16
 
21
17
  _defineProperty(this, "extent", void 0);
@@ -32,7 +28,7 @@ export default class VectorTileFeature {
32
28
 
33
29
  _defineProperty(this, "_values", void 0);
34
30
 
35
- _defineProperty(this, "_firstPassData", void 0);
31
+ _defineProperty(this, "_geometryInfo", void 0);
36
32
 
37
33
  this.properties = {};
38
34
  this.extent = extent;
@@ -42,7 +38,7 @@ export default class VectorTileFeature {
42
38
  this._geometry = -1;
43
39
  this._keys = keys;
44
40
  this._values = values;
45
- this._firstPassData = firstPassData;
41
+ this._geometryInfo = geometryInfo;
46
42
  pbf.readFields(readFeature, this, end);
47
43
  }
48
44
 
@@ -55,7 +51,7 @@ export default class VectorTileFeature {
55
51
  x = 0;
56
52
  y = 0;
57
53
  i = 0;
58
- const lines = [];
54
+ const indices = [];
59
55
  const data = [];
60
56
 
61
57
  while (pbf.pos < endPos) {
@@ -72,14 +68,14 @@ export default class VectorTileFeature {
72
68
  y += pbf.readSVarint();
73
69
 
74
70
  if (cmd === 1) {
75
- lines.push(i);
71
+ indices.push(i);
76
72
  }
77
73
 
78
74
  data.push(x, y);
79
75
  i += 2;
80
76
  } else if (cmd === 7) {
81
77
  if (i > 0) {
82
- const start = lines[lines.length - 1];
78
+ const start = indices[indices.length - 1];
83
79
  data.push(data[start], data[start + 1]);
84
80
  i += 2;
85
81
  }
@@ -90,50 +86,55 @@ export default class VectorTileFeature {
90
86
 
91
87
  return {
92
88
  data,
93
- lines
89
+ indices
94
90
  };
95
91
  }
96
92
 
97
93
  _toBinaryCoordinates(transform) {
98
- let geom = this.loadGeometry();
94
+ const geom = this.loadGeometry();
95
+ let geometry;
99
96
  transform(geom.data, this);
100
97
  const coordLength = 2;
101
98
 
102
99
  switch (this.type) {
103
100
  case 1:
104
- this._firstPassData.pointFeaturesCount++;
105
- this._firstPassData.pointPositionsCount += geom.lines.length;
101
+ this._geometryInfo.pointFeaturesCount++;
102
+ this._geometryInfo.pointPositionsCount += geom.indices.length;
103
+ geometry = {
104
+ type: 'Point',
105
+ ...geom
106
+ };
106
107
  break;
107
108
 
108
109
  case 2:
109
- this._firstPassData.lineFeaturesCount++;
110
- this._firstPassData.linePathsCount += geom.lines.length;
111
- this._firstPassData.linePositionsCount += geom.data.length / coordLength;
110
+ this._geometryInfo.lineFeaturesCount++;
111
+ this._geometryInfo.linePathsCount += geom.indices.length;
112
+ this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
113
+ geometry = {
114
+ type: 'LineString',
115
+ ...geom
116
+ };
112
117
  break;
113
118
 
114
119
  case 3:
115
- const classified = classifyRings(geom);
116
- this._firstPassData.polygonFeaturesCount++;
117
- this._firstPassData.polygonObjectsCount += classified.lines.length;
120
+ geometry = classifyRings(geom);
121
+ this._geometryInfo.polygonFeaturesCount++;
122
+ this._geometryInfo.polygonObjectsCount += geometry.indices.length;
118
123
 
119
- for (const lines of classified.lines) {
120
- this._firstPassData.polygonRingsCount += lines.length;
124
+ for (const indices of geometry.indices) {
125
+ this._geometryInfo.polygonRingsCount += indices.length;
121
126
  }
122
127
 
123
- this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;
124
- geom = classified;
128
+ this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
125
129
  break;
126
- }
127
-
128
- geom.type = VectorTileFeature.types[this.type];
129
130
 
130
- if (geom.lines.length > 1) {
131
- geom.type = "Multi".concat(geom.type);
131
+ default:
132
+ throw new Error("Invalid geometry type: ".concat(this.type));
132
133
  }
133
134
 
134
135
  const result = {
135
136
  type: 'Feature',
136
- geometry: geom,
137
+ geometry,
137
138
  properties: this.properties
138
139
  };
139
140
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":["classifyRings","project","readFeature","endPos","cmd","cmdLen","length","x","y","i","TEST_EXPORTS","VectorTileFeature","types","constructor","pbf","end","extent","keys","values","firstPassData","properties","type","id","_pbf","_geometry","_keys","_values","_firstPassData","readFields","loadGeometry","pos","readVarint","lines","data","readSVarint","push","start","Error","_toBinaryCoordinates","transform","geom","coordLength","pointFeaturesCount","pointPositionsCount","lineFeaturesCount","linePathsCount","linePositionsCount","classified","polygonFeaturesCount","polygonObjectsCount","polygonRingsCount","polygonPositionsCount","result","geometry","toBinaryCoordinates","options"],"mappings":";AAIA,SAAQA,aAAR,EAAuBC,OAAv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D;;AAED,UAAM+B,MAA4B,GAAG;AACnC/B,MAAAA,IAAI,EAAE,SAD6B;AAEnCgC,MAAAA,QAAQ,EAAEb,IAFyB;AAGnCpB,MAAAA,UAAU,EAAE,KAAKA;AAHkB,KAArC;;AAMA,QAAI,KAAKE,EAAL,KAAY,IAAhB,EAAsB;AACpB8B,MAAAA,MAAM,CAAC9B,EAAP,GAAY,KAAKA,EAAjB;AACD;;AAED,WAAO8B,MAAP;AACD;;AAEDE,EAAAA,mBAAmB,CACjBC,OADiB,EAEK;AACtB,QAAI,OAAOA,OAAP,KAAmB,UAAvB,EAAmC;AACjC,aAAO,KAAKjB,oBAAL,CAA0BiB,OAA1B,CAAP;AACD;;AACD,WAAO,KAAKjB,oBAAL,CAA0BrC,OAA1B,CAAP;AACD;;AArLoC","sourcesContent":["// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport Protobuf from 'pbf';\nimport {MvtBinaryCoordinates, MvtBinaryGeometry, MvtFirstPassedData} from '../types';\nimport {classifyRings, project, readFeature} from '../../helpers/binary-util-functions';\n\n// Reduce GC by reusing variables\nlet endPos: number;\nlet cmd: number;\nlet cmdLen: number;\nlet length: number;\nlet x: number;\nlet y: number;\nlet i: number;\n\nexport const TEST_EXPORTS = {\n classifyRings\n};\n\nexport default class VectorTileFeature {\n properties: {[x: string]: string | number | boolean | null};\n extent: any;\n type: number;\n id: number | null;\n _pbf: Protobuf;\n _geometry: number;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n _firstPassData: MvtFirstPassedData;\n static get types() {\n return ['Unknown', 'Point', 'LineString', 'Polygon'];\n }\n\n // eslint-disable-next-line max-params\n constructor(\n pbf: Protobuf,\n end: number,\n extent: any,\n keys: string[],\n values: (string | number | boolean | null)[],\n firstPassData: MvtFirstPassedData\n ) {\n // Public\n this.properties = {};\n this.extent = extent;\n this.type = 0;\n this.id = null;\n\n // Private\n this._pbf = pbf;\n this._geometry = -1;\n this._keys = keys;\n this._values = values;\n this._firstPassData = firstPassData;\n\n pbf.readFields(readFeature, this, end);\n }\n\n // eslint-disable-next-line complexity, max-statements\n loadGeometry(): MvtBinaryGeometry {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n endPos = pbf.readVarint() + pbf.pos;\n cmd = 1;\n length = 0;\n x = 0;\n y = 0;\n i = 0;\n\n // Note: I attempted to replace the `data` array with a\n // Float32Array, but performance was worse, both using\n // `set()` and direct index access. Also, we cannot\n // know how large the buffer should be, so it would\n // increase memory usage\n const lines: number[] = []; // Indices where lines start\n const data: number[] = []; // Flat array of coordinate data\n\n while (pbf.pos < endPos) {\n if (length <= 0) {\n cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n\n if (cmd === 1) {\n // New line\n lines.push(i);\n }\n data.push(x, y);\n i += 2;\n } else if (cmd === 7) {\n // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90\n if (i > 0) {\n const start = lines[lines.length - 1]; // start index of polygon\n data.push(data[start], data[start + 1]); // closePolygon\n i += 2;\n }\n } else {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n return {data, lines};\n }\n\n /**\n *\n * @param transform\n * @returns result\n */\n _toBinaryCoordinates(transform) {\n // Expands the protobuf data to an intermediate `lines`\n // data format, which maps closely to the binary data buffers.\n // It is similar to GeoJSON, but rather than storing the coordinates\n // in multidimensional arrays, we have a 1D `data` with all the\n // coordinates, and then index into this using the `lines`\n // parameter, e.g.\n //\n // geometry: {\n // type: 'Point', data: [1,2], lines: [0]\n // }\n // geometry: {\n // type: 'LineString', data: [1,2,3,4,...], lines: [0]\n // }\n // geometry: {\n // type: 'Polygon', data: [1,2,3,4,...], lines: [[0, 2]]\n // }\n // Thus the lines member lets us look up the relevant range\n // from the data array.\n // The Multi* versions of the above types share the same data\n // structure, just with multiple elements in the lines array\n let geom = this.loadGeometry();\n\n // Apply the supplied transformation to data\n transform(geom.data, this);\n\n const coordLength = 2;\n\n // eslint-disable-next-line default-case\n switch (this.type) {\n case 1: // Point\n this._firstPassData.pointFeaturesCount++;\n this._firstPassData.pointPositionsCount += geom.lines.length;\n break;\n\n case 2: // LineString\n this._firstPassData.lineFeaturesCount++;\n this._firstPassData.linePathsCount += geom.lines.length;\n this._firstPassData.linePositionsCount += geom.data.length / coordLength;\n break;\n\n case 3: // Polygon\n const classified = classifyRings(geom);\n\n // Unlike Point & LineString geom.lines is a 2D array, thanks\n // to the classifyRings method\n this._firstPassData.polygonFeaturesCount++;\n this._firstPassData.polygonObjectsCount += classified.lines.length;\n\n for (const lines of classified.lines) {\n this._firstPassData.polygonRingsCount += lines.length;\n }\n this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;\n\n geom = classified;\n break;\n }\n\n geom.type = VectorTileFeature.types[this.type];\n if (geom.lines.length > 1) {\n geom.type = `Multi${geom.type}`;\n }\n\n const result: MvtBinaryCoordinates = {\n type: 'Feature',\n geometry: geom,\n properties: this.properties\n };\n\n if (this.id !== null) {\n result.id = this.id;\n }\n\n return result;\n }\n\n toBinaryCoordinates(\n options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)\n ): MvtBinaryCoordinates {\n if (typeof options === 'function') {\n return this._toBinaryCoordinates(options);\n }\n return this._toBinaryCoordinates(project);\n }\n}\n"],"file":"vector-tile-feature.js"}
1
+ {"version":3,"sources":["../../../../src/lib/binary-vector-tile/vector-tile-feature.ts"],"names":["classifyRings","project","readFeature","endPos","cmd","cmdLen","length","x","y","i","TEST_EXPORTS","VectorTileFeature","constructor","pbf","end","extent","keys","values","geometryInfo","properties","type","id","_pbf","_geometry","_keys","_values","_geometryInfo","readFields","loadGeometry","pos","readVarint","indices","data","readSVarint","push","start","Error","_toBinaryCoordinates","transform","geom","geometry","coordLength","pointFeaturesCount","pointPositionsCount","lineFeaturesCount","linePathsCount","linePositionsCount","polygonFeaturesCount","polygonObjectsCount","polygonR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mB,GAAG;AAAC/B,MAAAA,IAAI,EAAE,SAAP;AAAkBoB,MAAAA,QAAlB;AAA4BrB,MAAAA,UAAU,EAAE,KAAKA;AAA7C,KAA5B;;AAEA,QAAI,KAAKE,EAAL,KAAY,IAAhB,EAAsB;AACpB8B,MAAAA,MAAM,CAAC9B,EAAP,GAAY,KAAKA,EAAjB;AACD;;AAED,WAAO8B,MAAP;AACD;;AAEDC,EAAAA,mBAAmB,CACjBC,OADiB,EAEJ;AACb,QAAI,OAAOA,OAAP,KAAmB,UAAvB,EAAmC;AACjC,aAAO,KAAKhB,oBAAL,CAA0BgB,OAA1B,CAAP;AACD;;AACD,WAAO,KAAKhB,oBAAL,CAA0BpC,OAA1B,CAAP;AACD;;AA7KoC","sourcesContent":["// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.\n\nimport Protobuf from 'pbf';\nimport {FlatFeature, FlatIndexedGeometry, GeojsonGeometryInfo} from '@loaders.gl/schema';\nimport {classifyRings, project, readFeature} from '../../helpers/binary-util-functions';\n\n// Reduce GC by reusing variables\nlet endPos: number;\nlet cmd: number;\nlet cmdLen: number;\nlet length: number;\nlet x: number;\nlet y: number;\nlet i: number;\n\nexport const TEST_EXPORTS = {\n classifyRings\n};\n\nexport default class VectorTileFeature {\n properties: {[x: string]: string | number | boolean | null};\n extent: any;\n type: number;\n id: number | null;\n _pbf: Protobuf;\n _geometry: number;\n _keys: string[];\n _values: (string | number | boolean | null)[];\n _geometryInfo: GeojsonGeometryInfo;\n\n // eslint-disable-next-line max-params\n constructor(\n pbf: Protobuf,\n end: number,\n extent: any,\n keys: string[],\n values: (string | number | boolean | null)[],\n geometryInfo: GeojsonGeometryInfo\n ) {\n // Public\n this.properties = {};\n this.extent = extent;\n this.type = 0;\n this.id = null;\n\n // Private\n this._pbf = pbf;\n this._geometry = -1;\n this._keys = keys;\n this._values = values;\n this._geometryInfo = geometryInfo;\n\n pbf.readFields(readFeature, this, end);\n }\n\n // eslint-disable-next-line complexity, max-statements\n loadGeometry(): FlatIndexedGeometry {\n const pbf = this._pbf;\n pbf.pos = this._geometry;\n\n endPos = pbf.readVarint() + pbf.pos;\n cmd = 1;\n length = 0;\n x = 0;\n y = 0;\n i = 0;\n\n // Note: I attempted to replace the `data` array with a\n // Float32Array, but performance was worse, both using\n // `set()` and direct index access. Also, we cannot\n // know how large the buffer should be, so it would\n // increase memory usage\n const indices: number[] = []; // Indices where geometries start\n const data: number[] = []; // Flat array of coordinate data\n\n while (pbf.pos < endPos) {\n if (length <= 0) {\n cmdLen = pbf.readVarint();\n cmd = cmdLen & 0x7;\n length = cmdLen >> 3;\n }\n\n length--;\n\n if (cmd === 1 || cmd === 2) {\n x += pbf.readSVarint();\n y += pbf.readSVarint();\n\n if (cmd === 1) {\n // New line\n indices.push(i);\n }\n data.push(x, y);\n i += 2;\n } else if (cmd === 7) {\n // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90\n if (i > 0) {\n const start = indices[indices.length - 1]; // start index of polygon\n data.push(data[start], data[start + 1]); // closePolygon\n i += 2;\n }\n } else {\n throw new Error(`unknown command ${cmd}`);\n }\n }\n\n return {data, indices};\n }\n\n /**\n *\n * @param transform\n * @returns result\n */\n _toBinaryCoordinates(transform) {\n // Expands the protobuf data to an intermediate Flat GeoJSON\n // data format, which maps closely to the binary data buffers.\n // It is similar to GeoJSON, but rather than storing the coordinates\n // in multidimensional arrays, we have a 1D `data` with all the\n // coordinates, and then index into this using the `indices`\n // parameter, e.g.\n //\n // geometry: {\n // type: 'Point', data: [1,2], indices: [0]\n // }\n // geometry: {\n // type: 'LineString', data: [1,2,3,4,...], indices: [0]\n // }\n // geometry: {\n // type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]\n // }\n // Thus the indices member lets us look up the relevant range\n // from the data array.\n // The Multi* versions of the above types share the same data\n // structure, just with multiple elements in the indices array\n const geom = this.loadGeometry();\n let geometry;\n\n // Apply the supplied transformation to data\n transform(geom.data, this);\n\n const coordLength = 2;\n\n // eslint-disable-next-line default-case\n switch (this.type) {\n case 1: // Point\n this._geometryInfo.pointFeaturesCount++;\n this._geometryInfo.pointPositionsCount += geom.indices.length;\n geometry = {type: 'Point', ...geom};\n break;\n\n case 2: // LineString\n this._geometryInfo.lineFeaturesCount++;\n this._geometryInfo.linePathsCount += geom.indices.length;\n this._geometryInfo.linePositionsCount += geom.data.length / coordLength;\n geometry = {type: 'LineString', ...geom};\n break;\n\n case 3: // Polygon\n geometry = classifyRings(geom);\n\n // Unlike Point & LineString geom.indices is a 2D array, thanks\n // to the classifyRings method\n this._geometryInfo.polygonFeaturesCount++;\n this._geometryInfo.polygonObjectsCount += geometry.indices.length;\n\n for (const indices of geometry.indices) {\n this._geometryInfo.polygonRingsCount += indices.length;\n }\n this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;\n\n break;\n default:\n throw new Error(`Invalid geometry type: ${this.type}`);\n }\n\n const result: FlatFeature = {type: 'Feature', geometry, properties: this.properties};\n\n if (this.id !== null) {\n result.id = this.id;\n }\n\n return result;\n }\n\n toBinaryCoordinates(\n options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)\n ): FlatFeature {\n if (typeof options === 'function') {\n return this._toBinaryCoordinates(options);\n }\n return this._toBinaryCoordinates(project);\n }\n}\n"],"file":"vector-tile-feature.js"}
@@ -30,7 +30,7 @@ export default class VectorTileLayer {
30
30
  this.length = this._features.length;
31
31
  }
32
32
 
33
- feature(i, firstPassData) {
33
+ feature(i, geometryInfo) {
34
34
  if (i < 0 || i >= this._features.length) {
35
35
  throw new Error('feature index out of bounds');
36
36
  }
@@ -39,7 +39,7 @@ export default class VectorTileLayer {
39
39
 
40
40
  const end = this._pbf.readVarint() + this._pbf.pos;
41
41
 
42
- return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, firstPassData);
42
+ return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
43
43
  }
44
44
 
45
45
  }
@@ -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","firstPassData","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,aAAZ,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,CAAf,CAAhB;;AAEA,UAAMZ,GAAG,GAAG,KAAKK,IAAL,CAAUW,UAAV,KAAyB,KAAKX,IAAL,CAAUU,GAA/C;;AACA,WAAO,IAAInB,iBAAJ,CACL,KAAKS,IADA,EAELL,GAFK,EAGL,KAAKG,MAHA,EAIL,KAAKG,KAJA,EAKL,K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AAK,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 {MvtFirstPassedData} from '../types';\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 firstPassData\n * @returns {VectorTileFeature}\n */\n feature(i: number, firstPassData: MvtFirstPassedData): 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 firstPassData\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
+ {"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;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EAAeC,KAAK,CAACX,OAAN,CAAca,IAAd,CAAmBC,gBAAgB,CAACtB,GAAD,CAAnC;AACrB;AACF;;AAOD,SAASsB,gBAAT,CAA0BtB,GAA1B,EAAyC;AACvC,MAAIuB,KAAuC,GAAG,IAA9C;AACA,QAAMtB,GAAG,GAAGD,GAAG,CAACiB,UAAJ,KAAmBjB,GAAG,CAACgB,GAAnC;;AAEA,SAAOhB,GAAG,CAACgB,GAAJ,GAAUf,GAAjB,EAAsB;AACpB,UAAMiB,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 { featuresToBinary } from './binary-vector-tile/features-to-binary';
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 firstPassData = {
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, firstPassData);
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 = featuresToBinary(features, firstPassData);
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,CAA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;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 {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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CAAvB;;AAKA,MAAIvD,OAAO,CAACoD,aAAR,IAAyBjB,cAAc,CAACkB,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"}
@@ -1,5 +1,5 @@
1
1
  import parseMVT from './lib/parse-mvt';
2
- const VERSION = typeof "3.1.0" !== 'undefined' ? "3.1.0" : 'latest';
2
+ const VERSION = typeof "3.1.4" !== 'undefined' ? "3.1.4" : 'latest';
3
3
  export const MVTWorkerLoader = {
4
4
  name: 'Mapbox Vector Tile',
5
5
  id: 'mvt',
@@ -1,5 +1,5 @@
1
1
  import Protobuf from 'pbf';
2
- import { MvtBinaryGeometry } from '../lib/types';
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: MvtBinaryGeometry): {
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,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAC/C,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAE9E;;;;;;;;GAQG;AAEH,wBAAgB,aAAa,CAAC,IAAI,EAAE,iBAAiB;;;;EA0DpD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAMlF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAO1F;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAQvE"}
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.lines.length;
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
- lines: [geom.lines]
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.lines[i] - offset;
32
- endIndex = geom.lines[i + 1] - offset || geom.data.length;
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, lines: polygons, data: geom.data };
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 { MvtBinaryCoordinates, MvtBinaryGeometry, MvtFirstPassedData } from '../types';
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
- _firstPassData: MvtFirstPassedData;
19
- static get types(): string[];
20
- constructor(pbf: Protobuf, end: number, extent: any, keys: string[], values: (string | number | boolean | null)[], firstPassData: MvtFirstPassedData);
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): MvtBinaryCoordinates;
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)): MvtBinaryCoordinates;
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,oBAAoB,EAAE,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,UAAU,CAAC;AACrF,OAAO,EAAC,aAAa,EAAuB,MAAM,qCAAqC,CAAC;AAWxF,eAAO,MAAM,YAAY;;CAExB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,cAAc,EAAE,kBAAkB,CAAC;IACnC,MAAM,KAAK,KAAK,a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AE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,aAAa,EAAE,mBAAmB,CAAC;gBAIjC,GAAG,EAAE,QAAQ,EACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,EAC5C,YAAY,EAAE,mBAAmB;IAmBnC,YAAY,IAAI,mBAAmB;IAqDnC;;;;OAIG;IACH,oBAAoB,CAAC,SAAS,KAAA;;;;;;;IAuE9B,mBAAmB,CACjB,OAAO,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,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, firstPassData) {
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._firstPassData = firstPassData;
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 lines = []; // Indices where lines start
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
- lines.push(i);
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 = lines[lines.length - 1]; // start index of polygon
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, lines };
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 `lines`
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 `lines`
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], lines: [0]
95
+ // type: 'Point', data: [1,2], indices: [0]
99
96
  // }
100
97
  // geometry: {
101
- // type: 'LineString', data: [1,2,3,4,...], lines: [0]
98
+ // type: 'LineString', data: [1,2,3,4,...], indices: [0]
102
99
  // }
103
100
  // geometry: {
104
- // type: 'Polygon', data: [1,2,3,4,...], lines: [[0, 2]]
101
+ // type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
105
102
  // }
106
- // Thus the lines member lets us look up the relevant range
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 lines array
110
- let geom = this.loadGeometry();
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._firstPassData.pointFeaturesCount++;
118
- this._firstPassData.pointPositionsCount += geom.lines.length;
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._firstPassData.lineFeaturesCount++;
122
- this._firstPassData.linePathsCount += geom.lines.length;
123
- this._firstPassData.linePositionsCount += geom.data.length / coordLength;
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
- const classified = (0, binary_util_functions_1.classifyRings)(geom);
127
- // Unlike Point & LineString geom.lines is a 2D array, thanks
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._firstPassData.polygonFeaturesCount++;
130
- this._firstPassData.polygonObjectsCount += classified.lines.length;
131
- for (const lines of classified.lines) {
132
- this._firstPassData.polygonRingsCount += lines.length;
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._firstPassData.polygonPositionsCount += classified.data.length / coordLength;
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
- geom.type = VectorTileFeature.types[this.type];
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 { MvtFirstPassedData } from '../types';
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 firstPassData
18
+ * @param geometryInfo
19
19
  * @returns {VectorTileFeature}
20
20
  */
21
- feature(i: number, firstPassData: MvtFirstPassedData): VectorTileFeature;
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,kBAAkB,EAAC,MAAM,UAAU,CAAC;AAE5C,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CA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