@loaders.gl/mvt 4.2.1 → 4.3.0-alpha.2

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 (120) hide show
  1. package/dist/dist.dev.js +1784 -847
  2. package/dist/dist.min.js +1 -1
  3. package/dist/index.cjs +713 -640
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib/parse-mvt.d.ts +2 -1
  9. package/dist/lib/parse-mvt.d.ts.map +1 -1
  10. package/dist/lib/parse-mvt.js +15 -45
  11. package/dist/lib/parse-tilejson.d.ts +4 -4
  12. package/dist/lib/parse-tilejson.d.ts.map +1 -1
  13. package/dist/lib/types.d.ts +1 -39
  14. package/dist/lib/types.d.ts.map +1 -1
  15. package/dist/lib/utils/geometry-utils.d.ts +83 -0
  16. package/dist/lib/utils/geometry-utils.d.ts.map +1 -0
  17. package/dist/lib/utils/geometry-utils.js +206 -0
  18. package/dist/lib/vector-tile/vector-tile-feature.d.ts +72 -0
  19. package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -0
  20. package/dist/lib/vector-tile/vector-tile-feature.js +342 -0
  21. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.d.ts +10 -1
  22. package/dist/lib/vector-tile/vector-tile-layer.d.ts.map +1 -0
  23. package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.js +16 -1
  24. package/dist/lib/vector-tile/vector-tile.d.ts.map +1 -0
  25. package/dist/lib/{geojson-tiler → vector-tiler}/clip.d.ts +3 -3
  26. package/dist/lib/vector-tiler/clip.d.ts.map +1 -0
  27. package/dist/lib/vector-tiler/convert.d.ts +18 -0
  28. package/dist/lib/vector-tiler/convert.d.ts.map +1 -0
  29. package/dist/lib/{geojson-tiler → vector-tiler}/convert.js +8 -1
  30. package/dist/lib/vector-tiler/feature.d.ts +3 -0
  31. package/dist/lib/vector-tiler/feature.d.ts.map +1 -0
  32. package/dist/lib/vector-tiler/simplify.d.ts.map +1 -0
  33. package/dist/lib/{geojson-tiler → vector-tiler}/tile.d.ts +4 -4
  34. package/dist/lib/vector-tiler/tile.d.ts.map +1 -0
  35. package/dist/lib/vector-tiler/transform.d.ts +7 -0
  36. package/dist/lib/vector-tiler/transform.d.ts.map +1 -0
  37. package/dist/lib/{geojson-tiler → vector-tiler}/wrap.d.ts +2 -2
  38. package/dist/lib/vector-tiler/wrap.d.ts.map +1 -0
  39. package/dist/mvt-loader.d.ts +19 -8
  40. package/dist/mvt-loader.d.ts.map +1 -1
  41. package/dist/mvt-loader.js +3 -2
  42. package/dist/mvt-source.d.ts +4 -4
  43. package/dist/mvt-source.d.ts.map +1 -1
  44. package/dist/mvt-source.js +7 -7
  45. package/dist/mvt-worker.js +1244 -762
  46. package/dist/table-tile-source.d.ts +118 -0
  47. package/dist/table-tile-source.d.ts.map +1 -0
  48. package/dist/table-tile-source.js +370 -0
  49. package/dist/tilejson-loader.js +1 -1
  50. package/package.json +7 -6
  51. package/src/index.ts +3 -3
  52. package/src/lib/parse-mvt.ts +28 -66
  53. package/src/lib/parse-tilejson.ts +5 -5
  54. package/src/lib/types.ts +1 -39
  55. package/src/lib/utils/geometry-utils.ts +234 -0
  56. package/src/lib/vector-tile/vector-tile-feature.ts +416 -0
  57. package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile-layer.ts +28 -2
  58. package/src/lib/{geojson-tiler → vector-tiler}/clip.ts +4 -4
  59. package/src/lib/{geojson-tiler → vector-tiler}/convert.ts +19 -9
  60. package/src/lib/{geojson-tiler → vector-tiler}/feature.ts +3 -3
  61. package/src/lib/{geojson-tiler → vector-tiler}/tile.ts +10 -10
  62. package/src/lib/{geojson-tiler → vector-tiler}/transform.ts +2 -2
  63. package/src/lib/{geojson-tiler → vector-tiler}/wrap.ts +5 -5
  64. package/src/mvt-loader.ts +14 -6
  65. package/src/mvt-source.ts +9 -10
  66. package/src/table-tile-source.ts +508 -0
  67. package/dist/helpers/binary-util-functions.d.ts +0 -35
  68. package/dist/helpers/binary-util-functions.d.ts.map +0 -1
  69. package/dist/helpers/binary-util-functions.js +0 -114
  70. package/dist/helpers/mapbox-util-functions.d.ts +0 -29
  71. package/dist/helpers/mapbox-util-functions.d.ts.map +0 -1
  72. package/dist/helpers/mapbox-util-functions.js +0 -78
  73. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +0 -41
  74. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +0 -1
  75. package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -163
  76. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -23
  77. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +0 -1
  78. package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -96
  79. package/dist/lib/binary-vector-tile/vector-tile.d.ts +0 -9
  80. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +0 -1
  81. package/dist/lib/binary-vector-tile/vector-tile.js +0 -27
  82. package/dist/lib/geojson-tiler/clip.d.ts.map +0 -1
  83. package/dist/lib/geojson-tiler/convert.d.ts +0 -10
  84. package/dist/lib/geojson-tiler/convert.d.ts.map +0 -1
  85. package/dist/lib/geojson-tiler/feature.d.ts +0 -3
  86. package/dist/lib/geojson-tiler/feature.d.ts.map +0 -1
  87. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +0 -44
  88. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +0 -1
  89. package/dist/lib/geojson-tiler/geojson-tiler.js +0 -209
  90. package/dist/lib/geojson-tiler/simplify.d.ts.map +0 -1
  91. package/dist/lib/geojson-tiler/tile.d.ts.map +0 -1
  92. package/dist/lib/geojson-tiler/transform.d.ts +0 -7
  93. package/dist/lib/geojson-tiler/transform.d.ts.map +0 -1
  94. package/dist/lib/geojson-tiler/wrap.d.ts.map +0 -1
  95. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -27
  96. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +0 -1
  97. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -178
  98. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +0 -1
  99. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +0 -1
  100. package/src/helpers/binary-util-functions.ts +0 -125
  101. package/src/helpers/mapbox-util-functions.ts +0 -82
  102. package/src/lib/binary-vector-tile/vector-tile-feature.ts +0 -203
  103. package/src/lib/binary-vector-tile/vector-tile-layer.ts +0 -113
  104. package/src/lib/binary-vector-tile/vector-tile.ts +0 -36
  105. package/src/lib/geojson-tiler/geojson-tiler.ts +0 -283
  106. package/src/lib/mapbox-vector-tile/LICENSE.txt +0 -31
  107. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +0 -207
  108. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.d.ts +0 -0
  109. /package/dist/lib/{mapbox-vector-tile → vector-tile}/vector-tile.js +0 -0
  110. /package/dist/lib/{geojson-tiler → vector-tiler}/clip.js +0 -0
  111. /package/dist/lib/{geojson-tiler → vector-tiler}/feature.js +0 -0
  112. /package/dist/lib/{geojson-tiler → vector-tiler}/simplify.d.ts +0 -0
  113. /package/dist/lib/{geojson-tiler → vector-tiler}/simplify.js +0 -0
  114. /package/dist/lib/{geojson-tiler → vector-tiler}/tile.js +0 -0
  115. /package/dist/lib/{geojson-tiler → vector-tiler}/transform.js +0 -0
  116. /package/dist/lib/{geojson-tiler → vector-tiler}/wrap.js +0 -0
  117. /package/src/lib/{binary-vector-tile → vector-tile}/LICENSE.txt +0 -0
  118. /package/src/lib/{mapbox-vector-tile → vector-tile}/vector-tile.ts +0 -0
  119. /package/src/lib/{geojson-tiler → vector-tiler}/LICENSE +0 -0
  120. /package/src/lib/{geojson-tiler → vector-tiler}/simplify.ts +0 -0
@@ -0,0 +1,118 @@
1
+ import type { VectorTileSourceProps, GetTileDataParameters, GetTileParameters } from '@loaders.gl/loader-utils';
2
+ import { VectorTileSource } from '@loaders.gl/loader-utils';
3
+ import { Schema, GeoJSONTable, Feature, BinaryFeatureCollection } from '@loaders.gl/schema';
4
+ import { Stats } from '@probe.gl/stats';
5
+ import type { TableTile, TableTileFeature } from "./lib/vector-tiler/tile.js";
6
+ /** Options to configure tiling */
7
+ export type TableTileSourceProps = VectorTileSourceProps & {
8
+ coordinates: 'local' | 'wgs84' | 'EPSG:4326';
9
+ /** max zoom to preserve detail on */
10
+ maxZoom?: number;
11
+ /** max zoom in the tile index */
12
+ indexMaxZoom?: number;
13
+ /** max number of points per tile in the tile index */
14
+ maxPointsPerTile?: number;
15
+ /** simplification tolerance (higher means simpler) */
16
+ tolerance?: number;
17
+ /** tile extent */
18
+ extent?: number;
19
+ /** tile buffer on each side */
20
+ buffer?: number;
21
+ /** name of a feature property to be promoted to feature.id */
22
+ promoteId?: string;
23
+ /** whether to generate feature ids. Cannot be used with promoteId */
24
+ generateId?: boolean;
25
+ /** logging level (0, 1 or 2) */
26
+ debug?: number;
27
+ /** whether to calculate line metrics */
28
+ lineMetrics?: boolean;
29
+ };
30
+ /**
31
+ * Dynamically vector tiles a table (the table needs a geometry column)
32
+ * - Tiles are generated when requested.
33
+ * - Each tile contains a tables of clipped features.
34
+ *
35
+ * @note - Currently only accepts `GeoJSONTable` tables
36
+ * @note - Currently only outputs `GeoJSONTable`
37
+ * @note - (can be initialized with a promise that resolves to GeoJSONTable).
38
+ *
39
+ * @todo - metadata should scan all rows to determine schema
40
+ * @todo - metadata scan all rows to determine tilestats (field values[] etc).
41
+ * @todo - handle binary input tables
42
+ * @todo - generate binary output tables
43
+ * @todo - how does TileSourceLayer specify coordinates / decided which layer to render with
44
+ */
45
+ export declare class TableTileSource implements VectorTileSource<any> {
46
+ static defaultProps: Required<TableTileSourceProps>;
47
+ /** Global stats for all TableTileSources */
48
+ static stats: Stats;
49
+ /** Stats for this TableTileSource */
50
+ stats: Stats;
51
+ /** MIME type of the tiles emitted by this tile source */
52
+ readonly mimeType = "application/vnd.mapbox-vector-tile";
53
+ readonly localCoordinates = true;
54
+ /** The props that this tile source was created with */
55
+ props: Required<TableTileSourceProps>;
56
+ schema: Schema | null;
57
+ /** Map of generated tiles, indexed by stringified tile coordinates */
58
+ tiles: Record<string, TableTile>;
59
+ /** Array of tile coordinates */
60
+ tileCoords: {
61
+ x: number;
62
+ y: number;
63
+ z: number;
64
+ }[];
65
+ /** Input data has loaded, initial top-level tiling is done, sync methods can now be called */
66
+ ready: Promise<void>;
67
+ /** Metadata for the tile source (generated TileJSON/tilestats */
68
+ metadata: Promise<unknown>;
69
+ constructor(table: GeoJSONTable | Promise<GeoJSONTable>, props?: TableTileSourceProps);
70
+ initializeTilesAsync(tablePromise: GeoJSONTable | Promise<GeoJSONTable>): Promise<void>;
71
+ getMetadata(): Promise<unknown>;
72
+ getSchema(): Promise<Schema>;
73
+ /**
74
+ * Get a tile at the specified index
75
+ * @param tileIndex z, x, y of tile
76
+ * @returns
77
+ */
78
+ getVectorTile(tileIndex: GetTileParameters): Promise<GeoJSONTable | null>;
79
+ getTile(tileIndex: {
80
+ z: number;
81
+ x: number;
82
+ y: number;
83
+ }): Promise<GeoJSONTable | null>;
84
+ getTileData(tileParams: GetTileDataParameters): Promise<Feature[] | BinaryFeatureCollection>;
85
+ /**
86
+ * Synchronously request a tile
87
+ * @note Application must await `source.ready` before calling sync methods.
88
+ */
89
+ getTileSync(tileIndex: {
90
+ z: number;
91
+ x: number;
92
+ y: number;
93
+ }): GeoJSONTable | null;
94
+ /**
95
+ * Create the initial tiles
96
+ * @note the tiles stores all the features together with additional data
97
+ */
98
+ createRootTiles(table: GeoJSONTable): void;
99
+ /**
100
+ * Return geojsonvt-style "half formed" vector tile
101
+ * @note Application must await `source.ready` before calling sync methods.
102
+ */
103
+ getRawTile(tileIndex: {
104
+ z: number;
105
+ x: number;
106
+ y: number;
107
+ }): TableTile | null;
108
+ /**
109
+ * splits features from a parent tile to sub-tiles.
110
+ * @param z, x, and y are the coordinates of the parent tile
111
+ * @param cz, cx, and cy are the coordinates of the target tile
112
+ *
113
+ * If no target tile is specified, splitting stops when we reach the maximum
114
+ * zoom or the number of points is low as specified in the props.
115
+ */
116
+ splitTile(features: TableTileFeature[], z: number, x: number, y: number, cz?: number, cx?: number, cy?: number): void;
117
+ }
118
+ //# sourceMappingURL=table-tile-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-tile-source.d.ts","sourceRoot":"","sources":["../src/table-tile-source.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,370 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT AND ISC
3
+ // Copyright (c) vis.gl contributors
4
+ // Based on https://github.com/mapbox/geojson-vt under compatible ISC license
5
+ import { log } from '@loaders.gl/loader-utils';
6
+ import { deduceTableSchema } from '@loaders.gl/schema';
7
+ import { Stats, Stat } from '@probe.gl/stats';
8
+ import { convert } from "./lib/vector-tiler/convert.js"; // GeoJSON conversion and preprocessing
9
+ import { clip } from "./lib/vector-tiler/clip.js"; // stripe clipping algorithm
10
+ import { wrap } from "./lib/vector-tiler/wrap.js"; // date line processing
11
+ import { transformTile } from "./lib/vector-tiler/transform.js"; // coordinate transformation
12
+ import { createTile } from "./lib/vector-tiler/tile.js"; // final simplified tile generation
13
+ import { projectToLngLat } from "./lib/utils/geometry-utils.js";
14
+ import { convertToLocalCoordinates } from "./lib/utils/geometry-utils.js";
15
+ /**
16
+ * Dynamically vector tiles a table (the table needs a geometry column)
17
+ * - Tiles are generated when requested.
18
+ * - Each tile contains a tables of clipped features.
19
+ *
20
+ * @note - Currently only accepts `GeoJSONTable` tables
21
+ * @note - Currently only outputs `GeoJSONTable`
22
+ * @note - (can be initialized with a promise that resolves to GeoJSONTable).
23
+ *
24
+ * @todo - metadata should scan all rows to determine schema
25
+ * @todo - metadata scan all rows to determine tilestats (field values[] etc).
26
+ * @todo - handle binary input tables
27
+ * @todo - generate binary output tables
28
+ * @todo - how does TileSourceLayer specify coordinates / decided which layer to render with
29
+ */
30
+ export class TableTileSource {
31
+ static defaultProps = {
32
+ coordinates: 'wgs84', // coordinates in tile coordinates or lng/lat
33
+ maxZoom: 14, // max zoom to preserve detail on
34
+ indexMaxZoom: 5, // max zoom in the tile index
35
+ maxPointsPerTile: 100000, // max number of points per tile in the tile index
36
+ tolerance: 3, // simplification tolerance (higher means simpler)
37
+ extent: 4096, // tile extent
38
+ buffer: 64, // tile buffer on each side
39
+ lineMetrics: false, // whether to calculate line metrics
40
+ // @ts-expect-error
41
+ promoteId: undefined, // name of a feature property to be promoted to feature.id
42
+ generateId: false, // whether to generate feature ids. Cannot be used with promoteId
43
+ debug: 0 // logging level (0, 1 or 2)
44
+ };
45
+ /** Global stats for all TableTileSources */
46
+ static stats = new Stats({
47
+ id: 'table-tile-source-all',
48
+ stats: [new Stat('count', 'tiles'), new Stat('count', 'features')]
49
+ });
50
+ /** Stats for this TableTileSource */
51
+ stats = new Stats({
52
+ id: 'table-tile-source',
53
+ stats: [new Stat('tiles', 'count'), new Stat('features', 'count')]
54
+ });
55
+ /** MIME type of the tiles emitted by this tile source */
56
+ mimeType = 'application/vnd.mapbox-vector-tile';
57
+ localCoordinates = true;
58
+ /** The props that this tile source was created with */
59
+ props;
60
+ /* Schema of the data */
61
+ schema = null;
62
+ /** Map of generated tiles, indexed by stringified tile coordinates */
63
+ tiles = {};
64
+ /** Array of tile coordinates */
65
+ tileCoords = [];
66
+ /** Input data has loaded, initial top-level tiling is done, sync methods can now be called */
67
+ ready;
68
+ /** Metadata for the tile source (generated TileJSON/tilestats */
69
+ metadata;
70
+ constructor(table, props) {
71
+ this.props = { ...TableTileSource.defaultProps, ...props };
72
+ this.getTileData = this.getTileData.bind(this);
73
+ this.ready = this.initializeTilesAsync(table);
74
+ this.metadata = this.getMetadata();
75
+ }
76
+ async initializeTilesAsync(tablePromise) {
77
+ const table = await tablePromise;
78
+ this.schema = deduceTableSchema(table);
79
+ this.createRootTiles(table);
80
+ }
81
+ async getMetadata() {
82
+ await this.ready;
83
+ return { schema: this.schema, minZoom: 0, maxZoom: this.props.maxZoom };
84
+ }
85
+ async getSchema() {
86
+ await this.ready;
87
+ return this.schema;
88
+ }
89
+ /**
90
+ * Get a tile at the specified index
91
+ * @param tileIndex z, x, y of tile
92
+ * @returns
93
+ */
94
+ async getVectorTile(tileIndex) {
95
+ await this.ready;
96
+ const table = this.getTileSync(tileIndex);
97
+ log.info(2, 'getVectorTile', tileIndex, table)();
98
+ return table;
99
+ }
100
+ async getTile(tileIndex) {
101
+ await this.ready;
102
+ return this.getTileSync(tileIndex);
103
+ }
104
+ async getTileData(tileParams) {
105
+ const { x, y, z } = tileParams.index;
106
+ const tile = await this.getVectorTile({ x, y, z });
107
+ return tile?.features || [];
108
+ }
109
+ // Implementation
110
+ /**
111
+ * Synchronously request a tile
112
+ * @note Application must await `source.ready` before calling sync methods.
113
+ */
114
+ getTileSync(tileIndex) {
115
+ const rawTile = this.getRawTile(tileIndex);
116
+ if (!rawTile) {
117
+ return null;
118
+ }
119
+ return convertToGeoJSONTable(rawTile, {
120
+ coordinates: this.props.coordinates,
121
+ tileIndex,
122
+ extent: this.props.extent
123
+ });
124
+ }
125
+ /**
126
+ * Create the initial tiles
127
+ * @note the tiles stores all the features together with additional data
128
+ */
129
+ createRootTiles(table) {
130
+ if (this.props.maxZoom < 0 || this.props.maxZoom > 24) {
131
+ throw new Error('maxZoom should be in the 0-24 range');
132
+ }
133
+ if (this.props.promoteId && this.props.generateId) {
134
+ throw new Error('promoteId and generateId cannot be used together.');
135
+ }
136
+ log.log(1, 'TableTileSource creating root tiles', this.props)();
137
+ // projects and adds simplification info
138
+ log.time(1, 'preprocess table')();
139
+ let features = convert(table, this.props);
140
+ log.timeEnd(1, 'preprocess table')();
141
+ // wraps features (ie extreme west and extreme east)
142
+ log.time(1, 'generate tiles')();
143
+ features = wrap(features, this.props);
144
+ // start slicing from the top tile down
145
+ if (features.length === 0) {
146
+ log.log(1, 'TableTileSource: no features generated')();
147
+ return;
148
+ }
149
+ this.splitTile(features, 0, 0, 0);
150
+ const rootTile = this.tiles[0];
151
+ log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
152
+ log.timeEnd(1, 'generate tiles')();
153
+ log.log(1, `TableTileSource: tiles generated: ${this.stats.get('total').count}`, this.stats)();
154
+ }
155
+ /**
156
+ * Return geojsonvt-style "half formed" vector tile
157
+ * @note Application must await `source.ready` before calling sync methods.
158
+ */
159
+ // eslint-disable-next-line complexity, max-statements
160
+ getRawTile(tileIndex) {
161
+ const { z, y } = tileIndex;
162
+ let { x } = tileIndex;
163
+ // z = +z;
164
+ // x = +x;
165
+ // y = +y;
166
+ const { extent } = this.props;
167
+ if (z < 0 || z > 24) {
168
+ return null;
169
+ }
170
+ const z2 = 1 << z;
171
+ x = (x + z2) & (z2 - 1); // wrap tile x coordinate
172
+ const id = toID(z, x, y);
173
+ if (this.tiles[id]) {
174
+ return transformTile(this.tiles[id], extent);
175
+ }
176
+ log.log(log, 'drilling down to z%d-%d-%d', z, x, y)();
177
+ let z0 = z;
178
+ let x0 = x;
179
+ let y0 = y;
180
+ let parent;
181
+ while (!parent && z0 > 0) {
182
+ z0--;
183
+ x0 = x0 >> 1;
184
+ y0 = y0 >> 1;
185
+ parent = this.tiles[toID(z0, x0, y0)];
186
+ }
187
+ if (!parent || !parent.source) {
188
+ return null;
189
+ }
190
+ // if we found a parent tile containing the original geometry, we can drill down from it
191
+ log.log(1, 'found parent tile z%d-%d-%d', z0, x0, y0)();
192
+ log.time(1, 'drilling down')();
193
+ this.splitTile(parent.source, z0, x0, y0, z, x, y);
194
+ log.timeEnd(1, 'drilling down')();
195
+ return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
196
+ }
197
+ /**
198
+ * splits features from a parent tile to sub-tiles.
199
+ * @param z, x, and y are the coordinates of the parent tile
200
+ * @param cz, cx, and cy are the coordinates of the target tile
201
+ *
202
+ * If no target tile is specified, splitting stops when we reach the maximum
203
+ * zoom or the number of points is low as specified in the props.
204
+ */
205
+ // eslint-disable-next-line max-params, max-statements, complexity
206
+ splitTile(features, z, x, y, cz, cx, cy) {
207
+ const stack = [features, z, x, y];
208
+ // avoid recursion by using a processing queue
209
+ while (stack.length) {
210
+ y = stack.pop();
211
+ x = stack.pop();
212
+ z = stack.pop();
213
+ features = stack.pop();
214
+ const z2 = 1 << z;
215
+ const id = toID(z, x, y);
216
+ let tile = this.tiles[id];
217
+ if (!tile) {
218
+ log.time(2, 'tile creation')();
219
+ tile = this.tiles[id] = createTile(features, z, x, y, this.props);
220
+ this.tileCoords.push({ z, x, y });
221
+ const key = `z${z}`;
222
+ let stat = this.stats.get(key, 'count');
223
+ stat.incrementCount();
224
+ stat = this.stats.get('total');
225
+ stat.incrementCount();
226
+ stat = TableTileSource.stats.get(key, 'count');
227
+ stat.incrementCount();
228
+ stat = TableTileSource.stats.get('total');
229
+ stat.incrementCount();
230
+ log.log(2, 'tile z%d-%d-%d (features: %d, points: %d, simplified: %d)', z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified)();
231
+ log.timeEnd(2, 'tile creation')();
232
+ }
233
+ // save reference to original geometry in tile so that we can drill down later if we stop now
234
+ tile.source = features;
235
+ /** eslint-disable no-continue */
236
+ // if it's the first-pass tiling
237
+ if (cz === undefined) {
238
+ // stop tiling if we reached max zoom, or if the tile is too simple
239
+ if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
240
+ continue;
241
+ }
242
+ // if a drilldown to a specific tile
243
+ }
244
+ else if (z === this.props.maxZoom || z === cz) {
245
+ // stop tiling if we reached base zoom or our target tile zoom
246
+ continue;
247
+ }
248
+ else if (cz !== undefined) {
249
+ // stop tiling if it's not an ancestor of the target tile
250
+ const zoomSteps = cz - z;
251
+ // @ts-expect-error TODO fix the types of cx cy
252
+ if (x !== cx >> zoomSteps || y !== cy >> zoomSteps) {
253
+ continue;
254
+ }
255
+ }
256
+ // if we slice further down, no need to keep source geometry
257
+ tile.source = null;
258
+ if (features.length === 0)
259
+ continue;
260
+ log.time(2, 'clipping tile')();
261
+ // values we'll use for clipping
262
+ const k1 = (0.5 * this.props.buffer) / this.props.extent;
263
+ const k2 = 0.5 - k1;
264
+ const k3 = 0.5 + k1;
265
+ const k4 = 1 + k1;
266
+ let tl = null;
267
+ let bl = null;
268
+ let tr = null;
269
+ let br = null;
270
+ let left = clip(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
271
+ let right = clip(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
272
+ // @ts-expect-error - unclear why this is needed?
273
+ features = null;
274
+ if (left) {
275
+ tl = clip(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
276
+ bl = clip(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
277
+ left = null;
278
+ }
279
+ if (right) {
280
+ tr = clip(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
281
+ br = clip(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
282
+ right = null;
283
+ }
284
+ log.timeEnd(2, 'clipping tile')();
285
+ stack.push(tl || [], z + 1, x * 2, y * 2);
286
+ stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
287
+ stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
288
+ stack.push(br || [], z + 1, x * 2 + 1, y * 2 + 1);
289
+ }
290
+ }
291
+ }
292
+ function toID(z, x, y) {
293
+ return ((1 << z) * y + x) * 32 + z;
294
+ }
295
+ // eslint-disable-next-line max-statements, complexity
296
+ function convertToGeoJSONTable(vtTile, props) {
297
+ const features = [];
298
+ for (const rawFeature of vtTile.features) {
299
+ if (!rawFeature || !rawFeature.geometry) {
300
+ continue;
301
+ }
302
+ let type;
303
+ let coordinates;
304
+ // raw geometry
305
+ switch (rawFeature.type) {
306
+ case 1:
307
+ if (rawFeature.geometry.length === 1) {
308
+ type = 'Point';
309
+ coordinates = rawFeature.geometry[0];
310
+ }
311
+ else {
312
+ type = 'MultiPoint';
313
+ coordinates = rawFeature.geometry;
314
+ }
315
+ break;
316
+ case 2:
317
+ if (rawFeature.geometry.length === 1) {
318
+ type = 'LineString';
319
+ coordinates = rawFeature.geometry[0];
320
+ }
321
+ else {
322
+ type = 'MultiLineString';
323
+ coordinates = rawFeature.geometry;
324
+ }
325
+ break;
326
+ case 3:
327
+ if (rawFeature.geometry.length > 1) {
328
+ type = 'MultiPolygon';
329
+ coordinates = [rawFeature.geometry];
330
+ }
331
+ else {
332
+ type = 'Polygon';
333
+ coordinates = rawFeature.geometry;
334
+ }
335
+ break;
336
+ default:
337
+ continue;
338
+ }
339
+ switch (props.coordinates) {
340
+ case 'EPSG:4326':
341
+ case 'wgs84':
342
+ projectToLngLat(coordinates, props.tileIndex, props.extent);
343
+ break;
344
+ case 'local':
345
+ convertToLocalCoordinates(coordinates, props.extent);
346
+ break;
347
+ default:
348
+ throw new Error(`Unsupported CRS ${props.coordinates}`);
349
+ }
350
+ const feature = {
351
+ type: 'Feature',
352
+ geometry: {
353
+ type,
354
+ coordinates
355
+ },
356
+ properties: rawFeature.tags || {},
357
+ id: rawFeature.id
358
+ };
359
+ features.push(feature);
360
+ }
361
+ if (features.length === 0) {
362
+ return null;
363
+ }
364
+ const table = {
365
+ shape: 'geojson-table',
366
+ type: 'FeatureCollection',
367
+ features
368
+ };
369
+ return table;
370
+ }
@@ -4,7 +4,7 @@
4
4
  import { parseTileJSON } from "./lib/parse-tilejson.js";
5
5
  // __VERSION__ is injected by babel-plugin-version-inline
6
6
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
- const VERSION = typeof "4.2.0" !== 'undefined' ? "4.2.0" : 'latest';
7
+ const VERSION = typeof "4.3.0-alpha.1" !== 'undefined' ? "4.3.0-alpha.1" : 'latest';
8
8
  /**
9
9
  * Loader for TileJSON metadata
10
10
  */
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": "4.2.1",
4
+ "version": "4.3.0-alpha.2",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "publishConfig": {
@@ -41,11 +41,12 @@
41
41
  "build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
42
42
  },
43
43
  "dependencies": {
44
- "@loaders.gl/gis": "4.2.1",
45
- "@loaders.gl/images": "4.2.1",
46
- "@loaders.gl/loader-utils": "4.2.1",
47
- "@loaders.gl/schema": "4.2.1",
44
+ "@loaders.gl/gis": "4.3.0-alpha.2",
45
+ "@loaders.gl/images": "4.3.0-alpha.2",
46
+ "@loaders.gl/loader-utils": "4.3.0-alpha.2",
47
+ "@loaders.gl/schema": "4.3.0-alpha.2",
48
48
  "@math.gl/polygon": "^4.0.0",
49
+ "@probe.gl/stats": "^4.0.0",
49
50
  "pbf": "^3.2.1"
50
51
  },
51
52
  "devDependencies": {
@@ -54,5 +55,5 @@
54
55
  "peerDependencies": {
55
56
  "@loaders.gl/core": "^4.0.0"
56
57
  },
57
- "gitHead": "b2ea799ff9f233ab8af0a6c3696e28ddf6e3c5a3"
58
+ "gitHead": "77a3cb538ab7a1fbf74245f25590210451689f5c"
58
59
  }
package/src/index.ts CHANGED
@@ -11,7 +11,7 @@ export {TileJSONLoader} from './tilejson-loader';
11
11
 
12
12
  export {MVTSource} from './mvt-source';
13
13
 
14
- // GeoJSONTiler
14
+ // TableTileSource
15
15
 
16
- export type {GeoJSONTilerOptions} from './lib/geojson-tiler/geojson-tiler';
17
- export {GeoJSONTiler} from './lib/geojson-tiler/geojson-tiler';
16
+ export type {TableTileSourceProps} from './table-tile-source';
17
+ export {TableTileSource} from './table-tile-source';