@loaders.gl/mvt 4.3.0-alpha.2 → 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 (74) hide show
  1. package/dist/dist.dev.js +777 -688
  2. package/dist/dist.min.js +1 -1
  3. package/dist/index.cjs +746 -659
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +6 -5
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -1
  8. package/dist/lib/parse-tilejson.js +1 -1
  9. package/dist/lib/utils/geometry-utils.js +1 -1
  10. package/dist/lib/vector-tiler/{clip.d.ts → features/clip-features.d.ts} +4 -4
  11. package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
  12. package/dist/lib/vector-tiler/{clip.js → features/clip-features.js} +4 -4
  13. package/dist/lib/vector-tiler/{convert.d.ts → features/convert-feature.d.ts} +7 -7
  14. package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
  15. package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
  16. package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
  17. package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
  18. package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
  19. package/dist/lib/vector-tiler/{simplify.d.ts → features/simplify-path.d.ts} +2 -2
  20. package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
  21. package/dist/lib/vector-tiler/{simplify.js → features/simplify-path.js} +3 -3
  22. package/dist/lib/vector-tiler/{wrap.d.ts → features/wrap-features.d.ts} +5 -5
  23. package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
  24. package/dist/lib/vector-tiler/{wrap.js → features/wrap-features.js} +33 -26
  25. package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
  26. package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
  27. package/dist/lib/vector-tiler/proto-tile.js +138 -0
  28. package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
  29. package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
  30. package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
  31. package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
  32. package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
  33. package/dist/lib/vector-tiler/transform-tile.js +41 -0
  34. package/dist/mvt-loader.js +1 -1
  35. package/dist/mvt-source.d.ts +31 -14
  36. package/dist/mvt-source.d.ts.map +1 -1
  37. package/dist/mvt-source.js +26 -6
  38. package/dist/mvt-worker.js +4 -4
  39. package/dist/table-tile-source.d.ts +66 -36
  40. package/dist/table-tile-source.d.ts.map +1 -1
  41. package/dist/table-tile-source.js +167 -117
  42. package/dist/tilejson-loader.js +1 -1
  43. package/package.json +6 -6
  44. package/src/index.ts +13 -6
  45. package/src/lib/parse-tilejson.ts +1 -1
  46. package/src/lib/utils/geometry-utils.ts +1 -1
  47. package/src/lib/vector-tiler/{clip.ts → features/clip-features.ts} +8 -8
  48. package/src/lib/vector-tiler/{convert.ts → features/convert-feature.ts} +91 -70
  49. package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
  50. package/src/lib/vector-tiler/{simplify.ts → features/simplify-path.ts} +8 -3
  51. package/src/lib/vector-tiler/{wrap.ts → features/wrap-features.ts} +44 -29
  52. package/src/lib/vector-tiler/proto-tile.ts +217 -0
  53. package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
  54. package/src/lib/vector-tiler/transform-tile.ts +57 -0
  55. package/src/mvt-source.ts +42 -18
  56. package/src/table-tile-source.ts +130 -85
  57. package/src/tilejson-loader.ts +2 -2
  58. package/dist/lib/vector-tiler/clip.d.ts.map +0 -1
  59. package/dist/lib/vector-tiler/convert.d.ts.map +0 -1
  60. package/dist/lib/vector-tiler/convert.js +0 -139
  61. package/dist/lib/vector-tiler/feature.d.ts +0 -3
  62. package/dist/lib/vector-tiler/feature.d.ts.map +0 -1
  63. package/dist/lib/vector-tiler/feature.js +0 -44
  64. package/dist/lib/vector-tiler/simplify.d.ts.map +0 -1
  65. package/dist/lib/vector-tiler/tile.d.ts +0 -38
  66. package/dist/lib/vector-tiler/tile.d.ts.map +0 -1
  67. package/dist/lib/vector-tiler/tile.js +0 -123
  68. package/dist/lib/vector-tiler/transform.d.ts +0 -7
  69. package/dist/lib/vector-tiler/transform.d.ts.map +0 -1
  70. package/dist/lib/vector-tiler/transform.js +0 -41
  71. package/dist/lib/vector-tiler/wrap.d.ts.map +0 -1
  72. package/src/lib/vector-tiler/feature.ts +0 -47
  73. package/src/lib/vector-tiler/tile.ts +0 -187
  74. package/src/lib/vector-tiler/transform.ts +0 -57
@@ -1,139 +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
- import { simplify } from "./simplify.js";
6
- import { createFeature } from "./feature.js";
7
- /**
8
- * converts a GeoJSON feature into an intermediate projected JSON vector format
9
- * with simplification data
10
- */
11
- export function convert(data, options) {
12
- const features = [];
13
- if (data.type === 'FeatureCollection') {
14
- for (let i = 0; i < data.features.length; i++) {
15
- convertFeature(features, data.features[i], options, i);
16
- }
17
- }
18
- else if (data.type === 'Feature') {
19
- convertFeature(features, data, options);
20
- }
21
- else {
22
- // single geometry or a geometry collection
23
- convertFeature(features, { geometry: data }, options);
24
- }
25
- return features;
26
- }
27
- /**
28
- * converts a GeoJSON feature into an intermediate projected JSON vector format
29
- * with simplification data
30
- */
31
- function convertFeature(features, geojson, options, index) {
32
- if (!geojson.geometry) {
33
- return;
34
- }
35
- const coords = geojson.geometry.coordinates;
36
- const type = geojson.geometry.type;
37
- const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
38
- let geometry = [];
39
- let id = geojson.id;
40
- if (options.promoteId) {
41
- id = geojson.properties[options.promoteId];
42
- }
43
- else if (options.generateId) {
44
- id = index || 0;
45
- }
46
- if (type === 'Point') {
47
- convertPoint(coords, geometry);
48
- }
49
- else if (type === 'MultiPoint') {
50
- for (const p of coords) {
51
- convertPoint(p, geometry);
52
- }
53
- }
54
- else if (type === 'LineString') {
55
- convertLine(coords, geometry, tolerance, false);
56
- }
57
- else if (type === 'MultiLineString') {
58
- if (options.lineMetrics) {
59
- // explode into linestrings to be able to track metrics
60
- for (const line of coords) {
61
- geometry = [];
62
- convertLine(line, geometry, tolerance, false);
63
- features.push(createFeature(id, 'LineString', geometry, geojson.properties));
64
- }
65
- return;
66
- }
67
- else {
68
- convertLines(coords, geometry, tolerance, false);
69
- }
70
- }
71
- else if (type === 'Polygon') {
72
- convertLines(coords, geometry, tolerance, true);
73
- }
74
- else if (type === 'MultiPolygon') {
75
- for (const polygon of coords) {
76
- const newPolygon = [];
77
- convertLines(polygon, newPolygon, tolerance, true);
78
- geometry.push(newPolygon);
79
- }
80
- }
81
- else if (type === 'GeometryCollection') {
82
- for (const singleGeometry of geojson.geometry.geometries) {
83
- convertFeature(features, {
84
- id,
85
- geometry: singleGeometry,
86
- properties: geojson.properties
87
- }, options, index);
88
- }
89
- return;
90
- }
91
- else {
92
- throw new Error('Input data is not a valid GeoJSON object.');
93
- }
94
- features.push(createFeature(id, type, geometry, geojson.properties));
95
- }
96
- function convertPoint(coords, out) {
97
- out.push(projectX(coords[0]), projectY(coords[1]), 0);
98
- }
99
- function convertLine(ring, out, tolerance, isPolygon) {
100
- let x0, y0;
101
- let size = 0;
102
- for (let j = 0; j < ring.length; j++) {
103
- const x = projectX(ring[j][0]);
104
- const y = projectY(ring[j][1]);
105
- out.push(x, y, 0);
106
- if (j > 0) {
107
- if (isPolygon) {
108
- size += (x0 * y - x * y0) / 2; // area
109
- }
110
- else {
111
- size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
112
- }
113
- }
114
- x0 = x;
115
- y0 = y;
116
- }
117
- const last = out.length - 3;
118
- out[2] = 1;
119
- simplify(out, 0, last, tolerance);
120
- out[last + 2] = 1;
121
- out.size = Math.abs(size);
122
- out.start = 0;
123
- out.end = out.size;
124
- }
125
- function convertLines(rings, out, tolerance, isPolygon) {
126
- for (let i = 0; i < rings.length; i++) {
127
- const geom = [];
128
- convertLine(rings[i], geom, tolerance, isPolygon);
129
- out.push(geom);
130
- }
131
- }
132
- function projectX(x) {
133
- return x / 360 + 0.5;
134
- }
135
- function projectY(y) {
136
- const sin = Math.sin((y * Math.PI) / 180);
137
- const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
138
- return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
139
- }
@@ -1,3 +0,0 @@
1
- import { TableTileFeature } from "./tile.js";
2
- export declare function createFeature(id: any, type: any, geom: any, tags: any): TableTileFeature;
3
- //# sourceMappingURL=feature.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/feature.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,gBAAgB,EAAC,kBAAe;AAExC,wBAAgB,aAAa,CAAC,EAAE,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,GAAG,gBAAgB,CA8BpE"}
@@ -1,44 +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
- export function createFeature(id, type, geom, tags) {
6
- const feature = {
7
- // eslint-disable-next-line
8
- id: id == null ? null : id,
9
- type,
10
- geometry: geom,
11
- tags,
12
- minX: Infinity,
13
- minY: Infinity,
14
- maxX: -Infinity,
15
- maxY: -Infinity
16
- };
17
- if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
18
- calcLineBBox(feature, geom);
19
- }
20
- else if (type === 'Polygon') {
21
- // the outer ring (ie [0]) contains all inner rings
22
- calcLineBBox(feature, geom[0]);
23
- }
24
- else if (type === 'MultiLineString') {
25
- for (const line of geom) {
26
- calcLineBBox(feature, line);
27
- }
28
- }
29
- else if (type === 'MultiPolygon') {
30
- for (const polygon of geom) {
31
- // the outer ring (ie [0]) contains all inner rings
32
- calcLineBBox(feature, polygon[0]);
33
- }
34
- }
35
- return feature;
36
- }
37
- function calcLineBBox(feature, geom) {
38
- for (let i = 0; i < geom.length; i += 3) {
39
- feature.minX = Math.min(feature.minX, geom[i]);
40
- feature.minY = Math.min(feature.minY, geom[i + 1]);
41
- feature.maxX = Math.max(feature.maxX, geom[i]);
42
- feature.maxY = Math.max(feature.maxY, geom[i + 1]);
43
- }
44
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"simplify.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/simplify.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAkCjG"}
@@ -1,38 +0,0 @@
1
- export type TableTileFeature = {
2
- type: any;
3
- geometry: any;
4
- id?: string;
5
- tags?: string[];
6
- minX: number;
7
- maxX: number;
8
- minY: number;
9
- maxY: number;
10
- };
11
- export type TableTile = {
12
- features: TableTileFeature[];
13
- type?: number;
14
- tags?: Record<string, string>;
15
- x: number;
16
- y: number;
17
- z: number;
18
- minX: number;
19
- maxX: number;
20
- minY: number;
21
- maxY: number;
22
- transformed: boolean;
23
- numPoints: number;
24
- numSimplified: number;
25
- numFeatures: number;
26
- source: any | null;
27
- };
28
- export type CreateTileOptions = {
29
- maxZoom?: number;
30
- tolerance: number;
31
- extent: number;
32
- lineMetrics: boolean;
33
- };
34
- /**
35
- * Create a tile from features and tile index
36
- */
37
- export declare function createTile(features: any[], z: any, tx: any, ty: any, options: CreateTileOptions): TableTile;
38
- //# sourceMappingURL=tile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/tile.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,EAAE,GAAG,CAAC;IAGd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAGhB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAG9B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IAGV,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAEb,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,KAAA,EAAE,EAAE,KAAA,EAAE,EAAE,KAAA,EAAE,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAqB5F"}
@@ -1,123 +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
- * Create a tile from features and tile index
7
- */
8
- export function createTile(features, z, tx, ty, options) {
9
- const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
10
- const tile = {
11
- features: [],
12
- numPoints: 0,
13
- numSimplified: 0,
14
- numFeatures: features.length,
15
- source: null,
16
- x: tx,
17
- y: ty,
18
- z,
19
- transformed: false,
20
- minX: 2,
21
- minY: 1,
22
- maxX: -1,
23
- maxY: 0
24
- };
25
- for (const feature of features) {
26
- addFeature(tile, feature, tolerance, options);
27
- }
28
- return tile;
29
- }
30
- // eslint-disable-next-line complexity, max-statements
31
- function addFeature(tile, feature, tolerance, options) {
32
- const geom = feature.geometry;
33
- const type = feature.type;
34
- const simplified = [];
35
- tile.minX = Math.min(tile.minX, feature.minX);
36
- tile.minY = Math.min(tile.minY, feature.minY);
37
- tile.maxX = Math.max(tile.maxX, feature.maxX);
38
- tile.maxY = Math.max(tile.maxY, feature.maxY);
39
- if (type === 'Point' || type === 'MultiPoint') {
40
- for (let i = 0; i < geom.length; i += 3) {
41
- simplified.push(geom[i], geom[i + 1]);
42
- tile.numPoints++;
43
- tile.numSimplified++;
44
- }
45
- }
46
- else if (type === 'LineString') {
47
- addLine(simplified, geom, tile, tolerance, false, false);
48
- }
49
- else if (type === 'MultiLineString' || type === 'Polygon') {
50
- for (let i = 0; i < geom.length; i++) {
51
- addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
52
- }
53
- }
54
- else if (type === 'MultiPolygon') {
55
- for (let k = 0; k < geom.length; k++) {
56
- const polygon = geom[k];
57
- for (let i = 0; i < polygon.length; i++) {
58
- addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
59
- }
60
- }
61
- }
62
- if (simplified.length) {
63
- let tags = feature.tags || null;
64
- if (type === 'LineString' && options.lineMetrics) {
65
- tags = {};
66
- for (const key in feature.tags)
67
- tags[key] = feature.tags[key];
68
- // eslint-disable-next-line camelcase
69
- tags.mapbox_clip_start = geom.start / geom.size;
70
- // eslint-disable-next-line camelcase
71
- tags.mapbox_clip_end = geom.end / geom.size;
72
- }
73
- // @ts-expect-error TODO - create sub type?
74
- const tileFeature = {
75
- geometry: simplified,
76
- type: type === 'Polygon' || type === 'MultiPolygon'
77
- ? 3
78
- : type === 'LineString' || type === 'MultiLineString'
79
- ? 2
80
- : 1,
81
- tags
82
- };
83
- if (feature.id !== null) {
84
- tileFeature.id = feature.id;
85
- }
86
- tile.features.push(tileFeature);
87
- }
88
- }
89
- // eslint-disable-next-line max-params, max-statements
90
- function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
91
- const sqTolerance = tolerance * tolerance;
92
- if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
93
- tile.numPoints += geom.length / 3;
94
- return;
95
- }
96
- const ring = [];
97
- for (let i = 0; i < geom.length; i += 3) {
98
- if (tolerance === 0 || geom[i + 2] > sqTolerance) {
99
- tile.numSimplified++;
100
- ring.push(geom[i], geom[i + 1]);
101
- }
102
- tile.numPoints++;
103
- }
104
- if (isPolygon)
105
- rewind(ring, isOuter);
106
- result.push(ring);
107
- }
108
- function rewind(ring, clockwise) {
109
- let area = 0;
110
- for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
111
- area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
112
- }
113
- if (area > 0 === clockwise) {
114
- for (let i = 0, len = ring.length; i < len / 2; i += 2) {
115
- const x = ring[i];
116
- const y = ring[i + 1];
117
- ring[i] = ring[len - 2 - i];
118
- ring[i + 1] = ring[len - 1 - i];
119
- ring[len - 2 - i] = x;
120
- ring[len - 1 - i] = y;
121
- }
122
- }
123
- }
@@ -1,7 +0,0 @@
1
- import type { TableTile } from "./tile.js";
2
- /**
3
- * Transforms the coordinates of each feature in the given tile from
4
- * mercator-projected space into (extent x extent) tile space.
5
- */
6
- export declare function transformTile(tile: TableTile, extent: number): TableTile;
7
- //# sourceMappingURL=transform.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/transform.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,SAAS,EAAC,kBAAe;AAEtC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAiCxE"}
@@ -1,41 +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
- * Transforms the coordinates of each feature in the given tile from
7
- * mercator-projected space into (extent x extent) tile space.
8
- */
9
- export function transformTile(tile, extent) {
10
- if (tile.transformed) {
11
- return tile;
12
- }
13
- const z2 = 1 << tile.z;
14
- const tx = tile.x;
15
- const ty = tile.y;
16
- for (const feature of tile.features) {
17
- const geom = feature.geometry;
18
- const type = feature.type;
19
- feature.geometry = [];
20
- if (type === 1) {
21
- for (let j = 0; j < geom.length; j += 2) {
22
- feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
23
- }
24
- }
25
- else {
26
- for (let j = 0; j < geom.length; j++) {
27
- const ring = [];
28
- for (let k = 0; k < geom[j].length; k += 2) {
29
- ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
30
- }
31
- feature.geometry.push(ring);
32
- }
33
- }
34
- }
35
- tile.transformed = true;
36
- return tile;
37
- }
38
- // eslint-disable-next-line max-params
39
- function transformPoint(x, y, extent, z2, tx, ty) {
40
- return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
41
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/wrap.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,gBAAgB,EAAC,kBAAe;AAI7C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC,8CAA8C,CAAC;IAC9D,MAAM,EAAE,MAAM,CAAC,0BAA0B,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,WAAW,sBAkBtE"}
@@ -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 {TableTileFeature} from './tile';
7
-
8
- export function createFeature(id, type, geom, tags): TableTileFeature {
9
- const feature: TableTileFeature = {
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 TableTileFeature = {
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 TableTile = {
24
- features: TableTileFeature[]; // 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): TableTile {
57
- const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
58
- const tile: TableTile = {
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: TableTile, 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: TableTileFeature = {
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: TableTile,
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
- }