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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2276 -4
  4. package/dist/es5/bundle.js +7 -0
  5. package/dist/es5/bundle.js.map +1 -0
  6. package/dist/es5/helpers/binary-util-functions.js +95 -0
  7. package/dist/es5/helpers/binary-util-functions.js.map +1 -0
  8. package/dist/es5/helpers/mapbox-util-functions.js +62 -0
  9. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
  10. package/dist/es5/index.js +20 -0
  11. package/dist/es5/index.js.map +1 -0
  12. package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
  13. package/dist/es5/lib/binary-vector-tile/features-to-binary.js +338 -0
  14. package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +1 -0
  15. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +162 -0
  16. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  17. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +69 -0
  18. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  19. package/dist/es5/lib/binary-vector-tile/vector-tile.js +35 -0
  20. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
  21. package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
  22. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +207 -0
  23. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  24. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +69 -0
  25. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  26. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +35 -0
  27. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  28. package/dist/es5/lib/parse-mvt.js +129 -0
  29. package/dist/es5/lib/parse-mvt.js.map +1 -0
  30. package/dist/es5/lib/types.js +2 -0
  31. package/dist/{lib → es5/lib}/types.js.map +0 -0
  32. package/dist/es5/mvt-loader.js +38 -0
  33. package/dist/es5/mvt-loader.js.map +1 -0
  34. package/dist/es5/workers/mvt-worker.js +8 -0
  35. package/dist/es5/workers/mvt-worker.js.map +1 -0
  36. package/dist/esm/bundle.js +5 -0
  37. package/dist/esm/bundle.js.map +1 -0
  38. package/dist/esm/helpers/binary-util-functions.js +81 -0
  39. package/dist/esm/helpers/binary-util-functions.js.map +1 -0
  40. package/dist/esm/helpers/mapbox-util-functions.js +49 -0
  41. package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
  42. package/dist/esm/index.js +2 -0
  43. package/dist/esm/index.js.map +1 -0
  44. package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
  45. package/dist/esm/lib/binary-vector-tile/features-to-binary.js +327 -0
  46. package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +1 -0
  47. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +156 -0
  48. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  49. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +64 -0
  50. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  51. package/dist/esm/lib/binary-vector-tile/vector-tile.js +23 -0
  52. package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
  53. package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
  54. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +202 -0
  55. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  56. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +64 -0
  57. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  58. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +23 -0
  59. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  60. package/dist/esm/lib/parse-mvt.js +116 -0
  61. package/dist/esm/lib/parse-mvt.js.map +1 -0
  62. package/dist/esm/lib/types.js +2 -0
  63. package/dist/esm/lib/types.js.map +1 -0
  64. package/dist/esm/mvt-loader.js +26 -0
  65. package/dist/esm/mvt-loader.js.map +1 -0
  66. package/dist/esm/workers/mvt-worker.js +4 -0
  67. package/dist/esm/workers/mvt-worker.js.map +1 -0
  68. package/dist/helpers/binary-util-functions.d.ts +39 -0
  69. package/dist/helpers/binary-util-functions.d.ts.map +1 -0
  70. package/dist/helpers/binary-util-functions.js +109 -74
  71. package/dist/helpers/mapbox-util-functions.d.ts +29 -0
  72. package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
  73. package/dist/helpers/mapbox-util-functions.js +78 -45
  74. package/dist/index.d.ts +2 -0
  75. package/dist/index.d.ts.map +1 -0
  76. package/dist/index.js +6 -2
  77. package/dist/lib/binary-vector-tile/features-to-binary.d.ts +185 -0
  78. package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +1 -0
  79. package/dist/lib/binary-vector-tile/features-to-binary.js +323 -297
  80. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +36 -0
  81. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
  82. package/dist/lib/binary-vector-tile/vector-tile-feature.js +145 -142
  83. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
  84. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
  85. package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
  86. package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
  87. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
  88. package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
  89. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +27 -0
  90. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
  91. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
  92. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
  93. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
  94. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
  95. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
  96. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
  97. package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
  98. package/dist/lib/parse-mvt.d.ts +85 -0
  99. package/dist/lib/parse-mvt.d.ts.map +1 -0
  100. package/dist/lib/parse-mvt.js +126 -100
  101. package/dist/lib/types.d.ts +92 -0
  102. package/dist/lib/types.d.ts.map +1 -0
  103. package/dist/lib/types.js +2 -2
  104. package/dist/mvt-loader.d.ts +10 -0
  105. package/dist/mvt-loader.d.ts.map +1 -0
  106. package/dist/mvt-loader.js +42 -23
  107. package/dist/mvt-worker.js +2286 -3
  108. package/dist/workers/mvt-worker.d.ts +2 -0
  109. package/dist/workers/mvt-worker.d.ts.map +1 -0
  110. package/dist/workers/mvt-worker.js +5 -4
  111. package/package.json +9 -9
  112. package/src/lib/parse-mvt.ts +1 -1
  113. package/dist/bundle.js.map +0 -1
  114. package/dist/dist.min.js +0 -4
  115. package/dist/dist.min.js.map +0 -1
  116. package/dist/helpers/binary-util-functions.js.map +0 -1
  117. package/dist/helpers/mapbox-util-functions.js.map +0 -1
  118. package/dist/index.js.map +0 -1
  119. package/dist/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  120. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  121. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  122. package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
  123. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  124. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  125. package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  126. package/dist/lib/parse-mvt.js.map +0 -1
  127. package/dist/mvt-loader.js.map +0 -1
  128. package/dist/mvt-worker.js.map +0 -1
  129. package/dist/workers/mvt-worker.js.map +0 -1
@@ -0,0 +1,36 @@
1
+ import Protobuf from 'pbf';
2
+ import { MvtBinaryCoordinates, MvtBinaryGeometry, MvtFirstPassedData } from '../types';
3
+ import { classifyRings } from '../../helpers/binary-util-functions';
4
+ export declare const TEST_EXPORTS: {
5
+ classifyRings: typeof classifyRings;
6
+ };
7
+ export default class VectorTileFeature {
8
+ properties: {
9
+ [x: string]: string | number | boolean | null;
10
+ };
11
+ extent: any;
12
+ type: number;
13
+ id: number | null;
14
+ _pbf: Protobuf;
15
+ _geometry: number;
16
+ _keys: string[];
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;
22
+ /**
23
+ *
24
+ * @param transform
25
+ * @returns result
26
+ */
27
+ _toBinaryCoordinates(transform: any): MvtBinaryCoordinates;
28
+ toBinaryCoordinates(options: {
29
+ x: number;
30
+ y: number;
31
+ z: number;
32
+ } | ((data: number[], feature: {
33
+ extent: any;
34
+ }) => void)): MvtBinaryCoordinates;
35
+ }
36
+ //# sourceMappingURL=vector-tile-feature.d.ts.map
@@ -0,0 +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,aAEf;gBAIC,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,aAAa,EAAE,kBAAkB;IAmBnC,YAAY,IAAI,iBAAiB;IAqDjC;;;;OAIG;IACH,oBAAoB,CAAC,SAAS,KAAA;IA4E9B,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,oBAAoB;CAMxB"}
@@ -1,5 +1,9 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { classifyRings, project, readFeature } from '../../helpers/binary-util-functions';
1
+ "use strict";
2
+ // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.TEST_EXPORTS = void 0;
5
+ const binary_util_functions_1 = require("../../helpers/binary-util-functions");
6
+ // Reduce GC by reusing variables
3
7
  let endPos;
4
8
  let cmd;
5
9
  let cmdLen;
@@ -7,150 +11,149 @@ let length;
7
11
  let x;
8
12
  let y;
9
13
  let i;
10
- export const TEST_EXPORTS = {
11
- classifyRings
14
+ exports.TEST_EXPORTS = {
15
+ classifyRings: binary_util_functions_1.classifyRings
12
16
  };
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) {
19
- _defineProperty(this, "properties", void 0);
20
-
21
- _defineProperty(this, "extent", void 0);
22
-
23
- _defineProperty(this, "type", void 0);
24
-
25
- _defineProperty(this, "id", void 0);
26
-
27
- _defineProperty(this, "_pbf", void 0);
28
-
29
- _defineProperty(this, "_geometry", void 0);
30
-
31
- _defineProperty(this, "_keys", void 0);
32
-
33
- _defineProperty(this, "_values", void 0);
34
-
35
- _defineProperty(this, "_firstPassData", void 0);
36
-
37
- this.properties = {};
38
- this.extent = extent;
39
- this.type = 0;
40
- this.id = null;
41
- this._pbf = pbf;
42
- this._geometry = -1;
43
- this._keys = keys;
44
- this._values = values;
45
- this._firstPassData = firstPassData;
46
- pbf.readFields(readFeature, this, end);
47
- }
48
-
49
- loadGeometry() {
50
- const pbf = this._pbf;
51
- pbf.pos = this._geometry;
52
- endPos = pbf.readVarint() + pbf.pos;
53
- cmd = 1;
54
- length = 0;
55
- x = 0;
56
- y = 0;
57
- i = 0;
58
- const lines = [];
59
- const data = [];
60
-
61
- while (pbf.pos < endPos) {
62
- if (length <= 0) {
63
- cmdLen = pbf.readVarint();
64
- cmd = cmdLen & 0x7;
65
- length = cmdLen >> 3;
66
- }
67
-
68
- length--;
69
-
70
- if (cmd === 1 || cmd === 2) {
71
- x += pbf.readSVarint();
72
- y += pbf.readSVarint();
73
-
74
- if (cmd === 1) {
75
- lines.push(i);
76
- }
77
-
78
- data.push(x, y);
79
- i += 2;
80
- } else if (cmd === 7) {
81
- if (i > 0) {
82
- const start = lines[lines.length - 1];
83
- data.push(data[start], data[start + 1]);
84
- i += 2;
85
- }
86
- } else {
87
- throw new Error(`unknown command ${cmd}`);
88
- }
17
+ class VectorTileFeature {
18
+ // eslint-disable-next-line max-params
19
+ constructor(pbf, end, extent, keys, values, firstPassData) {
20
+ // Public
21
+ this.properties = {};
22
+ this.extent = extent;
23
+ this.type = 0;
24
+ this.id = null;
25
+ // Private
26
+ this._pbf = pbf;
27
+ this._geometry = -1;
28
+ this._keys = keys;
29
+ this._values = values;
30
+ this._firstPassData = firstPassData;
31
+ pbf.readFields(binary_util_functions_1.readFeature, this, end);
89
32
  }
90
-
91
- return {
92
- data,
93
- lines
94
- };
95
- }
96
-
97
- _toBinaryCoordinates(transform) {
98
- let geom = this.loadGeometry();
99
- transform(geom.data, this);
100
- const coordLength = 2;
101
-
102
- switch (this.type) {
103
- case 1:
104
- this._firstPassData.pointFeaturesCount++;
105
- this._firstPassData.pointPositionsCount += geom.lines.length;
106
- break;
107
-
108
- case 2:
109
- this._firstPassData.lineFeaturesCount++;
110
- this._firstPassData.linePathsCount += geom.lines.length;
111
- this._firstPassData.linePositionsCount += geom.data.length / coordLength;
112
- break;
113
-
114
- case 3:
115
- const classified = classifyRings(geom);
116
- this._firstPassData.polygonFeaturesCount++;
117
- this._firstPassData.polygonObjectsCount += classified.lines.length;
118
-
119
- for (const lines of classified.lines) {
120
- this._firstPassData.polygonRingsCount += lines.length;
121
- }
122
-
123
- this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;
124
- geom = classified;
125
- break;
33
+ static get types() {
34
+ return ['Unknown', 'Point', 'LineString', 'Polygon'];
126
35
  }
127
-
128
- geom.type = VectorTileFeature.types[this.type];
129
-
130
- if (geom.lines.length > 1) {
131
- geom.type = `Multi${geom.type}`;
36
+ // eslint-disable-next-line complexity, max-statements
37
+ loadGeometry() {
38
+ const pbf = this._pbf;
39
+ pbf.pos = this._geometry;
40
+ endPos = pbf.readVarint() + pbf.pos;
41
+ cmd = 1;
42
+ length = 0;
43
+ x = 0;
44
+ y = 0;
45
+ i = 0;
46
+ // Note: I attempted to replace the `data` array with a
47
+ // Float32Array, but performance was worse, both using
48
+ // `set()` and direct index access. Also, we cannot
49
+ // know how large the buffer should be, so it would
50
+ // increase memory usage
51
+ const lines = []; // Indices where lines start
52
+ const data = []; // Flat array of coordinate data
53
+ while (pbf.pos < endPos) {
54
+ if (length <= 0) {
55
+ cmdLen = pbf.readVarint();
56
+ cmd = cmdLen & 0x7;
57
+ length = cmdLen >> 3;
58
+ }
59
+ length--;
60
+ if (cmd === 1 || cmd === 2) {
61
+ x += pbf.readSVarint();
62
+ y += pbf.readSVarint();
63
+ if (cmd === 1) {
64
+ // New line
65
+ lines.push(i);
66
+ }
67
+ data.push(x, y);
68
+ i += 2;
69
+ }
70
+ else if (cmd === 7) {
71
+ // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
72
+ if (i > 0) {
73
+ const start = lines[lines.length - 1]; // start index of polygon
74
+ data.push(data[start], data[start + 1]); // closePolygon
75
+ i += 2;
76
+ }
77
+ }
78
+ else {
79
+ throw new Error(`unknown command ${cmd}`);
80
+ }
81
+ }
82
+ return { data, lines };
132
83
  }
133
-
134
- const result = {
135
- type: 'Feature',
136
- geometry: geom,
137
- properties: this.properties
138
- };
139
-
140
- if (this.id !== null) {
141
- result.id = this.id;
84
+ /**
85
+ *
86
+ * @param transform
87
+ * @returns result
88
+ */
89
+ _toBinaryCoordinates(transform) {
90
+ // Expands the protobuf data to an intermediate `lines`
91
+ // data format, which maps closely to the binary data buffers.
92
+ // It is similar to GeoJSON, but rather than storing the coordinates
93
+ // in multidimensional arrays, we have a 1D `data` with all the
94
+ // coordinates, and then index into this using the `lines`
95
+ // parameter, e.g.
96
+ //
97
+ // geometry: {
98
+ // type: 'Point', data: [1,2], lines: [0]
99
+ // }
100
+ // geometry: {
101
+ // type: 'LineString', data: [1,2,3,4,...], lines: [0]
102
+ // }
103
+ // geometry: {
104
+ // type: 'Polygon', data: [1,2,3,4,...], lines: [[0, 2]]
105
+ // }
106
+ // Thus the lines member lets us look up the relevant range
107
+ // from the data array.
108
+ // 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();
111
+ // Apply the supplied transformation to data
112
+ transform(geom.data, this);
113
+ const coordLength = 2;
114
+ // eslint-disable-next-line default-case
115
+ switch (this.type) {
116
+ case 1: // Point
117
+ this._firstPassData.pointFeaturesCount++;
118
+ this._firstPassData.pointPositionsCount += geom.lines.length;
119
+ break;
120
+ case 2: // LineString
121
+ this._firstPassData.lineFeaturesCount++;
122
+ this._firstPassData.linePathsCount += geom.lines.length;
123
+ this._firstPassData.linePositionsCount += geom.data.length / coordLength;
124
+ break;
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
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;
133
+ }
134
+ this._firstPassData.polygonPositionsCount += classified.data.length / coordLength;
135
+ geom = classified;
136
+ break;
137
+ }
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
+ };
147
+ if (this.id !== null) {
148
+ result.id = this.id;
149
+ }
150
+ return result;
142
151
  }
143
-
144
- return result;
145
- }
146
-
147
- toBinaryCoordinates(options) {
148
- if (typeof options === 'function') {
149
- return this._toBinaryCoordinates(options);
152
+ toBinaryCoordinates(options) {
153
+ if (typeof options === 'function') {
154
+ return this._toBinaryCoordinates(options);
155
+ }
156
+ return this._toBinaryCoordinates(binary_util_functions_1.project);
150
157
  }
151
-
152
- return this._toBinaryCoordinates(project);
153
- }
154
-
155
158
  }
156
- //# sourceMappingURL=vector-tile-feature.js.map
159
+ exports.default = VectorTileFeature;
@@ -0,0 +1,23 @@
1
+ import VectorTileFeature from './vector-tile-feature';
2
+ import Protobuf from 'pbf';
3
+ import { MvtFirstPassedData } from '../types';
4
+ export default class VectorTileLayer {
5
+ version: number;
6
+ name: string;
7
+ extent: number;
8
+ length: number;
9
+ _pbf: Protobuf;
10
+ _keys: string[];
11
+ _values: (string | number | boolean | null)[];
12
+ _features: number[];
13
+ constructor(pbf: Protobuf, end: number);
14
+ /**
15
+ * return feature `i` from this layer as a `VectorTileFeature`
16
+ *
17
+ * @param index
18
+ * @param firstPassData
19
+ * @returns {VectorTileFeature}
20
+ */
21
+ feature(i: number, firstPassData: MvtFirstPassedData): VectorTileFeature;
22
+ }
23
+ //# sourceMappingURL=vector-tile-layer.d.ts.map
@@ -0,0 +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,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;IAC9C,SAAS,EAAE,MAAM,EAAE,CAAC;gBACR,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM;IAkBtC;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,kBAAkB,GAAG,iBAAiB;CAiBzE"}
@@ -1,64 +1,91 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import VectorTileFeature from './vector-tile-feature';
3
- export default class VectorTileLayer {
4
- constructor(pbf, end) {
5
- _defineProperty(this, "version", void 0);
6
-
7
- _defineProperty(this, "name", void 0);
8
-
9
- _defineProperty(this, "extent", void 0);
10
-
11
- _defineProperty(this, "length", void 0);
12
-
13
- _defineProperty(this, "_pbf", void 0);
14
-
15
- _defineProperty(this, "_keys", void 0);
16
-
17
- _defineProperty(this, "_values", void 0);
18
-
19
- _defineProperty(this, "_features", void 0);
20
-
21
- this.version = 1;
22
- this.name = '';
23
- this.extent = 4096;
24
- this.length = 0;
25
- this._pbf = pbf;
26
- this._keys = [];
27
- this._values = [];
28
- this._features = [];
29
- pbf.readFields(readLayer, this, end);
30
- this.length = this._features.length;
31
- }
32
-
33
- feature(i, firstPassData) {
34
- if (i < 0 || i >= this._features.length) {
35
- throw new Error('feature index out of bounds');
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
+ *
27
+ * @param index
28
+ * @param firstPassData
29
+ * @returns {VectorTileFeature}
30
+ */
31
+ feature(i, firstPassData) {
32
+ if (i < 0 || i >= this._features.length) {
33
+ throw new Error('feature index out of bounds');
34
+ }
35
+ this._pbf.pos = this._features[i];
36
+ const end = this._pbf.readVarint() + this._pbf.pos;
37
+ return new vector_tile_feature_1.default(this._pbf, end, this.extent, this._keys, this._values, firstPassData);
36
38
  }
37
-
38
- this._pbf.pos = this._features[i];
39
-
40
- const end = this._pbf.readVarint() + this._pbf.pos;
41
-
42
- return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values, firstPassData);
43
- }
44
-
45
39
  }
46
-
40
+ exports.default = VectorTileLayer;
41
+ /**
42
+ *
43
+ * @param tag
44
+ * @param layer
45
+ * @param pbf
46
+ */
47
47
  function readLayer(tag, layer, pbf) {
48
- if (layer && pbf) {
49
- if (tag === 15) layer.version = pbf.readVarint();else if (tag === 1) layer.name = pbf.readString();else if (tag === 5) layer.extent = pbf.readVarint();else if (tag === 2) layer._features.push(pbf.pos);else if (tag === 3) layer._keys.push(pbf.readString());else if (tag === 4) layer._values.push(readValueMessage(pbf));
50
- }
48
+ if (layer && pbf) {
49
+ if (tag === 15)
50
+ layer.version = pbf.readVarint();
51
+ else if (tag === 1)
52
+ layer.name = pbf.readString();
53
+ else if (tag === 5)
54
+ layer.extent = pbf.readVarint();
55
+ else if (tag === 2)
56
+ layer._features.push(pbf.pos);
57
+ else if (tag === 3)
58
+ layer._keys.push(pbf.readString());
59
+ else if (tag === 4)
60
+ layer._values.push(readValueMessage(pbf));
61
+ }
51
62
  }
52
-
63
+ /**
64
+ *
65
+ * @param pbf
66
+ * @returns value
67
+ */
53
68
  function readValueMessage(pbf) {
54
- let value = null;
55
- const end = pbf.readVarint() + pbf.pos;
56
-
57
- while (pbf.pos < end) {
58
- const tag = pbf.readVarint() >> 3;
59
- value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
60
- }
61
-
62
- return value;
69
+ let value = null;
70
+ const end = pbf.readVarint() + pbf.pos;
71
+ while (pbf.pos < end) {
72
+ const tag = pbf.readVarint() >> 3;
73
+ value =
74
+ tag === 1
75
+ ? pbf.readString()
76
+ : tag === 2
77
+ ? pbf.readFloat()
78
+ : tag === 3
79
+ ? pbf.readDouble()
80
+ : tag === 4
81
+ ? pbf.readVarint64()
82
+ : tag === 5
83
+ ? pbf.readVarint()
84
+ : tag === 6
85
+ ? pbf.readSVarint()
86
+ : tag === 7
87
+ ? pbf.readBoolean()
88
+ : null;
89
+ }
90
+ return value;
63
91
  }
64
- //# sourceMappingURL=vector-tile-layer.js.map
@@ -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/binary-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"}
@@ -1,23 +1,29 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import VectorTileLayer from './vector-tile-layer';
3
- export default class VectorTile {
4
- constructor(pbf, end) {
5
- _defineProperty(this, "layers", void 0);
6
-
7
- this.layers = pbf.readFields(readTile, {}, end);
8
- }
9
-
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
+ }
10
12
  }
11
-
13
+ exports.default = VectorTile;
14
+ /**
15
+ *
16
+ * @param tag
17
+ * @param layers
18
+ * @param pbf
19
+ */
12
20
  function readTile(tag, layers, pbf) {
13
- if (tag === 3) {
14
- if (pbf) {
15
- const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
16
-
17
- if (layer.length && layers) {
18
- layers[layer.name] = layer;
19
- }
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
+ }
20
28
  }
21
- }
22
29
  }
23
- //# sourceMappingURL=vector-tile.js.map
@@ -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"}