@loaders.gl/mvt 4.3.0-alpha.1 → 4.3.0-alpha.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 (93) hide show
  1. package/dist/dist.dev.js +1289 -807
  2. package/dist/dist.min.js +1 -1
  3. package/dist/index.cjs +923 -773
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +7 -6
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +6 -2
  8. package/dist/lib/parse-mvt.d.ts +1 -1
  9. package/dist/lib/parse-mvt.js +2 -30
  10. package/dist/lib/parse-tilejson.d.ts +4 -4
  11. package/dist/lib/parse-tilejson.d.ts.map +1 -1
  12. package/dist/lib/parse-tilejson.js +1 -1
  13. package/dist/lib/utils/geometry-utils.d.ts +38 -1
  14. package/dist/lib/utils/geometry-utils.d.ts.map +1 -1
  15. package/dist/lib/utils/geometry-utils.js +65 -6
  16. package/dist/lib/vector-tile/vector-tile-feature.d.ts +28 -9
  17. package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -1
  18. package/dist/lib/vector-tile/vector-tile-feature.js +47 -50
  19. package/dist/lib/{geojsonvt/clip.d.ts → vector-tiler/features/clip-features.d.ts} +4 -4
  20. package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
  21. package/dist/lib/{geojsonvt/clip.js → vector-tiler/features/clip-features.js} +4 -4
  22. package/dist/lib/vector-tiler/features/convert-feature.d.ts +18 -0
  23. package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
  24. package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
  25. package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
  26. package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
  27. package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
  28. package/dist/lib/{geojsonvt/simplify.d.ts → vector-tiler/features/simplify-path.d.ts} +2 -2
  29. package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
  30. package/dist/lib/{geojsonvt/simplify.js → vector-tiler/features/simplify-path.js} +3 -3
  31. package/dist/lib/{geojsonvt/wrap.d.ts → vector-tiler/features/wrap-features.d.ts} +5 -5
  32. package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
  33. package/dist/lib/{geojsonvt/wrap.js → vector-tiler/features/wrap-features.js} +33 -26
  34. package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
  35. package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
  36. package/dist/lib/vector-tiler/proto-tile.js +138 -0
  37. package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
  38. package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
  39. package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
  40. package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
  41. package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
  42. package/dist/lib/vector-tiler/transform-tile.js +41 -0
  43. package/dist/mvt-loader.d.ts +1 -1
  44. package/dist/mvt-loader.js +1 -1
  45. package/dist/mvt-source.d.ts +35 -18
  46. package/dist/mvt-source.d.ts.map +1 -1
  47. package/dist/mvt-source.js +30 -10
  48. package/dist/mvt-worker.js +101 -56
  49. package/dist/table-tile-source.d.ts +148 -0
  50. package/dist/table-tile-source.d.ts.map +1 -0
  51. package/dist/table-tile-source.js +420 -0
  52. package/dist/tilejson-loader.js +1 -1
  53. package/package.json +7 -6
  54. package/src/index.ts +14 -7
  55. package/src/lib/parse-mvt.ts +4 -33
  56. package/src/lib/parse-tilejson.ts +6 -6
  57. package/src/lib/utils/geometry-utils.ts +66 -1
  58. package/src/lib/vector-tile/vector-tile-feature.ts +65 -56
  59. package/src/lib/{geojsonvt/clip.ts → vector-tiler/features/clip-features.ts} +8 -8
  60. package/src/lib/vector-tiler/features/convert-feature.ts +191 -0
  61. package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
  62. package/src/lib/{geojsonvt/simplify.ts → vector-tiler/features/simplify-path.ts} +8 -3
  63. package/src/lib/{geojsonvt/wrap.ts → vector-tiler/features/wrap-features.ts} +44 -29
  64. package/src/lib/vector-tiler/proto-tile.ts +217 -0
  65. package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
  66. package/src/lib/vector-tiler/transform-tile.ts +57 -0
  67. package/src/mvt-source.ts +47 -24
  68. package/src/table-tile-source.ts +553 -0
  69. package/src/tilejson-loader.ts +2 -2
  70. package/dist/geojson-tile-source.d.ts +0 -79
  71. package/dist/geojson-tile-source.d.ts.map +0 -1
  72. package/dist/geojson-tile-source.js +0 -319
  73. package/dist/lib/geojsonvt/clip.d.ts.map +0 -1
  74. package/dist/lib/geojsonvt/convert.d.ts +0 -10
  75. package/dist/lib/geojsonvt/convert.d.ts.map +0 -1
  76. package/dist/lib/geojsonvt/convert.js +0 -132
  77. package/dist/lib/geojsonvt/feature.d.ts +0 -3
  78. package/dist/lib/geojsonvt/feature.d.ts.map +0 -1
  79. package/dist/lib/geojsonvt/feature.js +0 -44
  80. package/dist/lib/geojsonvt/simplify.d.ts.map +0 -1
  81. package/dist/lib/geojsonvt/tile.d.ts +0 -38
  82. package/dist/lib/geojsonvt/tile.d.ts.map +0 -1
  83. package/dist/lib/geojsonvt/tile.js +0 -123
  84. package/dist/lib/geojsonvt/transform.d.ts +0 -7
  85. package/dist/lib/geojsonvt/transform.d.ts.map +0 -1
  86. package/dist/lib/geojsonvt/transform.js +0 -41
  87. package/dist/lib/geojsonvt/wrap.d.ts.map +0 -1
  88. package/src/geojson-tile-source.ts +0 -422
  89. package/src/lib/geojsonvt/convert.ts +0 -160
  90. package/src/lib/geojsonvt/feature.ts +0 -47
  91. package/src/lib/geojsonvt/tile.ts +0 -187
  92. package/src/lib/geojsonvt/transform.ts +0 -57
  93. /package/src/lib/{geojsonvt → vector-tiler}/LICENSE +0 -0
@@ -1,160 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
5
-
6
- /* eslint-disable */
7
- // @ts-nocheck
8
-
9
- import type {Feature, FeatureCollection} from '@loaders.gl/schema';
10
- import type {GeoJSONTileFeature} from './tile';
11
-
12
- import {simplify} from './simplify';
13
- import {createFeature} from './feature';
14
-
15
- // converts GeoJSON feature into an intermediate projected JSON vector format with simplification data
16
-
17
- export function convert(data: Feature | FeatureCollection, options): GeoJSONTileFeature[] {
18
- const features = [];
19
- if (data.type === 'FeatureCollection') {
20
- for (let i = 0; i < data.features.length; i++) {
21
- convertFeature(features, data.features[i], options, i);
22
- }
23
- } else if (data.type === 'Feature') {
24
- convertFeature(features, data, options);
25
- } else {
26
- // single geometry or a geometry collection
27
- convertFeature(features, {geometry: data}, options);
28
- }
29
-
30
- return features;
31
- }
32
-
33
- export type ConvertFeatureOptions = {
34
- maxZoom?: number;
35
- tolerance: number;
36
- extent: number;
37
- lineMetrics: boolean;
38
- };
39
-
40
- function convertFeature(
41
- features: GeoJSONTileFeature[],
42
- geojson: Feature,
43
- options: ConvertFeatureOptions,
44
- index: number
45
- ): void {
46
- if (!geojson.geometry) {
47
- return;
48
- }
49
-
50
- const coords = geojson.geometry.coordinates;
51
- const type = geojson.geometry.type;
52
- const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
53
- let geometry = [];
54
- let id = geojson.id;
55
- if (options.promoteId) {
56
- id = geojson.properties[options.promoteId];
57
- } else if (options.generateId) {
58
- id = index || 0;
59
- }
60
- if (type === 'Point') {
61
- convertPoint(coords, geometry);
62
- } else if (type === 'MultiPoint') {
63
- for (const p of coords) {
64
- convertPoint(p, geometry);
65
- }
66
- } else if (type === 'LineString') {
67
- convertLine(coords, geometry, tolerance, false);
68
- } else if (type === 'MultiLineString') {
69
- if (options.lineMetrics) {
70
- // explode into linestrings to be able to track metrics
71
- for (const line of coords) {
72
- geometry = [];
73
- convertLine(line, geometry, tolerance, false);
74
- features.push(createFeature(id, 'LineString', geometry, geojson.properties));
75
- }
76
- return;
77
- } else {
78
- convertLines(coords, geometry, tolerance, false);
79
- }
80
- } else if (type === 'Polygon') {
81
- convertLines(coords, geometry, tolerance, true);
82
- } else if (type === 'MultiPolygon') {
83
- for (const polygon of coords) {
84
- const newPolygon = [];
85
- convertLines(polygon, newPolygon, tolerance, true);
86
- geometry.push(newPolygon);
87
- }
88
- } else if (type === 'GeometryCollection') {
89
- for (const singleGeometry of geojson.geometry.geometries) {
90
- convertFeature(
91
- features,
92
- {
93
- id,
94
- geometry: singleGeometry,
95
- properties: geojson.properties
96
- },
97
- options,
98
- index
99
- );
100
- }
101
- return;
102
- } else {
103
- throw new Error('Input data is not a valid GeoJSON object.');
104
- }
105
-
106
- features.push(createFeature(id, type, geometry, geojson.properties));
107
- }
108
-
109
- function convertPoint(coords, out): void {
110
- out.push(projectX(coords[0]), projectY(coords[1]), 0);
111
- }
112
-
113
- function convertLine(ring: number[], out, tolerance: number, isPolygon: boolean): void {
114
- let x0, y0;
115
- let size = 0;
116
-
117
- for (let j = 0; j < ring.length; j++) {
118
- const x = projectX(ring[j][0]);
119
- const y = projectY(ring[j][1]);
120
-
121
- out.push(x, y, 0);
122
-
123
- if (j > 0) {
124
- if (isPolygon) {
125
- size += (x0 * y - x * y0) / 2; // area
126
- } else {
127
- size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
128
- }
129
- }
130
- x0 = x;
131
- y0 = y;
132
- }
133
-
134
- const last = out.length - 3;
135
- out[2] = 1;
136
- simplify(out, 0, last, tolerance);
137
- out[last + 2] = 1;
138
-
139
- out.size = Math.abs(size);
140
- out.start = 0;
141
- out.end = out.size;
142
- }
143
-
144
- function convertLines(rings: number[][], out, tolerance: number, isPolygon: boolean): void {
145
- for (let i = 0; i < rings.length; i++) {
146
- const geom = [];
147
- convertLine(rings[i], geom, tolerance, isPolygon);
148
- out.push(geom);
149
- }
150
- }
151
-
152
- function projectX(x: number): number {
153
- return x / 360 + 0.5;
154
- }
155
-
156
- function projectY(y: number): number {
157
- const sin = Math.sin((y * Math.PI) / 180);
158
- const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
159
- return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
160
- }
@@ -1,47 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
5
-
6
- import {GeoJSONTileFeature} from './tile';
7
-
8
- export function createFeature(id, type, geom, tags): GeoJSONTileFeature {
9
- const feature: GeoJSONTileFeature = {
10
- // eslint-disable-next-line
11
- id: id == null ? null : id,
12
- type,
13
- geometry: geom,
14
- tags,
15
- minX: Infinity,
16
- minY: Infinity,
17
- maxX: -Infinity,
18
- maxY: -Infinity
19
- };
20
-
21
- if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
22
- calcLineBBox(feature, geom);
23
- } else if (type === 'Polygon') {
24
- // the outer ring (ie [0]) contains all inner rings
25
- calcLineBBox(feature, geom[0]);
26
- } else if (type === 'MultiLineString') {
27
- for (const line of geom) {
28
- calcLineBBox(feature, line);
29
- }
30
- } else if (type === 'MultiPolygon') {
31
- for (const polygon of geom) {
32
- // the outer ring (ie [0]) contains all inner rings
33
- calcLineBBox(feature, polygon[0]);
34
- }
35
- }
36
-
37
- return feature;
38
- }
39
-
40
- function calcLineBBox(feature, geom) {
41
- for (let i = 0; i < geom.length; i += 3) {
42
- feature.minX = Math.min(feature.minX, geom[i]);
43
- feature.minY = Math.min(feature.minY, geom[i + 1]);
44
- feature.maxX = Math.max(feature.maxX, geom[i]);
45
- feature.maxY = Math.max(feature.maxY, geom[i + 1]);
46
- }
47
- }
@@ -1,187 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
5
-
6
- // import type {Feature} from '@loaders.gl/schema';
7
-
8
- export type GeoJSONTileFeature = {
9
- type: any;
10
- geometry: any;
11
-
12
- // book keeping
13
- id?: string;
14
- tags?: string[];
15
-
16
- // spatial extents
17
- minX: number;
18
- maxX: number;
19
- minY: number;
20
- maxY: number;
21
- };
22
-
23
- export type GeoJSONTile = {
24
- features: GeoJSONTileFeature[]; // Feature[]; Doesn't seem JSON compatible??
25
- type?: number;
26
- tags?: Record<string, string>;
27
-
28
- // tile coordinates
29
- x: number;
30
- y: number;
31
- z: number;
32
-
33
- // spatial extents
34
- minX: number;
35
- maxX: number;
36
- minY: number;
37
- maxY: number;
38
-
39
- transformed: boolean;
40
- numPoints: number;
41
- numSimplified: number;
42
- numFeatures: number;
43
- source: any | null;
44
- };
45
-
46
- export type CreateTileOptions = {
47
- maxZoom?: number;
48
- tolerance: number;
49
- extent: number;
50
- lineMetrics: boolean;
51
- };
52
-
53
- /**
54
- * Create a tile from features and tile index
55
- */
56
- export function createTile(features: any[], z, tx, ty, options: CreateTileOptions): GeoJSONTile {
57
- const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
58
- const tile: GeoJSONTile = {
59
- features: [],
60
- numPoints: 0,
61
- numSimplified: 0,
62
- numFeatures: features.length,
63
- source: null,
64
- x: tx,
65
- y: ty,
66
- z,
67
- transformed: false,
68
- minX: 2,
69
- minY: 1,
70
- maxX: -1,
71
- maxY: 0
72
- };
73
- for (const feature of features) {
74
- addFeature(tile, feature, tolerance, options);
75
- }
76
- return tile;
77
- }
78
-
79
- // eslint-disable-next-line complexity, max-statements
80
- function addFeature(tile: GeoJSONTile, feature, tolerance: number, options: CreateTileOptions) {
81
- const geom = feature.geometry;
82
- const type = feature.type;
83
- const simplified: number[] = [];
84
-
85
- tile.minX = Math.min(tile.minX, feature.minX);
86
- tile.minY = Math.min(tile.minY, feature.minY);
87
- tile.maxX = Math.max(tile.maxX, feature.maxX);
88
- tile.maxY = Math.max(tile.maxY, feature.maxY);
89
-
90
- if (type === 'Point' || type === 'MultiPoint') {
91
- for (let i = 0; i < geom.length; i += 3) {
92
- simplified.push(geom[i], geom[i + 1]);
93
- tile.numPoints++;
94
- tile.numSimplified++;
95
- }
96
- } else if (type === 'LineString') {
97
- addLine(simplified, geom, tile, tolerance, false, false);
98
- } else if (type === 'MultiLineString' || type === 'Polygon') {
99
- for (let i = 0; i < geom.length; i++) {
100
- addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
101
- }
102
- } else if (type === 'MultiPolygon') {
103
- for (let k = 0; k < geom.length; k++) {
104
- const polygon = geom[k];
105
- for (let i = 0; i < polygon.length; i++) {
106
- addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
107
- }
108
- }
109
- }
110
-
111
- if (simplified.length) {
112
- let tags = feature.tags || null;
113
-
114
- if (type === 'LineString' && options.lineMetrics) {
115
- tags = {};
116
- for (const key in feature.tags) tags[key] = feature.tags[key];
117
- // eslint-disable-next-line camelcase
118
- tags.mapbox_clip_start = geom.start / geom.size;
119
- // eslint-disable-next-line camelcase
120
- tags.mapbox_clip_end = geom.end / geom.size;
121
- }
122
-
123
- // @ts-expect-error TODO - create sub type?
124
- const tileFeature: GeoJSONTileFeature = {
125
- geometry: simplified,
126
- type:
127
- type === 'Polygon' || type === 'MultiPolygon'
128
- ? 3
129
- : type === 'LineString' || type === 'MultiLineString'
130
- ? 2
131
- : 1,
132
- tags
133
- };
134
- if (feature.id !== null) {
135
- tileFeature.id = feature.id;
136
- }
137
- tile.features.push(tileFeature);
138
- }
139
- }
140
-
141
- // eslint-disable-next-line max-params, max-statements
142
- function addLine(
143
- result,
144
- geom,
145
- tile: GeoJSONTile,
146
- tolerance: number,
147
- isPolygon: boolean,
148
- isOuter: boolean
149
- ): void {
150
- const sqTolerance = tolerance * tolerance;
151
-
152
- if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
153
- tile.numPoints += geom.length / 3;
154
- return;
155
- }
156
-
157
- const ring: number[] = [];
158
-
159
- for (let i = 0; i < geom.length; i += 3) {
160
- if (tolerance === 0 || geom[i + 2] > sqTolerance) {
161
- tile.numSimplified++;
162
- ring.push(geom[i], geom[i + 1]);
163
- }
164
- tile.numPoints++;
165
- }
166
-
167
- if (isPolygon) rewind(ring, isOuter);
168
-
169
- result.push(ring);
170
- }
171
-
172
- function rewind(ring: number[], clockwise?: boolean): void {
173
- let area = 0;
174
- for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
175
- area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
176
- }
177
- if (area > 0 === clockwise) {
178
- for (let i = 0, len = ring.length; i < len / 2; i += 2) {
179
- const x = ring[i];
180
- const y = ring[i + 1];
181
- ring[i] = ring[len - 2 - i];
182
- ring[i + 1] = ring[len - 1 - i];
183
- ring[len - 2 - i] = x;
184
- ring[len - 1 - i] = y;
185
- }
186
- }
187
- }
@@ -1,57 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
5
-
6
- import type {GeoJSONTile} from './tile';
7
-
8
- /**
9
- * Transforms the coordinates of each feature in the given tile from
10
- * mercator-projected space into (extent x extent) tile space.
11
- */
12
- export function transformTile(tile: GeoJSONTile, extent: number): GeoJSONTile {
13
- if (tile.transformed) {
14
- return tile;
15
- }
16
-
17
- const z2 = 1 << tile.z;
18
- const tx = tile.x;
19
- const ty = tile.y;
20
-
21
- for (const feature of tile.features) {
22
- const geom = feature.geometry;
23
- const type = feature.type;
24
-
25
- feature.geometry = [];
26
-
27
- if (type === 1) {
28
- for (let j = 0; j < geom.length; j += 2) {
29
- feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
30
- }
31
- } else {
32
- for (let j = 0; j < geom.length; j++) {
33
- const ring: number[][] = [];
34
- for (let k = 0; k < geom[j].length; k += 2) {
35
- ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
36
- }
37
- feature.geometry.push(ring);
38
- }
39
- }
40
- }
41
-
42
- tile.transformed = true;
43
-
44
- return tile;
45
- }
46
-
47
- // eslint-disable-next-line max-params
48
- function transformPoint(
49
- x: number,
50
- y: number,
51
- extent: number,
52
- z2: number,
53
- tx: number,
54
- ty: number
55
- ): number[] {
56
- return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
57
- }
File without changes