@loaders.gl/mvt 3.1.0-alpha.4 → 3.1.0-beta.3

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 (83) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2277 -0
  4. package/dist/es5/bundle.js +1 -1
  5. package/dist/es5/bundle.js.map +1 -1
  6. package/dist/es5/helpers/binary-util-functions.js +18 -18
  7. package/dist/es5/helpers/binary-util-functions.js.map +1 -1
  8. package/dist/es5/helpers/mapbox-util-functions.js +11 -11
  9. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -1
  10. package/dist/es5/index.js +2 -2
  11. package/dist/es5/lib/binary-vector-tile/features-to-binary.js +130 -177
  12. package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +1 -1
  13. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +104 -131
  14. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  15. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +15 -23
  16. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  17. package/dist/es5/lib/binary-vector-tile/vector-tile.js +8 -8
  18. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -1
  19. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +147 -157
  20. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
  21. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +15 -23
  22. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -1
  23. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +8 -8
  24. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -1
  25. package/dist/es5/lib/parse-mvt.js +33 -35
  26. package/dist/es5/lib/parse-mvt.js.map +1 -1
  27. package/dist/es5/mvt-loader.js +5 -38
  28. package/dist/es5/mvt-loader.js.map +1 -1
  29. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +2 -2
  30. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  31. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +3 -3
  32. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
  33. package/dist/esm/lib/parse-mvt.js.map +1 -1
  34. package/dist/esm/mvt-loader.js +1 -1
  35. package/dist/esm/mvt-loader.js.map +1 -1
  36. package/dist/helpers/binary-util-functions.d.ts +39 -0
  37. package/dist/helpers/binary-util-functions.d.ts.map +1 -0
  38. package/dist/helpers/binary-util-functions.js +116 -0
  39. package/dist/helpers/mapbox-util-functions.d.ts +29 -0
  40. package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
  41. package/dist/helpers/mapbox-util-functions.js +82 -0
  42. package/dist/index.d.ts +2 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +6 -0
  45. package/dist/lib/binary-vector-tile/features-to-binary.d.ts +185 -0
  46. package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +1 -0
  47. package/dist/lib/binary-vector-tile/features-to-binary.js +353 -0
  48. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +36 -0
  49. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
  50. package/dist/lib/binary-vector-tile/vector-tile-feature.js +159 -0
  51. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
  52. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
  53. package/dist/lib/binary-vector-tile/vector-tile-layer.js +91 -0
  54. package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
  55. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
  56. package/dist/lib/binary-vector-tile/vector-tile.js +29 -0
  57. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +27 -0
  58. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
  59. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +170 -0
  60. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
  61. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
  62. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +89 -0
  63. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
  64. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
  65. package/dist/lib/mapbox-vector-tile/vector-tile.js +29 -0
  66. package/dist/lib/parse-mvt.d.ts +85 -0
  67. package/dist/lib/parse-mvt.d.ts.map +1 -0
  68. package/dist/lib/parse-mvt.js +142 -0
  69. package/dist/lib/types.d.ts +92 -0
  70. package/dist/lib/types.d.ts.map +1 -0
  71. package/dist/lib/types.js +2 -0
  72. package/dist/mvt-loader.d.ts +10 -0
  73. package/dist/mvt-loader.d.ts.map +1 -0
  74. package/dist/mvt-loader.js +45 -0
  75. package/dist/mvt-worker.js +2286 -3
  76. package/dist/workers/mvt-worker.d.ts +2 -0
  77. package/dist/workers/mvt-worker.d.ts.map +1 -0
  78. package/dist/workers/mvt-worker.js +5 -0
  79. package/package.json +7 -7
  80. package/src/lib/parse-mvt.ts +1 -1
  81. package/dist/dist.min.js +0 -4
  82. package/dist/dist.min.js.map +0 -1
  83. package/dist/mvt-worker.js.map +0 -1
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const vector_tile_layer_1 = __importDefault(require("./vector-tile-layer"));
8
+ class VectorTile {
9
+ constructor(pbf, end) {
10
+ this.layers = pbf.readFields(readTile, {}, end);
11
+ }
12
+ }
13
+ exports.default = VectorTile;
14
+ /**
15
+ *
16
+ * @param tag
17
+ * @param layers
18
+ * @param pbf
19
+ */
20
+ function readTile(tag, layers, pbf) {
21
+ if (tag === 3) {
22
+ if (pbf) {
23
+ const layer = new vector_tile_layer_1.default(pbf, pbf.readVarint() + pbf.pos);
24
+ if (layer.length && layers) {
25
+ layers[layer.name] = layer;
26
+ }
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,27 @@
1
+ import Protobuf from 'pbf';
2
+ import { MvtMapboxCoordinates, MvtMapboxGeometry } from '../types';
3
+ export default class VectorTileFeature {
4
+ properties: {
5
+ [x: string]: string | number | boolean | null;
6
+ };
7
+ extent: any;
8
+ type: number;
9
+ id: number | null;
10
+ _pbf: Protobuf;
11
+ _geometry: number;
12
+ _keys: string[];
13
+ _values: (string | number | boolean | null)[];
14
+ static get types(): string[];
15
+ constructor(pbf: Protobuf, end: number, extent: any, keys: string[], values: (string | number | boolean | null)[]);
16
+ loadGeometry(): MvtMapboxGeometry;
17
+ bbox(): number[];
18
+ _toGeoJSON(transform: any): MvtMapboxCoordinates;
19
+ toGeoJSON(options: {
20
+ x: number;
21
+ y: number;
22
+ z: number;
23
+ } | ((data: number[], feature: {
24
+ extent: any;
25
+ }) => void)): MvtMapboxCoordinates;
26
+ }
27
+ //# sourceMappingURL=vector-tile-feature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector-tile-feature.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile-feature.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,UAAU,CAAC;AAGjE,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,MAAM,KAAK,KAAK,aAEf;gBAGC,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;IAkB9C,YAAY,IAAI,iBAAiB;IA+CjC,IAAI;IAsCJ,UAAU,CAAC,SAAS,KAAA;IAuDpB,SAAS,CACP,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,oBAAoB;CAmBxB"}
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mapbox_util_functions_1 = require("../../helpers/mapbox-util-functions");
4
+ class VectorTileFeature {
5
+ constructor(pbf, end, extent, keys, values) {
6
+ // Public
7
+ this.properties = {};
8
+ this.extent = extent;
9
+ this.type = 0;
10
+ this.id = null;
11
+ // Private
12
+ this._pbf = pbf;
13
+ this._geometry = -1;
14
+ this._keys = keys;
15
+ this._values = values;
16
+ pbf.readFields(mapbox_util_functions_1.readFeature, this, end);
17
+ }
18
+ static get types() {
19
+ return ['Unknown', 'Point', 'LineString', 'Polygon'];
20
+ }
21
+ // eslint-disable-next-line complexity, max-statements
22
+ loadGeometry() {
23
+ const pbf = this._pbf;
24
+ pbf.pos = this._geometry;
25
+ const end = pbf.readVarint() + pbf.pos;
26
+ let cmd = 1;
27
+ let length = 0;
28
+ let x = 0;
29
+ let y = 0;
30
+ const lines = [];
31
+ let line;
32
+ while (pbf.pos < end) {
33
+ if (length <= 0) {
34
+ const cmdLen = pbf.readVarint();
35
+ cmd = cmdLen & 0x7;
36
+ length = cmdLen >> 3;
37
+ }
38
+ length--;
39
+ if (cmd === 1 || cmd === 2) {
40
+ x += pbf.readSVarint();
41
+ y += pbf.readSVarint();
42
+ if (cmd === 1) {
43
+ // moveTo
44
+ if (line)
45
+ lines.push(line);
46
+ line = [];
47
+ }
48
+ if (line)
49
+ line.push([x, y]);
50
+ }
51
+ else if (cmd === 7) {
52
+ // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
53
+ if (line) {
54
+ line.push(line[0].slice()); // closePolygon
55
+ }
56
+ }
57
+ else {
58
+ throw new Error(`unknown command ${cmd}`);
59
+ }
60
+ }
61
+ if (line)
62
+ lines.push(line);
63
+ return lines;
64
+ }
65
+ // eslint-disable-next-line max-statements
66
+ bbox() {
67
+ const pbf = this._pbf;
68
+ pbf.pos = this._geometry;
69
+ const end = pbf.readVarint() + pbf.pos;
70
+ let cmd = 1;
71
+ let length = 0;
72
+ let x = 0;
73
+ let y = 0;
74
+ let x1 = Infinity;
75
+ let x2 = -Infinity;
76
+ let y1 = Infinity;
77
+ let y2 = -Infinity;
78
+ while (pbf.pos < end) {
79
+ if (length <= 0) {
80
+ const cmdLen = pbf.readVarint();
81
+ cmd = cmdLen & 0x7;
82
+ length = cmdLen >> 3;
83
+ }
84
+ length--;
85
+ if (cmd === 1 || cmd === 2) {
86
+ x += pbf.readSVarint();
87
+ y += pbf.readSVarint();
88
+ if (x < x1)
89
+ x1 = x;
90
+ if (x > x2)
91
+ x2 = x;
92
+ if (y < y1)
93
+ y1 = y;
94
+ if (y > y2)
95
+ y2 = y;
96
+ }
97
+ else if (cmd !== 7) {
98
+ throw new Error(`unknown command ${cmd}`);
99
+ }
100
+ }
101
+ return [x1, y1, x2, y2];
102
+ }
103
+ _toGeoJSON(transform) {
104
+ let coords = this.loadGeometry();
105
+ let type = VectorTileFeature.types[this.type];
106
+ let i;
107
+ let j;
108
+ // eslint-disable-next-line default-case
109
+ switch (this.type) {
110
+ case 1:
111
+ const points = [];
112
+ for (i = 0; i < coords.length; i++) {
113
+ points[i] = coords[i][0];
114
+ }
115
+ coords = points;
116
+ transform(coords, this);
117
+ break;
118
+ case 2:
119
+ for (i = 0; i < coords.length; i++) {
120
+ transform(coords[i], this);
121
+ }
122
+ break;
123
+ case 3:
124
+ coords = (0, mapbox_util_functions_1.classifyRings)(coords);
125
+ for (i = 0; i < coords.length; i++) {
126
+ for (j = 0; j < coords[i].length; j++) {
127
+ transform(coords[i][j], this);
128
+ }
129
+ }
130
+ break;
131
+ }
132
+ if (coords.length === 1) {
133
+ coords = coords[0];
134
+ }
135
+ else {
136
+ type = `Multi${type}`;
137
+ }
138
+ const result = {
139
+ type: 'Feature',
140
+ geometry: {
141
+ type,
142
+ coordinates: coords
143
+ },
144
+ properties: this.properties
145
+ };
146
+ if (this.id !== null) {
147
+ result.id = this.id;
148
+ }
149
+ return result;
150
+ }
151
+ toGeoJSON(options) {
152
+ if (typeof options === 'function') {
153
+ return this._toGeoJSON(options);
154
+ }
155
+ const { x, y, z } = options;
156
+ const size = this.extent * Math.pow(2, z);
157
+ const x0 = this.extent * x;
158
+ const y0 = this.extent * y;
159
+ function project(line) {
160
+ for (let j = 0; j < line.length; j++) {
161
+ const p = line[j];
162
+ p[0] = ((p[0] + x0) * 360) / size - 180;
163
+ const y2 = 180 - ((p[1] + y0) * 360) / size;
164
+ p[1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
165
+ }
166
+ }
167
+ return this._toGeoJSON(project);
168
+ }
169
+ }
170
+ exports.default = VectorTileFeature;
@@ -0,0 +1,20 @@
1
+ import Protobuf from 'pbf';
2
+ import VectorTileFeature from './vector-tile-feature';
3
+ export default class VectorTileLayer {
4
+ version: number;
5
+ name: string;
6
+ extent: number;
7
+ length: number;
8
+ _pbf: Protobuf;
9
+ _keys: string[];
10
+ _values: (string | number | boolean | null)[];
11
+ _features: number[];
12
+ constructor(pbf: Protobuf, end: number);
13
+ /**
14
+ * return feature `i` from this layer as a `VectorTileFeature`
15
+ * @param index
16
+ * @returns feature
17
+ */
18
+ feature(i: number): VectorTileFeature;
19
+ }
20
+ //# sourceMappingURL=vector-tile-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector-tile-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile-layer.ts"],"names":[],"mappings":"AAGA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,iBAAiB,MAAM,uBAAuB,CAAC;AAEtD,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,SAAS,EAAE,MAAM,EAAE,CAAC;gBACR,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM;IAkBtC;;;;OAIG;IAEH,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,iBAAiB;CAUtC"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ /* eslint-disable indent */
3
+ // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const vector_tile_feature_1 = __importDefault(require("./vector-tile-feature"));
9
+ class VectorTileLayer {
10
+ constructor(pbf, end) {
11
+ // Public
12
+ this.version = 1;
13
+ this.name = '';
14
+ this.extent = 4096;
15
+ this.length = 0;
16
+ // Private
17
+ this._pbf = pbf;
18
+ this._keys = [];
19
+ this._values = [];
20
+ this._features = [];
21
+ pbf.readFields(readLayer, this, end);
22
+ this.length = this._features.length;
23
+ }
24
+ /**
25
+ * return feature `i` from this layer as a `VectorTileFeature`
26
+ * @param index
27
+ * @returns feature
28
+ */
29
+ feature(i) {
30
+ if (i < 0 || i >= this._features.length) {
31
+ throw new Error('feature index out of bounds');
32
+ }
33
+ this._pbf.pos = this._features[i];
34
+ const end = this._pbf.readVarint() + this._pbf.pos;
35
+ return new vector_tile_feature_1.default(this._pbf, end, this.extent, this._keys, this._values);
36
+ }
37
+ }
38
+ exports.default = VectorTileLayer;
39
+ /**
40
+ *
41
+ * @param tag
42
+ * @param layer
43
+ * @param pbf
44
+ */
45
+ function readLayer(tag, layer, pbf) {
46
+ if (layer && pbf) {
47
+ if (tag === 15)
48
+ layer.version = pbf.readVarint();
49
+ else if (tag === 1)
50
+ layer.name = pbf.readString();
51
+ else if (tag === 5)
52
+ layer.extent = pbf.readVarint();
53
+ else if (tag === 2)
54
+ layer._features.push(pbf.pos);
55
+ else if (tag === 3)
56
+ layer._keys.push(pbf.readString());
57
+ else if (tag === 4)
58
+ layer._values.push(readValueMessage(pbf));
59
+ }
60
+ }
61
+ /**
62
+ *
63
+ * @param pbf
64
+ * @returns value
65
+ */
66
+ function readValueMessage(pbf) {
67
+ let value = null;
68
+ const end = pbf.readVarint() + pbf.pos;
69
+ while (pbf.pos < end) {
70
+ const tag = pbf.readVarint() >> 3;
71
+ value =
72
+ tag === 1
73
+ ? pbf.readString()
74
+ : tag === 2
75
+ ? pbf.readFloat()
76
+ : tag === 3
77
+ ? pbf.readDouble()
78
+ : tag === 4
79
+ ? pbf.readVarint64()
80
+ : tag === 5
81
+ ? pbf.readVarint()
82
+ : tag === 6
83
+ ? pbf.readSVarint()
84
+ : tag === 7
85
+ ? pbf.readBoolean()
86
+ : null;
87
+ }
88
+ return value;
89
+ }
@@ -0,0 +1,9 @@
1
+ import VectorTileLayer from './vector-tile-layer';
2
+ import Protobuf from 'pbf';
3
+ export default class VectorTile {
4
+ layers: {
5
+ [x: string]: VectorTileLayer;
6
+ };
7
+ constructor(pbf: Protobuf, end?: number);
8
+ }
9
+ //# sourceMappingURL=vector-tile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/mapbox-vector-tile/vector-tile.ts"],"names":[],"mappings":"AAEA,OAAO,eAAe,MAAM,qBAAqB,CAAC;AAClD,OAAO,QAAQ,MAAM,KAAK,CAAC;AAE3B,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,MAAM,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;KAAC,CAAC;gBAC3B,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM;CAGxC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const vector_tile_layer_1 = __importDefault(require("./vector-tile-layer"));
8
+ class VectorTile {
9
+ constructor(pbf, end) {
10
+ this.layers = pbf.readFields(readTile, {}, end);
11
+ }
12
+ }
13
+ exports.default = VectorTile;
14
+ /**
15
+ *
16
+ * @param tag
17
+ * @param layers
18
+ * @param pbf
19
+ */
20
+ function readTile(tag, layers, pbf) {
21
+ if (tag === 3) {
22
+ if (pbf) {
23
+ const layer = new vector_tile_layer_1.default(pbf, pbf.readVarint() + pbf.pos);
24
+ if (layer.length && layers) {
25
+ layers[layer.name] = layer;
26
+ }
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,85 @@
1
+ import { MvtBinaryCoordinates, MvtMapboxCoordinates } from '../lib/types';
2
+ import { LoaderOptions } from '@loaders.gl/loader-utils';
3
+ /**
4
+ * Parse MVT arrayBuffer and return GeoJSON.
5
+ *
6
+ * @param arrayBuffer A MVT arrayBuffer
7
+ * @param options
8
+ * @returns A GeoJSON geometry object or a binary representation
9
+ */
10
+ export default function parseMVT(arrayBuffer: ArrayBuffer, options?: LoaderOptions): {
11
+ points: {
12
+ positions: {
13
+ value: Float32Array;
14
+ size: number;
15
+ };
16
+ globalFeatureIds: {
17
+ value: Uint16Array | Uint32Array;
18
+ size: number;
19
+ };
20
+ featureIds: {
21
+ value: Uint16Array | Uint32Array;
22
+ size: number;
23
+ };
24
+ numericProps: object;
25
+ properties: {}[];
26
+ fields: {
27
+ id?: number | undefined;
28
+ }[];
29
+ };
30
+ lines: {
31
+ pathIndices: {
32
+ value: Uint16Array | Uint32Array;
33
+ size: number;
34
+ };
35
+ positions: {
36
+ value: Float32Array;
37
+ size: number;
38
+ };
39
+ globalFeatureIds: {
40
+ value: Uint16Array | Uint32Array;
41
+ size: number;
42
+ };
43
+ featureIds: {
44
+ value: Uint16Array | Uint32Array;
45
+ size: number;
46
+ };
47
+ numericProps: object;
48
+ properties: {}[];
49
+ fields: {
50
+ id?: number | undefined;
51
+ }[];
52
+ };
53
+ polygons: {
54
+ polygonIndices: {
55
+ value: Uint16Array | Uint32Array;
56
+ size: number;
57
+ };
58
+ primitivePolygonIndices: {
59
+ value: Uint16Array | Uint32Array;
60
+ size: number;
61
+ };
62
+ positions: {
63
+ value: Float32Array;
64
+ size: number;
65
+ };
66
+ triangles: {
67
+ value: Uint32Array;
68
+ size: number;
69
+ };
70
+ globalFeatureIds: {
71
+ value: Uint16Array | Uint32Array;
72
+ size: number;
73
+ };
74
+ featureIds: {
75
+ value: Uint16Array | Uint32Array;
76
+ size: number;
77
+ };
78
+ numericProps: object;
79
+ properties: {}[];
80
+ fields: {
81
+ id?: number | undefined;
82
+ }[];
83
+ };
84
+ } | (MvtBinaryCoordinates | MvtMapboxCoordinates)[];
85
+ //# sourceMappingURL=parse-mvt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,oBAAoB,EAAE,oBAAoB,EAAa,MAAM,cAAc,CAAC;AAGpF,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oDAyDjF"}
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // import {VectorTile} from '@mapbox/vector-tile';
7
+ const vector_tile_1 = __importDefault(require("./mapbox-vector-tile/vector-tile"));
8
+ const vector_tile_2 = __importDefault(require("./binary-vector-tile/vector-tile"));
9
+ const features_to_binary_1 = require("./binary-vector-tile/features-to-binary");
10
+ const pbf_1 = __importDefault(require("pbf"));
11
+ /**
12
+ * Parse MVT arrayBuffer and return GeoJSON.
13
+ *
14
+ * @param arrayBuffer A MVT arrayBuffer
15
+ * @param options
16
+ * @returns A GeoJSON geometry object or a binary representation
17
+ */
18
+ function parseMVT(arrayBuffer, options) {
19
+ options = normalizeOptions(options);
20
+ const features = [];
21
+ if (options) {
22
+ const binary = options.gis.format === 'binary';
23
+ const firstPassData = {
24
+ pointPositionsCount: 0,
25
+ pointFeaturesCount: 0,
26
+ linePositionsCount: 0,
27
+ linePathsCount: 0,
28
+ lineFeaturesCount: 0,
29
+ polygonPositionsCount: 0,
30
+ polygonObjectsCount: 0,
31
+ polygonRingsCount: 0,
32
+ polygonFeaturesCount: 0
33
+ };
34
+ if (arrayBuffer.byteLength > 0) {
35
+ const tile = binary
36
+ ? new vector_tile_2.default(new pbf_1.default(arrayBuffer))
37
+ : new vector_tile_1.default(new pbf_1.default(arrayBuffer));
38
+ const loaderOptions = options.mvt;
39
+ const selectedLayers = Array.isArray(loaderOptions.layers)
40
+ ? loaderOptions.layers
41
+ : Object.keys(tile.layers);
42
+ selectedLayers.forEach((layerName) => {
43
+ const vectorTileLayer = tile.layers[layerName];
44
+ const featureOptions = { ...loaderOptions, layerName };
45
+ if (!vectorTileLayer) {
46
+ return;
47
+ }
48
+ for (let i = 0; i < vectorTileLayer.length; i++) {
49
+ const vectorTileFeature = vectorTileLayer.feature(i, firstPassData);
50
+ const decodedFeature = binary
51
+ ? getDecodedFeatureBinary(vectorTileFeature, featureOptions)
52
+ : getDecodedFeature(vectorTileFeature, featureOptions);
53
+ features.push(decodedFeature);
54
+ }
55
+ });
56
+ }
57
+ if (binary) {
58
+ const data = (0, features_to_binary_1.featuresToBinary)(features, firstPassData);
59
+ // Add the original byteLength (as a reasonable approximation of the size of the binary data)
60
+ // TODO decide where to store extra fields like byteLength (header etc) and document
61
+ // @ts-ignore
62
+ data.byteLength = arrayBuffer.byteLength;
63
+ return data;
64
+ }
65
+ }
66
+ return features;
67
+ }
68
+ exports.default = parseMVT;
69
+ /**
70
+ * @param options
71
+ * @returns options
72
+ */
73
+ function normalizeOptions(options) {
74
+ if (options) {
75
+ options = {
76
+ ...options,
77
+ mvt: options.mvt || {},
78
+ gis: options.gis || {}
79
+ };
80
+ // Validate
81
+ const wgs84Coordinates = options.coordinates === 'wgs84';
82
+ const { tileIndex } = options;
83
+ const hasTileIndex = tileIndex &&
84
+ Number.isFinite(tileIndex.x) &&
85
+ Number.isFinite(tileIndex.y) &&
86
+ Number.isFinite(tileIndex.z);
87
+ if (wgs84Coordinates && !hasTileIndex) {
88
+ throw new Error('MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.');
89
+ }
90
+ }
91
+ return options;
92
+ }
93
+ /**
94
+ * @param feature
95
+ * @param options
96
+ * @returns decoded feature
97
+ */
98
+ function getDecodedFeature(feature, options) {
99
+ const decodedFeature = feature.toGeoJSON(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
100
+ // Add layer name to GeoJSON properties
101
+ if (options.layerProperty) {
102
+ decodedFeature.properties[options.layerProperty] = options.layerName;
103
+ }
104
+ return decodedFeature;
105
+ }
106
+ /**
107
+ * @param feature
108
+ * @param options
109
+ * @returns decoded binary feature
110
+ */
111
+ function getDecodedFeatureBinary(feature, options) {
112
+ const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
113
+ // Add layer name to GeoJSON properties
114
+ if (options.layerProperty) {
115
+ decodedFeature.properties[options.layerProperty] = options.layerName;
116
+ }
117
+ return decodedFeature;
118
+ }
119
+ /**
120
+ * @param line
121
+ * @param feature
122
+ */
123
+ function transformToLocalCoordinates(line, feature) {
124
+ // This function transforms local coordinates in a
125
+ // [0 - bufferSize, this.extent + bufferSize] range to a
126
+ // [0 - (bufferSize / this.extent), 1 + (bufferSize / this.extent)] range.
127
+ // The resulting extent would be 1.
128
+ const { extent } = feature;
129
+ for (let i = 0; i < line.length; i++) {
130
+ const p = line[i];
131
+ p[0] /= extent;
132
+ p[1] /= extent;
133
+ }
134
+ }
135
+ function transformToLocalCoordinatesBinary(data, feature) {
136
+ // For the binary code path, the feature data is just
137
+ // one big flat array, so we just divide each value
138
+ const { extent } = feature;
139
+ for (let i = 0, il = data.length; i < il; ++i) {
140
+ data[i] /= extent;
141
+ }
142
+ }