@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,167 +0,0 @@
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
- const gis_1 = require("@loaders.gl/gis");
7
- const pbf_1 = __importDefault(require("pbf"));
8
- const vector_tile_1 = __importDefault(require("./mapbox-vector-tile/vector-tile"));
9
- const vector_tile_2 = __importDefault(require("./binary-vector-tile/vector-tile"));
10
- /**
11
- * Parse MVT arrayBuffer and return GeoJSON.
12
- *
13
- * @param arrayBuffer A MVT arrayBuffer
14
- * @param options
15
- * @returns A GeoJSON geometry object or a binary representation
16
- */
17
- function parseMVT(arrayBuffer, options) {
18
- const mvtOptions = normalizeOptions(options);
19
- const shape = options?.gis?.format || options?.mvt?.shape;
20
- switch (shape) {
21
- case 'columnar-table': // binary + some JS arrays
22
- return { shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions) };
23
- case 'geojson-row-table': {
24
- const table = {
25
- shape: 'geojson-row-table',
26
- data: parseToGeojson(arrayBuffer, mvtOptions)
27
- };
28
- return table;
29
- }
30
- case 'geojson':
31
- return parseToGeojson(arrayBuffer, mvtOptions);
32
- case 'binary-geometry':
33
- return parseToBinary(arrayBuffer, mvtOptions);
34
- case 'binary':
35
- return parseToBinary(arrayBuffer, mvtOptions);
36
- default:
37
- throw new Error(shape);
38
- }
39
- }
40
- exports.default = parseMVT;
41
- function parseToBinary(arrayBuffer, options) {
42
- const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);
43
- const binaryData = (0, gis_1.flatGeojsonToBinary)(flatGeoJsonFeatures, geometryInfo);
44
- // Add the original byteLength (as a reasonable approximation of the size of the binary data)
45
- // TODO decide where to store extra fields like byteLength (header etc) and document
46
- // @ts-ignore
47
- binaryData.byteLength = arrayBuffer.byteLength;
48
- return binaryData;
49
- }
50
- function parseToFlatGeoJson(arrayBuffer, options) {
51
- const features = [];
52
- const geometryInfo = {
53
- coordLength: 2,
54
- pointPositionsCount: 0,
55
- pointFeaturesCount: 0,
56
- linePositionsCount: 0,
57
- linePathsCount: 0,
58
- lineFeaturesCount: 0,
59
- polygonPositionsCount: 0,
60
- polygonObjectsCount: 0,
61
- polygonRingsCount: 0,
62
- polygonFeaturesCount: 0
63
- };
64
- if (arrayBuffer.byteLength <= 0) {
65
- return [features, geometryInfo];
66
- }
67
- const tile = new vector_tile_2.default(new pbf_1.default(arrayBuffer));
68
- const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
69
- selectedLayers.forEach((layerName) => {
70
- const vectorTileLayer = tile.layers[layerName];
71
- if (!vectorTileLayer) {
72
- return;
73
- }
74
- for (let i = 0; i < vectorTileLayer.length; i++) {
75
- const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
76
- const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
77
- features.push(decodedFeature);
78
- }
79
- });
80
- return [features, geometryInfo];
81
- }
82
- function parseToGeojson(arrayBuffer, options) {
83
- if (arrayBuffer.byteLength <= 0) {
84
- return [];
85
- }
86
- const features = [];
87
- const tile = new vector_tile_1.default(new pbf_1.default(arrayBuffer));
88
- const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
89
- selectedLayers.forEach((layerName) => {
90
- const vectorTileLayer = tile.layers[layerName];
91
- if (!vectorTileLayer) {
92
- return;
93
- }
94
- for (let i = 0; i < vectorTileLayer.length; i++) {
95
- const vectorTileFeature = vectorTileLayer.feature(i);
96
- const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
97
- features.push(decodedFeature);
98
- }
99
- });
100
- return features;
101
- }
102
- function normalizeOptions(options) {
103
- if (!options?.mvt) {
104
- throw new Error('mvt options required');
105
- }
106
- // Validate
107
- const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';
108
- const { tileIndex } = options.mvt;
109
- const hasTileIndex = tileIndex &&
110
- Number.isFinite(tileIndex.x) &&
111
- Number.isFinite(tileIndex.y) &&
112
- Number.isFinite(tileIndex.z);
113
- if (wgs84Coordinates && !hasTileIndex) {
114
- throw new Error('MVT Loader: WGS84 coordinates need tileIndex property');
115
- }
116
- return options.mvt;
117
- }
118
- /**
119
- * @param feature
120
- * @param options
121
- * @returns decoded feature
122
- */
123
- function getDecodedFeature(feature, options, layerName) {
124
- const decodedFeature = feature.toGeoJSON(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
125
- // Add layer name to GeoJSON properties
126
- if (options.layerProperty) {
127
- decodedFeature.properties[options.layerProperty] = layerName;
128
- }
129
- return decodedFeature;
130
- }
131
- /**
132
- * @param feature
133
- * @param options
134
- * @returns decoded binary feature
135
- */
136
- function getDecodedFeatureBinary(feature, options, layerName) {
137
- const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
138
- // Add layer name to GeoJSON properties
139
- if (options.layerProperty && decodedFeature.properties) {
140
- decodedFeature.properties[options.layerProperty] = layerName;
141
- }
142
- return decodedFeature;
143
- }
144
- /**
145
- * @param line
146
- * @param feature
147
- */
148
- function transformToLocalCoordinates(line, feature) {
149
- // This function transforms local coordinates in a
150
- // [0 - bufferSize, this.extent + bufferSize] range to a
151
- // [0 - (bufferSize / this.extent), 1 + (bufferSize / this.extent)] range.
152
- // The resulting extent would be 1.
153
- const { extent } = feature;
154
- for (let i = 0; i < line.length; i++) {
155
- const p = line[i];
156
- p[0] /= extent;
157
- p[1] /= extent;
158
- }
159
- }
160
- function transformToLocalCoordinatesBinary(data, feature) {
161
- // For the binary code path, the feature data is just
162
- // one big flat array, so we just divide each value
163
- const { extent } = feature;
164
- for (let i = 0, il = data.length; i < il; ++i) {
165
- data[i] /= extent;
166
- }
167
- }
package/dist/lib/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,53 +0,0 @@
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
- exports.MVTLoader = exports.MVTWorkerLoader = void 0;
7
- // import type {
8
- // Feature,
9
- // BinaryFeatures,
10
- // GeoJSONRowTable,
11
- // Geometry,
12
- // GeoJsonProperties
13
- // } from '@loaders.gl/schema';
14
- const parse_mvt_1 = __importDefault(require("./lib/parse-mvt"));
15
- // __VERSION__ is injected by babel-plugin-version-inline
16
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
17
- const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
18
- /**
19
- * Worker loader for the Mapbox Vector Tile format
20
- */
21
- exports.MVTWorkerLoader = {
22
- name: 'Mapbox Vector Tile',
23
- id: 'mvt',
24
- module: 'mvt',
25
- version: VERSION,
26
- // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
27
- extensions: ['mvt', 'pbf'],
28
- mimeTypes: [
29
- 'application/vnd.mapbox-vector-tile',
30
- 'application/x-protobuf'
31
- // 'application/octet-stream'
32
- ],
33
- worker: true,
34
- category: 'geometry',
35
- options: {
36
- mvt: {
37
- shape: 'geojson',
38
- coordinates: 'local',
39
- layerProperty: 'layerName',
40
- layers: undefined,
41
- tileIndex: null
42
- }
43
- }
44
- };
45
- /**
46
- * Loader for the Mapbox Vector Tile format
47
- */
48
- exports.MVTLoader = {
49
- ...exports.MVTWorkerLoader,
50
- parse: async (arrayBuffer, options) => (0, parse_mvt_1.default)(arrayBuffer, options),
51
- parseSync: parse_mvt_1.default,
52
- binary: true
53
- };
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const mvt_loader_1 = require("../mvt-loader");
4
- const loader_utils_1 = require("@loaders.gl/loader-utils");
5
- (0, loader_utils_1.createLoaderWorker)(mvt_loader_1.MVTLoader);