@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,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readTag = exports.readFeature = exports.project = exports.classifyRings = void 0;
4
+ const polygon_1 = require("@math.gl/polygon");
5
+ /**
6
+ * Classifies an array of rings into polygons with outer rings and holes
7
+ * The function also detects holes which have zero area and
8
+ * removes them. In doing so it modifies the input
9
+ * `geom.data` array to remove the unneeded data
10
+ *
11
+ * @param geometry
12
+ * @returns object
13
+ */
14
+ // eslint-disable-next-line max-statements
15
+ function classifyRings(geom) {
16
+ const len = geom.lines.length;
17
+ if (len <= 1) {
18
+ return {
19
+ data: geom.data,
20
+ areas: [[(0, polygon_1.getPolygonSignedArea)(geom.data)]],
21
+ lines: [geom.lines]
22
+ };
23
+ }
24
+ const areas = [];
25
+ const polygons = [];
26
+ let ringAreas = [];
27
+ let polygon = [];
28
+ let ccw;
29
+ let offset = 0;
30
+ 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
+ const shape = geom.data.slice(startIndex, endIndex);
34
+ const area = (0, polygon_1.getPolygonSignedArea)(shape);
35
+ if (area === 0) {
36
+ // This polygon has no area, so remove it from the shape
37
+ // Remove the section from the data array
38
+ const before = geom.data.slice(0, startIndex);
39
+ const after = geom.data.slice(endIndex);
40
+ geom.data = before.concat(after);
41
+ // Need to offset any remaining indices as we have
42
+ // modified the data buffer
43
+ offset += endIndex - startIndex;
44
+ // Do not add this index to the output and process next shape
45
+ continue; // eslint-disable-line no-continue
46
+ }
47
+ if (ccw === undefined)
48
+ ccw = area < 0;
49
+ if (ccw === area < 0) {
50
+ if (polygon.length) {
51
+ areas.push(ringAreas);
52
+ polygons.push(polygon);
53
+ }
54
+ polygon = [startIndex];
55
+ ringAreas = [area];
56
+ }
57
+ else {
58
+ ringAreas.push(area);
59
+ polygon.push(startIndex);
60
+ }
61
+ }
62
+ if (ringAreas)
63
+ areas.push(ringAreas);
64
+ if (polygon.length)
65
+ polygons.push(polygon);
66
+ return { areas, lines: polygons, data: geom.data };
67
+ }
68
+ exports.classifyRings = classifyRings;
69
+ /**
70
+ *
71
+ * @param data
72
+ * @param x0
73
+ * @param y0
74
+ * @param size
75
+ */
76
+ function project(data, x0, y0, size) {
77
+ for (let j = 0, jl = data.length; j < jl; j += 2) {
78
+ data[j] = ((data[j] + x0) * 360) / size - 180;
79
+ const y2 = 180 - ((data[j + 1] + y0) * 360) / size;
80
+ data[j + 1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
81
+ }
82
+ }
83
+ exports.project = project;
84
+ /**
85
+ * All code below is unchanged from the original Mapbox implemenation
86
+ *
87
+ * @param tag
88
+ * @param feature
89
+ * @param pbf
90
+ */
91
+ function readFeature(tag, feature, pbf) {
92
+ if (feature && pbf) {
93
+ if (tag === 1)
94
+ feature.id = pbf.readVarint();
95
+ else if (tag === 2)
96
+ readTag(pbf, feature);
97
+ else if (tag === 3)
98
+ feature.type = pbf.readVarint();
99
+ else if (tag === 4)
100
+ feature._geometry = pbf.pos;
101
+ }
102
+ }
103
+ exports.readFeature = readFeature;
104
+ /**
105
+ * @param pbf
106
+ * @param feature
107
+ */
108
+ function readTag(pbf, feature) {
109
+ const end = pbf.readVarint() + pbf.pos;
110
+ while (pbf.pos < end) {
111
+ const key = feature._keys[pbf.readVarint()];
112
+ const value = feature._values[pbf.readVarint()];
113
+ feature.properties[key] = value;
114
+ }
115
+ }
116
+ exports.readTag = readTag;
@@ -0,0 +1,29 @@
1
+ import Protobuf from 'pbf';
2
+ import { MvtMapboxGeometry } from '../lib/types';
3
+ import VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';
4
+ /**
5
+ * Classifies an array of rings into polygons with outer rings and holes
6
+ * @param rings
7
+ * @returns polygons
8
+ */
9
+ export declare function classifyRings(rings: MvtMapboxGeometry): MvtMapboxGeometry[] | number[][][];
10
+ /**
11
+ *
12
+ * @param ring
13
+ * @returns sum
14
+ */
15
+ export declare function signedArea(ring: number[][]): number;
16
+ /**
17
+ *
18
+ * @param tag
19
+ * @param feature
20
+ * @param pbf
21
+ */
22
+ export declare function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Protobuf): void;
23
+ /**
24
+ *
25
+ * @param pbf
26
+ * @param feature
27
+ */
28
+ export declare function readTag(pbf: Protobuf, feature: VectorTileFeature): void;
29
+ //# sourceMappingURL=mapbox-util-functions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapbox-util-functions.d.ts","sourceRoot":"","sources":["../../src/helpers/mapbox-util-functions.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAC/C,OAAO,iBAAiB,MAAM,+CAA+C,CAAC;AAE9E;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,sCAuBrD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,UAQ1C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAO1F;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAQvE"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readTag = exports.readFeature = exports.signedArea = exports.classifyRings = void 0;
4
+ /**
5
+ * Classifies an array of rings into polygons with outer rings and holes
6
+ * @param rings
7
+ * @returns polygons
8
+ */
9
+ function classifyRings(rings) {
10
+ const len = rings.length;
11
+ if (len <= 1)
12
+ return [rings];
13
+ const polygons = [];
14
+ let polygon;
15
+ let ccw;
16
+ for (let i = 0; i < len; i++) {
17
+ const area = signedArea(rings[i]);
18
+ if (area === 0)
19
+ continue; // eslint-disable-line no-continue
20
+ if (ccw === undefined)
21
+ ccw = area < 0;
22
+ if (ccw === area < 0) {
23
+ if (polygon)
24
+ polygons.push(polygon);
25
+ polygon = [rings[i]];
26
+ }
27
+ else if (polygon)
28
+ polygon.push(rings[i]);
29
+ }
30
+ if (polygon)
31
+ polygons.push(polygon);
32
+ return polygons;
33
+ }
34
+ exports.classifyRings = classifyRings;
35
+ /**
36
+ *
37
+ * @param ring
38
+ * @returns sum
39
+ */
40
+ function signedArea(ring) {
41
+ let sum = 0;
42
+ for (let i = 0, j = ring.length - 1, p1, p2; i < ring.length; j = i++) {
43
+ p1 = ring[i];
44
+ p2 = ring[j];
45
+ sum += (p2[0] - p1[0]) * (p1[1] + p2[1]);
46
+ }
47
+ return sum;
48
+ }
49
+ exports.signedArea = signedArea;
50
+ /**
51
+ *
52
+ * @param tag
53
+ * @param feature
54
+ * @param pbf
55
+ */
56
+ function readFeature(tag, feature, pbf) {
57
+ if (feature && pbf) {
58
+ if (tag === 1)
59
+ feature.id = pbf.readVarint();
60
+ else if (tag === 2)
61
+ readTag(pbf, feature);
62
+ else if (tag === 3)
63
+ feature.type = pbf.readVarint();
64
+ else if (tag === 4)
65
+ feature._geometry = pbf.pos;
66
+ }
67
+ }
68
+ exports.readFeature = readFeature;
69
+ /**
70
+ *
71
+ * @param pbf
72
+ * @param feature
73
+ */
74
+ function readTag(pbf, feature) {
75
+ const end = pbf.readVarint() + pbf.pos;
76
+ while (pbf.pos < end) {
77
+ const key = feature._keys[pbf.readVarint()];
78
+ const value = feature._values[pbf.readVarint()];
79
+ feature.properties[key] = value;
80
+ }
81
+ }
82
+ exports.readTag = readTag;
@@ -0,0 +1,2 @@
1
+ export { MVTLoader, MVTWorkerLoader } from './mvt-loader';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MVTWorkerLoader = exports.MVTLoader = void 0;
4
+ var mvt_loader_1 = require("./mvt-loader");
5
+ Object.defineProperty(exports, "MVTLoader", { enumerable: true, get: function () { return mvt_loader_1.MVTLoader; } });
6
+ Object.defineProperty(exports, "MVTWorkerLoader", { enumerable: true, get: function () { return mvt_loader_1.MVTWorkerLoader; } });
@@ -0,0 +1,185 @@
1
+ import { MvtBinaryCoordinates, MvtBinaryOptions, MvtFirstPassedData } from '../types';
2
+ /**
3
+ * Convert binary features to flat binary arrays. Similar to
4
+ * `geojsonToBinary` helper function, except that it expects
5
+ * a binary representation of the feature data, which enables
6
+ * 2X-3X speed increase in parse speed, compared to using
7
+ * geoJSON. See `binary-vector-tile/VectorTileFeature` for
8
+ * data format detais
9
+ *
10
+ * @param features
11
+ * @param firstPassData
12
+ * @param options
13
+ * @returns filled arrays
14
+ */
15
+ export declare function featuresToBinary(features: MvtBinaryCoordinates[], firstPassData: MvtFirstPassedData, options?: MvtBinaryOptions): {
16
+ points: {
17
+ positions: {
18
+ value: Float32Array;
19
+ size: number;
20
+ };
21
+ globalFeatureIds: {
22
+ value: Uint16Array | Uint32Array;
23
+ size: number;
24
+ };
25
+ featureIds: {
26
+ value: Uint16Array | Uint32Array;
27
+ size: number;
28
+ };
29
+ numericProps: object;
30
+ properties: {}[];
31
+ fields: {
32
+ id?: number | undefined;
33
+ }[];
34
+ };
35
+ lines: {
36
+ pathIndices: {
37
+ value: Uint16Array | Uint32Array;
38
+ size: number;
39
+ };
40
+ positions: {
41
+ value: Float32Array;
42
+ size: number;
43
+ };
44
+ globalFeatureIds: {
45
+ value: Uint16Array | Uint32Array;
46
+ size: number;
47
+ };
48
+ featureIds: {
49
+ value: Uint16Array | Uint32Array;
50
+ size: number;
51
+ };
52
+ numericProps: object;
53
+ properties: {}[];
54
+ fields: {
55
+ id?: number | undefined;
56
+ }[];
57
+ };
58
+ polygons: {
59
+ polygonIndices: {
60
+ value: Uint16Array | Uint32Array;
61
+ size: number;
62
+ };
63
+ primitivePolygonIndices: {
64
+ value: Uint16Array | Uint32Array;
65
+ size: number;
66
+ };
67
+ positions: {
68
+ value: Float32Array;
69
+ size: number;
70
+ };
71
+ triangles: {
72
+ value: Uint32Array;
73
+ size: number;
74
+ };
75
+ globalFeatureIds: {
76
+ value: Uint16Array | Uint32Array;
77
+ size: number;
78
+ };
79
+ featureIds: {
80
+ value: Uint16Array | Uint32Array;
81
+ size: number;
82
+ };
83
+ numericProps: object;
84
+ properties: {}[];
85
+ fields: {
86
+ id?: number | undefined;
87
+ }[];
88
+ };
89
+ };
90
+ export declare const TEST_EXPORTS: {
91
+ extractNumericPropKeys: typeof extractNumericPropKeys;
92
+ fillArrays: typeof fillArrays;
93
+ };
94
+ /**
95
+ * Extracts properties that are always numeric
96
+ *
97
+ * @param features
98
+ * @returns object with numeric keys
99
+ */
100
+ declare function extractNumericPropKeys(features: MvtBinaryCoordinates[]): string[];
101
+ /**
102
+ * Fills coordinates into pre-allocated typed arrays
103
+ *
104
+ * @param features
105
+ * @param firstPassData
106
+ * @param options
107
+ * @returns an accessor object with value and size keys
108
+ */
109
+ declare function fillArrays(features: MvtBinaryCoordinates[], firstPassData: MvtFirstPassedData, options: MvtBinaryOptions): {
110
+ points: {
111
+ positions: {
112
+ value: Float32Array;
113
+ size: number;
114
+ };
115
+ globalFeatureIds: {
116
+ value: Uint16Array | Uint32Array;
117
+ size: number;
118
+ };
119
+ featureIds: {
120
+ value: Uint16Array | Uint32Array;
121
+ size: number;
122
+ };
123
+ numericProps: object;
124
+ properties: {}[];
125
+ fields: {
126
+ id?: number | undefined;
127
+ }[];
128
+ };
129
+ lines: {
130
+ pathIndices: {
131
+ value: Uint16Array | Uint32Array;
132
+ size: number;
133
+ };
134
+ positions: {
135
+ value: Float32Array;
136
+ size: number;
137
+ };
138
+ globalFeatureIds: {
139
+ value: Uint16Array | Uint32Array;
140
+ size: number;
141
+ };
142
+ featureIds: {
143
+ value: Uint16Array | Uint32Array;
144
+ size: number;
145
+ };
146
+ numericProps: object;
147
+ properties: {}[];
148
+ fields: {
149
+ id?: number | undefined;
150
+ }[];
151
+ };
152
+ polygons: {
153
+ polygonIndices: {
154
+ value: Uint16Array | Uint32Array;
155
+ size: number;
156
+ };
157
+ primitivePolygonIndices: {
158
+ value: Uint16Array | Uint32Array;
159
+ size: number;
160
+ };
161
+ positions: {
162
+ value: Float32Array;
163
+ size: number;
164
+ };
165
+ triangles: {
166
+ value: Uint32Array;
167
+ size: number;
168
+ };
169
+ globalFeatureIds: {
170
+ value: Uint16Array | Uint32Array;
171
+ size: number;
172
+ };
173
+ featureIds: {
174
+ value: Uint16Array | Uint32Array;
175
+ size: number;
176
+ };
177
+ numericProps: object;
178
+ properties: {}[];
179
+ fields: {
180
+ id?: number | undefined;
181
+ }[];
182
+ };
183
+ };
184
+ export {};
185
+ //# sourceMappingURL=features-to-binary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features-to-binary.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EAEpB,gBAAgB,EAChB,kBAAkB,EAInB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,CAAC,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAM3B;AAED,eAAO,MAAM,YAAY;;;CAGxB,CAAC;AAEF;;;;;GAKG;AACH,iBAAS,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,CAkB1E;AAED;;;;;;;GAOG;AAEH,iBAAS,UAAU,CACjB,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoI1B"}