@loaders.gl/mvt 3.4.10 → 3.4.12

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.
@@ -11,7 +11,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
11
11
  var _parseMvt = _interopRequireDefault(require("./lib/parse-mvt"));
12
12
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
13
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
14
- var VERSION = typeof "3.4.10" !== 'undefined' ? "3.4.10" : 'latest';
14
+ var VERSION = typeof "3.4.12" !== 'undefined' ? "3.4.12" : 'latest';
15
15
  var DEFAULT_MVT_LOADER_OPTIONS = {
16
16
  mvt: {
17
17
  shape: 'geojson',
@@ -1,5 +1,5 @@
1
1
  import parseMVT from './lib/parse-mvt';
2
- const VERSION = typeof "3.4.10" !== 'undefined' ? "3.4.10" : 'latest';
2
+ const VERSION = typeof "3.4.12" !== 'undefined' ? "3.4.12" : 'latest';
3
3
  const DEFAULT_MVT_LOADER_OPTIONS = {
4
4
  mvt: {
5
5
  shape: 'geojson',
@@ -2154,7 +2154,7 @@
2154
2154
  }
2155
2155
 
2156
2156
  // src/mvt-loader.ts
2157
- var VERSION = true ? "3.4.10" : "latest";
2157
+ var VERSION = true ? "3.4.12" : "latest";
2158
2158
  var DEFAULT_MVT_LOADER_OPTIONS = {
2159
2159
  mvt: {
2160
2160
  shape: "geojson",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loaders.gl/mvt",
3
3
  "description": "Loader for Mapbox Vector Tiles",
4
- "version": "3.4.10",
4
+ "version": "3.4.12",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -32,14 +32,14 @@
32
32
  "build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
33
33
  },
34
34
  "dependencies": {
35
- "@loaders.gl/gis": "3.4.10",
36
- "@loaders.gl/loader-utils": "3.4.10",
37
- "@loaders.gl/schema": "3.4.10",
35
+ "@loaders.gl/gis": "3.4.12",
36
+ "@loaders.gl/loader-utils": "3.4.12",
37
+ "@loaders.gl/schema": "3.4.12",
38
38
  "@math.gl/polygon": "^3.5.1",
39
39
  "pbf": "^3.2.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/pbf": "^3.0.2"
43
43
  },
44
- "gitHead": "4568459c96eaf0480a50ab77cace355307f61f04"
44
+ "gitHead": "85254762ae3082f608a863291deef09f2b40c6cf"
45
45
  }
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
@@ -1,118 +0,0 @@
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.indices.length;
17
- const type = 'Polygon';
18
- if (len <= 1) {
19
- return {
20
- type,
21
- data: geom.data,
22
- areas: [[(0, polygon_1.getPolygonSignedArea)(geom.data)]],
23
- indices: [geom.indices]
24
- };
25
- }
26
- const areas = [];
27
- const polygons = [];
28
- let ringAreas = [];
29
- let polygon = [];
30
- let ccw;
31
- let offset = 0;
32
- for (let endIndex, i = 0, startIndex; i < len; i++) {
33
- startIndex = geom.indices[i] - offset;
34
- endIndex = geom.indices[i + 1] - offset || geom.data.length;
35
- const shape = geom.data.slice(startIndex, endIndex);
36
- const area = (0, polygon_1.getPolygonSignedArea)(shape);
37
- if (area === 0) {
38
- // This polygon has no area, so remove it from the shape
39
- // Remove the section from the data array
40
- const before = geom.data.slice(0, startIndex);
41
- const after = geom.data.slice(endIndex);
42
- geom.data = before.concat(after);
43
- // Need to offset any remaining indices as we have
44
- // modified the data buffer
45
- offset += endIndex - startIndex;
46
- // Do not add this index to the output and process next shape
47
- continue; // eslint-disable-line no-continue
48
- }
49
- if (ccw === undefined)
50
- ccw = area < 0;
51
- if (ccw === area < 0) {
52
- if (polygon.length) {
53
- areas.push(ringAreas);
54
- polygons.push(polygon);
55
- }
56
- polygon = [startIndex];
57
- ringAreas = [area];
58
- }
59
- else {
60
- ringAreas.push(area);
61
- polygon.push(startIndex);
62
- }
63
- }
64
- if (ringAreas)
65
- areas.push(ringAreas);
66
- if (polygon.length)
67
- polygons.push(polygon);
68
- return { type, areas, indices: polygons, data: geom.data };
69
- }
70
- exports.classifyRings = classifyRings;
71
- /**
72
- *
73
- * @param data
74
- * @param x0
75
- * @param y0
76
- * @param size
77
- */
78
- function project(data, x0, y0, size) {
79
- for (let j = 0, jl = data.length; j < jl; j += 2) {
80
- data[j] = ((data[j] + x0) * 360) / size - 180;
81
- const y2 = 180 - ((data[j + 1] + y0) * 360) / size;
82
- data[j + 1] = (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
83
- }
84
- }
85
- exports.project = project;
86
- /**
87
- * All code below is unchanged from the original Mapbox implemenation
88
- *
89
- * @param tag
90
- * @param feature
91
- * @param pbf
92
- */
93
- function readFeature(tag, feature, pbf) {
94
- if (feature && pbf) {
95
- if (tag === 1)
96
- feature.id = pbf.readVarint();
97
- else if (tag === 2)
98
- readTag(pbf, feature);
99
- else if (tag === 3)
100
- feature.type = pbf.readVarint();
101
- else if (tag === 4)
102
- feature._geometry = pbf.pos;
103
- }
104
- }
105
- exports.readFeature = readFeature;
106
- /**
107
- * @param pbf
108
- * @param feature
109
- */
110
- function readTag(pbf, feature) {
111
- const end = pbf.readVarint() + pbf.pos;
112
- while (pbf.pos < end) {
113
- const key = feature._keys[pbf.readVarint()];
114
- const value = feature._values[pbf.readVarint()];
115
- feature.properties[key] = value;
116
- }
117
- }
118
- exports.readTag = readTag;
@@ -1,82 +0,0 @@
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;
package/dist/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.GeoJSONTiler = exports.MVTWorkerLoader = exports.MVTLoader = void 0;
5
- var mvt_loader_1 = require("./mvt-loader");
6
- Object.defineProperty(exports, "MVTLoader", { enumerable: true, get: function () { return mvt_loader_1.MVTLoader; } });
7
- Object.defineProperty(exports, "MVTWorkerLoader", { enumerable: true, get: function () { return mvt_loader_1.MVTWorkerLoader; } });
8
- var geojson_tiler_1 = require("./lib/geojson-tiler/geojson-tiler");
9
- Object.defineProperty(exports, "GeoJSONTiler", { enumerable: true, get: function () { return geojson_tiler_1.GeoJSONTiler; } });
@@ -1,156 +0,0 @@
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
7
- let endPos;
8
- let cmd;
9
- let cmdLen;
10
- let length;
11
- let x;
12
- let y;
13
- let i;
14
- exports.TEST_EXPORTS = {
15
- classifyRings: binary_util_functions_1.classifyRings
16
- };
17
- class VectorTileFeature {
18
- // eslint-disable-next-line max-params
19
- constructor(pbf, end, extent, keys, values, geometryInfo) {
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._geometryInfo = geometryInfo;
31
- pbf.readFields(binary_util_functions_1.readFeature, this, end);
32
- }
33
- // eslint-disable-next-line complexity, max-statements
34
- loadGeometry() {
35
- const pbf = this._pbf;
36
- pbf.pos = this._geometry;
37
- endPos = pbf.readVarint() + pbf.pos;
38
- cmd = 1;
39
- length = 0;
40
- x = 0;
41
- y = 0;
42
- i = 0;
43
- // Note: I attempted to replace the `data` array with a
44
- // Float32Array, but performance was worse, both using
45
- // `set()` and direct index access. Also, we cannot
46
- // know how large the buffer should be, so it would
47
- // increase memory usage
48
- const indices = []; // Indices where geometries start
49
- const data = []; // Flat array of coordinate data
50
- while (pbf.pos < endPos) {
51
- if (length <= 0) {
52
- cmdLen = pbf.readVarint();
53
- cmd = cmdLen & 0x7;
54
- length = cmdLen >> 3;
55
- }
56
- length--;
57
- if (cmd === 1 || cmd === 2) {
58
- x += pbf.readSVarint();
59
- y += pbf.readSVarint();
60
- if (cmd === 1) {
61
- // New line
62
- indices.push(i);
63
- }
64
- data.push(x, y);
65
- i += 2;
66
- }
67
- else if (cmd === 7) {
68
- // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
69
- if (i > 0) {
70
- const start = indices[indices.length - 1]; // start index of polygon
71
- data.push(data[start], data[start + 1]); // closePolygon
72
- i += 2;
73
- }
74
- }
75
- else {
76
- throw new Error(`unknown command ${cmd}`);
77
- }
78
- }
79
- return { data, indices };
80
- }
81
- /**
82
- *
83
- * @param transform
84
- * @returns result
85
- */
86
- _toBinaryCoordinates(transform) {
87
- // Expands the protobuf data to an intermediate Flat GeoJSON
88
- // data format, which maps closely to the binary data buffers.
89
- // It is similar to GeoJSON, but rather than storing the coordinates
90
- // in multidimensional arrays, we have a 1D `data` with all the
91
- // coordinates, and then index into this using the `indices`
92
- // parameter, e.g.
93
- //
94
- // geometry: {
95
- // type: 'Point', data: [1,2], indices: [0]
96
- // }
97
- // geometry: {
98
- // type: 'LineString', data: [1,2,3,4,...], indices: [0]
99
- // }
100
- // geometry: {
101
- // type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
102
- // }
103
- // Thus the indices member lets us look up the relevant range
104
- // from the data array.
105
- // The Multi* versions of the above types share the same data
106
- // structure, just with multiple elements in the indices array
107
- const geom = this.loadGeometry();
108
- let geometry;
109
- // Apply the supplied transformation to data
110
- transform(geom.data, this);
111
- const coordLength = 2;
112
- // eslint-disable-next-line default-case
113
- switch (this.type) {
114
- case 1: // Point
115
- this._geometryInfo.pointFeaturesCount++;
116
- this._geometryInfo.pointPositionsCount += geom.indices.length;
117
- geometry = { type: 'Point', ...geom };
118
- break;
119
- case 2: // LineString
120
- this._geometryInfo.lineFeaturesCount++;
121
- this._geometryInfo.linePathsCount += geom.indices.length;
122
- this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
123
- geometry = { type: 'LineString', ...geom };
124
- break;
125
- case 3: // Polygon
126
- geometry = (0, binary_util_functions_1.classifyRings)(geom);
127
- // Unlike Point & LineString geom.indices is a 2D array, thanks
128
- // to the classifyRings method
129
- this._geometryInfo.polygonFeaturesCount++;
130
- this._geometryInfo.polygonObjectsCount += geometry.indices.length;
131
- for (const indices of geometry.indices) {
132
- this._geometryInfo.polygonRingsCount += indices.length;
133
- }
134
- this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
135
- break;
136
- default:
137
- throw new Error(`Invalid geometry type: ${this.type}`);
138
- }
139
- const result = { type: 'Feature', geometry, properties: this.properties };
140
- if (this.id !== null) {
141
- result.id = this.id;
142
- }
143
- return result;
144
- }
145
- toBinaryCoordinates(options) {
146
- if (typeof options === 'function') {
147
- return this._toBinaryCoordinates(options);
148
- }
149
- const { x, y, z } = options;
150
- const size = this.extent * Math.pow(2, z);
151
- const x0 = this.extent * x;
152
- const y0 = this.extent * y;
153
- return this._toBinaryCoordinates((data) => (0, binary_util_functions_1.project)(data, x0, y0, size));
154
- }
155
- }
156
- exports.default = VectorTileFeature;
@@ -1,91 +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
- *
27
- * @param index
28
- * @param geometryInfo
29
- * @returns {VectorTileFeature}
30
- */
31
- feature(i, geometryInfo) {
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, geometryInfo);
38
- }
39
- }
40
- exports.default = VectorTileLayer;
41
- /**
42
- *
43
- * @param tag
44
- * @param layer
45
- * @param pbf
46
- */
47
- function readLayer(tag, layer, pbf) {
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
- }
62
- }
63
- /**
64
- *
65
- * @param pbf
66
- * @returns value
67
- */
68
- function readValueMessage(pbf) {
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;
91
- }
@@ -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
- }