@loaders.gl/mvt 4.0.0-alpha.23 → 4.0.0-alpha.25

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/dist.min.js +7 -6
  2. package/dist/es5/index.js.map +1 -1
  3. package/dist/es5/lib/parse-mvt.js +6 -5
  4. package/dist/es5/lib/parse-mvt.js.map +1 -1
  5. package/dist/es5/lib/types.js.map +1 -1
  6. package/dist/es5/mvt-loader.js +1 -1
  7. package/dist/es5/mvt-loader.js.map +1 -1
  8. package/dist/esm/index.js.map +1 -1
  9. package/dist/esm/lib/parse-mvt.js +6 -5
  10. package/dist/esm/lib/parse-mvt.js.map +1 -1
  11. package/dist/esm/lib/types.js.map +1 -1
  12. package/dist/esm/mvt-loader.js +1 -1
  13. package/dist/esm/mvt-loader.js.map +1 -1
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/lib/parse-mvt.d.ts +3 -3
  17. package/dist/lib/parse-mvt.d.ts.map +1 -1
  18. package/dist/lib/types.d.ts +4 -4
  19. package/dist/lib/types.d.ts.map +1 -1
  20. package/dist/mvt-loader.d.ts +2 -2
  21. package/dist/mvt-loader.d.ts.map +1 -1
  22. package/dist/mvt-worker.js +8 -7
  23. package/package.json +5 -5
  24. package/src/index.ts +1 -0
  25. package/src/lib/parse-mvt.ts +12 -9
  26. package/src/lib/types.ts +4 -4
  27. package/src/mvt-loader.ts +4 -4
  28. package/dist/bundle.js +0 -5
  29. package/dist/helpers/binary-util-functions.js +0 -118
  30. package/dist/helpers/mapbox-util-functions.js +0 -82
  31. package/dist/index.js +0 -9
  32. package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -156
  33. package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -91
  34. package/dist/lib/binary-vector-tile/vector-tile.js +0 -29
  35. package/dist/lib/geojson-tiler/clip.js +0 -209
  36. package/dist/lib/geojson-tiler/convert.js +0 -134
  37. package/dist/lib/geojson-tiler/feature.js +0 -46
  38. package/dist/lib/geojson-tiler/geojson-tiler.js +0 -210
  39. package/dist/lib/geojson-tiler/simplify.js +0 -68
  40. package/dist/lib/geojson-tiler/tile.js +0 -125
  41. package/dist/lib/geojson-tiler/transform.js +0 -43
  42. package/dist/lib/geojson-tiler/wrap.js +0 -86
  43. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -170
  44. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +0 -89
  45. package/dist/lib/mapbox-vector-tile/vector-tile.js +0 -29
  46. package/dist/lib/parse-mvt.js +0 -167
  47. package/dist/lib/types.js +0 -2
  48. package/dist/mvt-loader.js +0 -53
  49. package/dist/workers/mvt-worker.js +0 -5
@@ -1,125 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.createTile = void 0;
6
- /**
7
- * Create a tile from features and tile index
8
- */
9
- function createTile(features, z, tx, ty, options) {
10
- const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
11
- const tile = {
12
- features: [],
13
- numPoints: 0,
14
- numSimplified: 0,
15
- numFeatures: features.length,
16
- source: null,
17
- x: tx,
18
- y: ty,
19
- z,
20
- transformed: false,
21
- minX: 2,
22
- minY: 1,
23
- maxX: -1,
24
- maxY: 0
25
- };
26
- for (const feature of features) {
27
- addFeature(tile, feature, tolerance, options);
28
- }
29
- return tile;
30
- }
31
- exports.createTile = createTile;
32
- // eslint-disable-next-line complexity, max-statements
33
- function addFeature(tile, feature, tolerance, options) {
34
- const geom = feature.geometry;
35
- const type = feature.type;
36
- const simplified = [];
37
- tile.minX = Math.min(tile.minX, feature.minX);
38
- tile.minY = Math.min(tile.minY, feature.minY);
39
- tile.maxX = Math.max(tile.maxX, feature.maxX);
40
- tile.maxY = Math.max(tile.maxY, feature.maxY);
41
- if (type === 'Point' || type === 'MultiPoint') {
42
- for (let i = 0; i < geom.length; i += 3) {
43
- simplified.push(geom[i], geom[i + 1]);
44
- tile.numPoints++;
45
- tile.numSimplified++;
46
- }
47
- }
48
- else if (type === 'LineString') {
49
- addLine(simplified, geom, tile, tolerance, false, false);
50
- }
51
- else if (type === 'MultiLineString' || type === 'Polygon') {
52
- for (let i = 0; i < geom.length; i++) {
53
- addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
54
- }
55
- }
56
- else if (type === 'MultiPolygon') {
57
- for (let k = 0; k < geom.length; k++) {
58
- const polygon = geom[k];
59
- for (let i = 0; i < polygon.length; i++) {
60
- addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
61
- }
62
- }
63
- }
64
- if (simplified.length) {
65
- let tags = feature.tags || null;
66
- if (type === 'LineString' && options.lineMetrics) {
67
- tags = {};
68
- for (const key in feature.tags)
69
- tags[key] = feature.tags[key];
70
- // eslint-disable-next-line camelcase
71
- tags.mapbox_clip_start = geom.start / geom.size;
72
- // eslint-disable-next-line camelcase
73
- tags.mapbox_clip_end = geom.end / geom.size;
74
- }
75
- // @ts-expect-error TODO - create sub type?
76
- const tileFeature = {
77
- geometry: simplified,
78
- type: type === 'Polygon' || type === 'MultiPolygon'
79
- ? 3
80
- : type === 'LineString' || type === 'MultiLineString'
81
- ? 2
82
- : 1,
83
- tags
84
- };
85
- if (feature.id !== null) {
86
- tileFeature.id = feature.id;
87
- }
88
- tile.features.push(tileFeature);
89
- }
90
- }
91
- // eslint-disable-next-line max-params, max-statements
92
- function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
93
- const sqTolerance = tolerance * tolerance;
94
- if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
95
- tile.numPoints += geom.length / 3;
96
- return;
97
- }
98
- const ring = [];
99
- for (let i = 0; i < geom.length; i += 3) {
100
- if (tolerance === 0 || geom[i + 2] > sqTolerance) {
101
- tile.numSimplified++;
102
- ring.push(geom[i], geom[i + 1]);
103
- }
104
- tile.numPoints++;
105
- }
106
- if (isPolygon)
107
- rewind(ring, isOuter);
108
- result.push(ring);
109
- }
110
- function rewind(ring, clockwise) {
111
- let area = 0;
112
- for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
113
- area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
114
- }
115
- if (area > 0 === clockwise) {
116
- for (let i = 0, len = ring.length; i < len / 2; i += 2) {
117
- const x = ring[i];
118
- const y = ring[i + 1];
119
- ring[i] = ring[len - 2 - i];
120
- ring[i + 1] = ring[len - 1 - i];
121
- ring[len - 2 - i] = x;
122
- ring[len - 1 - i] = y;
123
- }
124
- }
125
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.transformTile = void 0;
6
- /**
7
- * Transforms the coordinates of each feature in the given tile from
8
- * mercator-projected space into (extent x extent) tile space.
9
- */
10
- function transformTile(tile, extent) {
11
- if (tile.transformed) {
12
- return tile;
13
- }
14
- const z2 = 1 << tile.z;
15
- const tx = tile.x;
16
- const ty = tile.y;
17
- for (const feature of tile.features) {
18
- const geom = feature.geometry;
19
- const type = feature.type;
20
- feature.geometry = [];
21
- if (type === 1) {
22
- for (let j = 0; j < geom.length; j += 2) {
23
- feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
24
- }
25
- }
26
- else {
27
- for (let j = 0; j < geom.length; j++) {
28
- const ring = [];
29
- for (let k = 0; k < geom[j].length; k += 2) {
30
- ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
31
- }
32
- feature.geometry.push(ring);
33
- }
34
- }
35
- }
36
- tile.transformed = true;
37
- return tile;
38
- }
39
- exports.transformTile = transformTile;
40
- // eslint-disable-next-line max-params
41
- function transformPoint(x, y, extent, z2, tx, ty) {
42
- return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
43
- }
@@ -1,86 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.wrap = void 0;
6
- const clip_1 = require("./clip");
7
- const feature_1 = require("./feature");
8
- /**
9
- * Wrap across antemeridian, by clipping into two tiles, shifting the overflowing x coordinates
10
- * @param features list of features to be wrapped
11
- * @param options buffer and extent
12
- * @returns
13
- */
14
- function wrap(features, options) {
15
- const buffer = options.buffer / options.extent;
16
- let merged = features;
17
- const left = (0, clip_1.clip)(features, 1, -1 - buffer, buffer, 0, -1, 2, options); // left world copy
18
- const right = (0, clip_1.clip)(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options); // right world copy
19
- if (left || right) {
20
- merged = (0, clip_1.clip)(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || []; // center world copy
21
- if (left) {
22
- merged = shiftFeatureCoords(left, 1).concat(merged); // merge left into center
23
- }
24
- if (right) {
25
- merged = merged.concat(shiftFeatureCoords(right, -1)); // merge right into center
26
- }
27
- }
28
- return merged;
29
- }
30
- exports.wrap = wrap;
31
- /**
32
- * Shift the x coordinates of a list of features
33
- * @param features list of features to shift x coordinates for
34
- * @param offset
35
- * @returns
36
- */
37
- function shiftFeatureCoords(features, offset) {
38
- const newFeatures = [];
39
- for (let i = 0; i < features.length; i++) {
40
- const feature = features[i];
41
- const type = feature.type;
42
- let newGeometry;
43
- if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
44
- newGeometry = shiftCoords(feature.geometry, offset);
45
- }
46
- else if (type === 'MultiLineString' || type === 'Polygon') {
47
- newGeometry = [];
48
- for (const line of feature.geometry) {
49
- newGeometry.push(shiftCoords(line, offset));
50
- }
51
- }
52
- else if (type === 'MultiPolygon') {
53
- newGeometry = [];
54
- for (const polygon of feature.geometry) {
55
- const newPolygon = [];
56
- for (const line of polygon) {
57
- // @ts-expect-error TODO
58
- newPolygon.push(shiftCoords(line, offset));
59
- }
60
- newGeometry.push(newPolygon);
61
- }
62
- }
63
- newFeatures.push((0, feature_1.createFeature)(feature.id, type, newGeometry, feature.tags));
64
- }
65
- return newFeatures;
66
- }
67
- class Points extends Array {
68
- }
69
- /**
70
- * Shift the x coordinate of every point
71
- * @param points
72
- * @param offset
73
- * @returns
74
- */
75
- function shiftCoords(points, offset) {
76
- const newPoints = [];
77
- newPoints.size = points.size;
78
- if (points.start !== undefined) {
79
- newPoints.start = points.start;
80
- newPoints.end = points.end;
81
- }
82
- for (let i = 0; i < points.length; i += 3) {
83
- newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
84
- }
85
- return newPoints;
86
- }
@@ -1,170 +0,0 @@
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
- static get types() {
6
- return ['Unknown', 'Point', 'LineString', 'Polygon'];
7
- }
8
- constructor(pbf, end, extent, keys, values) {
9
- // Public
10
- this.properties = {};
11
- this.extent = extent;
12
- this.type = 0;
13
- this.id = null;
14
- // Private
15
- this._pbf = pbf;
16
- this._geometry = -1;
17
- this._keys = keys;
18
- this._values = values;
19
- pbf.readFields(mapbox_util_functions_1.readFeature, this, end);
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;
@@ -1,89 +0,0 @@
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
- }
@@ -1,29 +0,0 @@
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
- }