@loaders.gl/mvt 4.3.0-alpha.2 → 4.3.0-alpha.4
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.
- package/dist/dist.dev.js +821 -680
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +795 -656
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/lib/get-schemas-from-tilejson.d.ts +4 -0
- package/dist/lib/get-schemas-from-tilejson.d.ts.map +1 -0
- package/dist/lib/get-schemas-from-tilejson.js +55 -0
- package/dist/lib/parse-tilejson.d.ts +9 -4
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.js +6 -6
- package/dist/lib/types.d.ts +39 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +1 -1
- package/dist/lib/utils/geometry-utils.js +1 -1
- package/dist/lib/vector-tiler/{clip.d.ts → features/clip-features.d.ts} +4 -4
- package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{clip.js → features/clip-features.js} +4 -4
- package/dist/lib/vector-tiler/{convert.d.ts → features/convert-feature.d.ts} +7 -7
- package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
- package/dist/lib/vector-tiler/{simplify.d.ts → features/simplify-path.d.ts} +2 -2
- package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{simplify.js → features/simplify-path.js} +3 -3
- package/dist/lib/vector-tiler/{wrap.d.ts → features/wrap-features.d.ts} +5 -5
- package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{wrap.js → features/wrap-features.js} +33 -26
- package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
- package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/proto-tile.js +138 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
- package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/transform-tile.js +41 -0
- package/dist/mvt-loader.d.ts +2 -0
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-source.d.ts +31 -14
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +26 -6
- package/dist/mvt-worker.js +4 -4
- package/dist/table-tile-source.d.ts +66 -36
- package/dist/table-tile-source.d.ts.map +1 -1
- package/dist/table-tile-source.js +167 -117
- package/dist/tilejson-loader.js +1 -1
- package/package.json +9 -6
- package/src/index.ts +13 -6
- package/src/lib/get-schemas-from-tilejson.ts +64 -0
- package/src/lib/parse-tilejson.ts +19 -12
- package/src/lib/types.ts +40 -2
- package/src/lib/utils/geometry-utils.ts +1 -1
- package/src/lib/vector-tiler/{clip.ts → features/clip-features.ts} +8 -8
- package/src/lib/vector-tiler/{convert.ts → features/convert-feature.ts} +91 -70
- package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
- package/src/lib/vector-tiler/{simplify.ts → features/simplify-path.ts} +8 -3
- package/src/lib/vector-tiler/{wrap.ts → features/wrap-features.ts} +44 -29
- package/src/lib/vector-tiler/proto-tile.ts +217 -0
- package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
- package/src/lib/vector-tiler/transform-tile.ts +57 -0
- package/src/mvt-loader.ts +2 -0
- package/src/mvt-source.ts +42 -18
- package/src/table-tile-source.ts +130 -85
- package/src/tilejson-loader.ts +2 -2
- package/dist/lib/vector-tiler/clip.d.ts.map +0 -1
- package/dist/lib/vector-tiler/convert.d.ts.map +0 -1
- package/dist/lib/vector-tiler/convert.js +0 -139
- package/dist/lib/vector-tiler/feature.d.ts +0 -3
- package/dist/lib/vector-tiler/feature.d.ts.map +0 -1
- package/dist/lib/vector-tiler/feature.js +0 -44
- package/dist/lib/vector-tiler/simplify.d.ts.map +0 -1
- package/dist/lib/vector-tiler/tile.d.ts +0 -38
- package/dist/lib/vector-tiler/tile.d.ts.map +0 -1
- package/dist/lib/vector-tiler/tile.js +0 -123
- package/dist/lib/vector-tiler/transform.d.ts +0 -7
- package/dist/lib/vector-tiler/transform.d.ts.map +0 -1
- package/dist/lib/vector-tiler/transform.js +0 -41
- package/dist/lib/vector-tiler/wrap.d.ts.map +0 -1
- package/src/lib/vector-tiler/feature.ts +0 -47
- package/src/lib/vector-tiler/tile.ts +0 -187
- package/src/lib/vector-tiler/transform.ts +0 -57
|
@@ -1,31 +1,60 @@
|
|
|
1
|
-
import type { VectorTileSourceProps, GetTileDataParameters, GetTileParameters } from '@loaders.gl/loader-utils';
|
|
2
|
-
import { VectorTileSource } from '@loaders.gl/loader-utils';
|
|
1
|
+
import type { VectorTileSourceProps, GetTileDataParameters, GetTileParameters, LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { VectorTileSource, TileSourceMetadata } from '@loaders.gl/loader-utils';
|
|
3
3
|
import { Schema, GeoJSONTable, Feature, BinaryFeatureCollection } from '@loaders.gl/schema';
|
|
4
4
|
import { Stats } from '@probe.gl/stats';
|
|
5
|
-
import type {
|
|
5
|
+
import type { ProtoFeature } from "./lib/vector-tiler/features/proto-feature.js";
|
|
6
|
+
import type { ProtoTile } from "./lib/vector-tiler/proto-tile.js";
|
|
6
7
|
/** Options to configure tiling */
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
8
|
+
export declare const TableTileSource: {
|
|
9
|
+
readonly name: "TableTiler";
|
|
10
|
+
readonly id: "table-tiler";
|
|
11
|
+
readonly version: "0.0.0";
|
|
12
|
+
readonly extensions: ["mvt"];
|
|
13
|
+
readonly mimeTypes: ["application/octet-stream"];
|
|
14
|
+
readonly options: {
|
|
15
|
+
readonly table: {
|
|
16
|
+
readonly coordinates: "local";
|
|
17
|
+
readonly promoteId: never;
|
|
18
|
+
readonly maxZoom: 14;
|
|
19
|
+
readonly indexMaxZoom: 5;
|
|
20
|
+
readonly maxPointsPerTile: 10000;
|
|
21
|
+
readonly tolerance: 3;
|
|
22
|
+
readonly extent: 4096;
|
|
23
|
+
readonly buffer: 64;
|
|
24
|
+
readonly generateId: undefined;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
readonly type: "table";
|
|
28
|
+
readonly testURL: (url: string) => boolean;
|
|
29
|
+
readonly createDataSource: (url: string | Blob | GeoJSONTable | Promise<GeoJSONTable>, options: DynamicVectorTileSourceProps) => DynamicVectorTileSource;
|
|
30
|
+
};
|
|
31
|
+
/** Options to configure tiling */
|
|
32
|
+
export type DynamicVectorTileSourceProps = VectorTileSourceProps & {
|
|
33
|
+
table: {
|
|
34
|
+
coordinates: 'local' | 'wgs84' | 'EPSG:4326';
|
|
35
|
+
/** max zoom to preserve detail on */
|
|
36
|
+
maxZoom?: number;
|
|
37
|
+
/** max zoom in the tile index */
|
|
38
|
+
indexMaxZoom?: number;
|
|
39
|
+
/** max number of points per tile in the tile index */
|
|
40
|
+
maxPointsPerTile?: number;
|
|
41
|
+
/** simplification tolerance (higher means simpler) */
|
|
42
|
+
tolerance?: number;
|
|
43
|
+
/** tile extent */
|
|
44
|
+
extent?: number;
|
|
45
|
+
/** tile buffer on each side */
|
|
46
|
+
buffer?: number;
|
|
47
|
+
/** name of a feature property to be promoted to feature.id */
|
|
48
|
+
promoteId?: string;
|
|
49
|
+
/** whether to generate feature ids. Cannot be used with promoteId */
|
|
50
|
+
generateId?: boolean;
|
|
51
|
+
/** logging level (0, 1 or 2) */
|
|
52
|
+
debug?: number;
|
|
53
|
+
/** whether to calculate line metrics */
|
|
54
|
+
lineMetrics?: boolean;
|
|
55
|
+
/** table loders */
|
|
56
|
+
loaders?: LoaderWithParser[];
|
|
57
|
+
};
|
|
29
58
|
};
|
|
30
59
|
/**
|
|
31
60
|
* Dynamically vector tiles a table (the table needs a geometry column)
|
|
@@ -42,20 +71,19 @@ export type TableTileSourceProps = VectorTileSourceProps & {
|
|
|
42
71
|
* @todo - generate binary output tables
|
|
43
72
|
* @todo - how does TileSourceLayer specify coordinates / decided which layer to render with
|
|
44
73
|
*/
|
|
45
|
-
export declare class
|
|
46
|
-
|
|
47
|
-
/** Global stats for all TableTileSources */
|
|
74
|
+
export declare class DynamicVectorTileSource implements VectorTileSource<DynamicVectorTileSourceProps, TileSourceMetadata> {
|
|
75
|
+
/** Global stats for all DynamicVectorTileSources */
|
|
48
76
|
static stats: Stats;
|
|
49
|
-
/** Stats for this
|
|
77
|
+
/** Stats for this DynamicVectorTileSource */
|
|
50
78
|
stats: Stats;
|
|
51
79
|
/** MIME type of the tiles emitted by this tile source */
|
|
52
80
|
readonly mimeType = "application/vnd.mapbox-vector-tile";
|
|
53
81
|
readonly localCoordinates = true;
|
|
54
82
|
/** The props that this tile source was created with */
|
|
55
|
-
props: Required<
|
|
83
|
+
props: Required<DynamicVectorTileSourceProps['table']>;
|
|
56
84
|
schema: Schema | null;
|
|
57
85
|
/** Map of generated tiles, indexed by stringified tile coordinates */
|
|
58
|
-
tiles: Record<string,
|
|
86
|
+
tiles: Record<string, ProtoTile>;
|
|
59
87
|
/** Array of tile coordinates */
|
|
60
88
|
tileCoords: {
|
|
61
89
|
x: number;
|
|
@@ -66,9 +94,11 @@ export declare class TableTileSource implements VectorTileSource<any> {
|
|
|
66
94
|
ready: Promise<void>;
|
|
67
95
|
/** Metadata for the tile source (generated TileJSON/tilestats */
|
|
68
96
|
metadata: Promise<unknown>;
|
|
69
|
-
constructor(table: GeoJSONTable | Promise<GeoJSONTable>, props?:
|
|
97
|
+
constructor(table: GeoJSONTable | Promise<GeoJSONTable>, props?: DynamicVectorTileSourceProps);
|
|
70
98
|
initializeTilesAsync(tablePromise: GeoJSONTable | Promise<GeoJSONTable>): Promise<void>;
|
|
71
|
-
getMetadata(): Promise<
|
|
99
|
+
getMetadata(): Promise<TileSourceMetadata & {
|
|
100
|
+
schema: Schema | null;
|
|
101
|
+
}>;
|
|
72
102
|
getSchema(): Promise<Schema>;
|
|
73
103
|
/**
|
|
74
104
|
* Get a tile at the specified index
|
|
@@ -100,11 +130,11 @@ export declare class TableTileSource implements VectorTileSource<any> {
|
|
|
100
130
|
* Return geojsonvt-style "half formed" vector tile
|
|
101
131
|
* @note Application must await `source.ready` before calling sync methods.
|
|
102
132
|
*/
|
|
103
|
-
|
|
133
|
+
getProtoTile(tileIndex: {
|
|
104
134
|
z: number;
|
|
105
135
|
x: number;
|
|
106
136
|
y: number;
|
|
107
|
-
}):
|
|
137
|
+
}): ProtoTile | null;
|
|
108
138
|
/**
|
|
109
139
|
* splits features from a parent tile to sub-tiles.
|
|
110
140
|
* @param z, x, and y are the coordinates of the parent tile
|
|
@@ -113,6 +143,6 @@ export declare class TableTileSource implements VectorTileSource<any> {
|
|
|
113
143
|
* If no target tile is specified, splitting stops when we reach the maximum
|
|
114
144
|
* zoom or the number of points is low as specified in the props.
|
|
115
145
|
*/
|
|
116
|
-
splitTile(features:
|
|
146
|
+
splitTile(features: ProtoFeature[], z: number, x: number, y: number, cz?: number, cx?: number, cy?: number): void;
|
|
117
147
|
}
|
|
118
148
|
//# sourceMappingURL=table-tile-source.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-tile-source.d.ts","sourceRoot":"","sources":["../src/table-tile-source.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"table-tile-source.d.ts","sourceRoot":"","sources":["../src/table-tile-source.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAM,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,uBAAuB,EAAC,MAAM,oBAAoB,CAAC;AAE1F,OAAO,EAAC,KAAK,EAAO,MAAM,iBAAiB,CAAC;AAE5C,OAAO,KAAK,EAAC,YAAY,EAAC,qDAAkD;AAC5E,OAAO,KAAK,EAAC,SAAS,EAAC,yCAAsC;AAQ7D,kCAAkC;AAClC,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;4BAoBX,MAAM,KAAG,OAAO;qCAExB,MAAM,GAAG,IAAI,GAAG,YAAY,GAAG,QAAQ,YAAY,CAAC,WAChD,4BAA4B,KACpC,uBAAuB;CAOsD,CAAC;AAanF,kCAAkC;AAClC,MAAM,MAAM,4BAA4B,GAAG,qBAAqB,GAAG;IACjE,KAAK,EAAE;QACL,WAAW,EAAE,OAAO,GAAG,OAAO,GAAG,WAAW,CAAC;QAC7C,qCAAqC;QACrC,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,iCAAiC;QACjC,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,sDAAsD;QACtD,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,sDAAsD;QACtD,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,kBAAkB;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,+BAA+B;QAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB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at } from '@probe.gl/stats';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
8
|
+
import { createProtoTile } from "./lib/vector-tiler/proto-tile.js";
|
|
9
|
+
import { transformTile } from "./lib/vector-tiler/transform-tile.js"; // coordinate transformation
|
|
10
|
+
import { convertTileToGeoJSON } from "./lib/vector-tiler/tile-to-geojson.js"; // tile clipping and wrapping
|
|
11
|
+
import { convertFeaturesToProtoFeature } from "./lib/vector-tiler/features/convert-feature.js";
|
|
12
|
+
import { clipFeatures } from "./lib/vector-tiler/features/clip-features.js"; // stripe clipping algorithm
|
|
13
|
+
import { wrapFeatures } from "./lib/vector-tiler/features/wrap-features.js"; // date line processing
|
|
14
|
+
/** Options to configure tiling */
|
|
15
|
+
export const TableTileSource = {
|
|
16
|
+
name: 'TableTiler',
|
|
17
|
+
id: 'table-tiler',
|
|
18
|
+
version: '0.0.0',
|
|
19
|
+
extensions: ['mvt'],
|
|
20
|
+
mimeTypes: ['application/octet-stream'],
|
|
21
|
+
options: {
|
|
22
|
+
table: {
|
|
23
|
+
coordinates: 'local',
|
|
24
|
+
promoteId: undefined,
|
|
25
|
+
maxZoom: 14,
|
|
26
|
+
indexMaxZoom: 5,
|
|
27
|
+
maxPointsPerTile: 10000,
|
|
28
|
+
tolerance: 3,
|
|
29
|
+
extent: 4096,
|
|
30
|
+
buffer: 64,
|
|
31
|
+
generateId: undefined
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
type: 'table',
|
|
35
|
+
testURL: (url) => url.endsWith('.geojson'),
|
|
36
|
+
createDataSource(url, options) {
|
|
37
|
+
const needsLoading = typeof url === 'string' || url instanceof Blob;
|
|
38
|
+
const loader = options?.table?.loaders?.[0];
|
|
39
|
+
const tablePromise = needsLoading ? loadTable(url, loader) : url;
|
|
40
|
+
return new DynamicVectorTileSource(tablePromise, options);
|
|
41
|
+
}
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
};
|
|
44
|
+
async function loadTable(url, loader) {
|
|
45
|
+
if (typeof url === 'string') {
|
|
46
|
+
const response = await fetch(url);
|
|
47
|
+
const data = await response.arrayBuffer();
|
|
48
|
+
return (await loader.parse(data));
|
|
49
|
+
}
|
|
50
|
+
const data = await url.arrayBuffer();
|
|
51
|
+
return (await loader.parse(data)); // options.loaders, options.loadOptions)
|
|
52
|
+
}
|
|
15
53
|
/**
|
|
16
54
|
* Dynamically vector tiles a table (the table needs a geometry column)
|
|
17
55
|
* - Tiles are generated when requested.
|
|
@@ -27,27 +65,13 @@ import { convertToLocalCoordinates } from "./lib/utils/geometry-utils.js";
|
|
|
27
65
|
* @todo - generate binary output tables
|
|
28
66
|
* @todo - how does TileSourceLayer specify coordinates / decided which layer to render with
|
|
29
67
|
*/
|
|
30
|
-
export class
|
|
31
|
-
|
|
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 */
|
|
68
|
+
export class DynamicVectorTileSource {
|
|
69
|
+
/** Global stats for all DynamicVectorTileSources */
|
|
46
70
|
static stats = new Stats({
|
|
47
71
|
id: 'table-tile-source-all',
|
|
48
72
|
stats: [new Stat('count', 'tiles'), new Stat('count', 'features')]
|
|
49
73
|
});
|
|
50
|
-
/** Stats for this
|
|
74
|
+
/** Stats for this DynamicVectorTileSource */
|
|
51
75
|
stats = new Stats({
|
|
52
76
|
id: 'table-tile-source',
|
|
53
77
|
stats: [new Stat('tiles', 'count'), new Stat('features', 'count')]
|
|
@@ -56,6 +80,7 @@ export class TableTileSource {
|
|
|
56
80
|
mimeType = 'application/vnd.mapbox-vector-tile';
|
|
57
81
|
localCoordinates = true;
|
|
58
82
|
/** The props that this tile source was created with */
|
|
83
|
+
// @ts-expect-error
|
|
59
84
|
props;
|
|
60
85
|
/* Schema of the data */
|
|
61
86
|
schema = null;
|
|
@@ -68,7 +93,8 @@ export class TableTileSource {
|
|
|
68
93
|
/** Metadata for the tile source (generated TileJSON/tilestats */
|
|
69
94
|
metadata;
|
|
70
95
|
constructor(table, props) {
|
|
71
|
-
|
|
96
|
+
// @ts-expect-error
|
|
97
|
+
this.props = { ...TableTileSource.options.table, ...props?.table };
|
|
72
98
|
this.getTileData = this.getTileData.bind(this);
|
|
73
99
|
this.ready = this.initializeTilesAsync(table);
|
|
74
100
|
this.metadata = this.getMetadata();
|
|
@@ -112,11 +138,11 @@ export class TableTileSource {
|
|
|
112
138
|
* @note Application must await `source.ready` before calling sync methods.
|
|
113
139
|
*/
|
|
114
140
|
getTileSync(tileIndex) {
|
|
115
|
-
const
|
|
116
|
-
if (!
|
|
141
|
+
const protoTile = this.getProtoTile(tileIndex);
|
|
142
|
+
if (!protoTile) {
|
|
117
143
|
return null;
|
|
118
144
|
}
|
|
119
|
-
return
|
|
145
|
+
return convertTileToGeoJSON(protoTile, {
|
|
120
146
|
coordinates: this.props.coordinates,
|
|
121
147
|
tileIndex,
|
|
122
148
|
extent: this.props.extent
|
|
@@ -133,31 +159,31 @@ export class TableTileSource {
|
|
|
133
159
|
if (this.props.promoteId && this.props.generateId) {
|
|
134
160
|
throw new Error('promoteId and generateId cannot be used together.');
|
|
135
161
|
}
|
|
136
|
-
log.log(1, '
|
|
162
|
+
log.log(1, 'DynamicVectorTileSource creating root tiles', this.props)();
|
|
137
163
|
// projects and adds simplification info
|
|
138
164
|
log.time(1, 'preprocess table')();
|
|
139
|
-
let features =
|
|
165
|
+
let features = convertFeaturesToProtoFeature(table, this.props);
|
|
140
166
|
log.timeEnd(1, 'preprocess table')();
|
|
141
167
|
// wraps features (ie extreme west and extreme east)
|
|
142
168
|
log.time(1, 'generate tiles')();
|
|
143
|
-
features =
|
|
169
|
+
features = wrapFeatures(features, this.props);
|
|
144
170
|
// start slicing from the top tile down
|
|
145
171
|
if (features.length === 0) {
|
|
146
|
-
log.log(1, '
|
|
172
|
+
log.log(1, 'DynamicVectorTileSource: no features generated')();
|
|
147
173
|
return;
|
|
148
174
|
}
|
|
149
175
|
this.splitTile(features, 0, 0, 0);
|
|
150
176
|
const rootTile = this.tiles[0];
|
|
151
177
|
log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
|
|
152
178
|
log.timeEnd(1, 'generate tiles')();
|
|
153
|
-
log.log(1, `
|
|
179
|
+
log.log(1, `DynamicVectorTileSource: tiles generated: ${this.stats.get('total').count}`, this.stats)();
|
|
154
180
|
}
|
|
155
181
|
/**
|
|
156
182
|
* Return geojsonvt-style "half formed" vector tile
|
|
157
183
|
* @note Application must await `source.ready` before calling sync methods.
|
|
158
184
|
*/
|
|
159
185
|
// eslint-disable-next-line complexity, max-statements
|
|
160
|
-
|
|
186
|
+
getProtoTile(tileIndex) {
|
|
161
187
|
const { z, y } = tileIndex;
|
|
162
188
|
let { x } = tileIndex;
|
|
163
189
|
// z = +z;
|
|
@@ -168,7 +194,7 @@ export class TableTileSource {
|
|
|
168
194
|
return null;
|
|
169
195
|
}
|
|
170
196
|
const z2 = 1 << z;
|
|
171
|
-
x = (x + z2) & (z2 - 1); //
|
|
197
|
+
x = (x + z2) & (z2 - 1); // wrapFeatures tile x coordinate
|
|
172
198
|
const id = toID(z, x, y);
|
|
173
199
|
if (this.tiles[id]) {
|
|
174
200
|
return transformTile(this.tiles[id], extent);
|
|
@@ -184,13 +210,13 @@ export class TableTileSource {
|
|
|
184
210
|
y0 = y0 >> 1;
|
|
185
211
|
parent = this.tiles[toID(z0, x0, y0)];
|
|
186
212
|
}
|
|
187
|
-
if (!parent || !parent.
|
|
213
|
+
if (!parent || !parent.sourceFeatures) {
|
|
188
214
|
return null;
|
|
189
215
|
}
|
|
190
216
|
// if we found a parent tile containing the original geometry, we can drill down from it
|
|
191
217
|
log.log(1, 'found parent tile z%d-%d-%d', z0, x0, y0)();
|
|
192
218
|
log.time(1, 'drilling down')();
|
|
193
|
-
this.splitTile(parent.
|
|
219
|
+
this.splitTile(parent.sourceFeatures, z0, x0, y0, z, x, y);
|
|
194
220
|
log.timeEnd(1, 'drilling down')();
|
|
195
221
|
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
|
|
196
222
|
}
|
|
@@ -216,23 +242,23 @@ export class TableTileSource {
|
|
|
216
242
|
let tile = this.tiles[id];
|
|
217
243
|
if (!tile) {
|
|
218
244
|
log.time(2, 'tile creation')();
|
|
219
|
-
tile = this.tiles[id] =
|
|
245
|
+
tile = this.tiles[id] = createProtoTile(features, z, x, y, this.props);
|
|
220
246
|
this.tileCoords.push({ z, x, y });
|
|
221
247
|
const key = `z${z}`;
|
|
222
248
|
let stat = this.stats.get(key, 'count');
|
|
223
249
|
stat.incrementCount();
|
|
224
250
|
stat = this.stats.get('total');
|
|
225
251
|
stat.incrementCount();
|
|
226
|
-
stat =
|
|
252
|
+
stat = DynamicVectorTileSource.stats.get(key, 'count');
|
|
227
253
|
stat.incrementCount();
|
|
228
|
-
stat =
|
|
254
|
+
stat = DynamicVectorTileSource.stats.get('total');
|
|
229
255
|
stat.incrementCount();
|
|
230
256
|
log.log(2, 'tile z%d-%d-%d (features: %d, points: %d, simplified: %d)', z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified)();
|
|
231
257
|
log.timeEnd(2, 'tile creation')();
|
|
232
258
|
}
|
|
233
259
|
// save reference to original geometry in tile so that we can drill down later if we stop now
|
|
234
|
-
tile.
|
|
235
|
-
|
|
260
|
+
tile.sourceFeatures = features;
|
|
261
|
+
/* eslint-disable no-continue */
|
|
236
262
|
// if it's the first-pass tiling
|
|
237
263
|
if (cz === undefined) {
|
|
238
264
|
// stop tiling if we reached max zoom, or if the tile is too simple
|
|
@@ -254,7 +280,7 @@ export class TableTileSource {
|
|
|
254
280
|
}
|
|
255
281
|
}
|
|
256
282
|
// if we slice further down, no need to keep source geometry
|
|
257
|
-
tile.
|
|
283
|
+
tile.sourceFeatures = null;
|
|
258
284
|
if (features.length === 0)
|
|
259
285
|
continue;
|
|
260
286
|
log.time(2, 'clipping tile')();
|
|
@@ -267,18 +293,18 @@ export class TableTileSource {
|
|
|
267
293
|
let bl = null;
|
|
268
294
|
let tr = null;
|
|
269
295
|
let br = null;
|
|
270
|
-
let left =
|
|
271
|
-
let right =
|
|
296
|
+
let left = clipFeatures(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
|
|
297
|
+
let right = clipFeatures(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
|
|
272
298
|
// @ts-expect-error - unclear why this is needed?
|
|
273
299
|
features = null;
|
|
274
300
|
if (left) {
|
|
275
|
-
tl =
|
|
276
|
-
bl =
|
|
301
|
+
tl = clipFeatures(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
|
|
302
|
+
bl = clipFeatures(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
|
|
277
303
|
left = null;
|
|
278
304
|
}
|
|
279
305
|
if (right) {
|
|
280
|
-
tr =
|
|
281
|
-
br =
|
|
306
|
+
tr = clipFeatures(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
|
|
307
|
+
br = clipFeatures(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
|
|
282
308
|
right = null;
|
|
283
309
|
}
|
|
284
310
|
log.timeEnd(2, 'clipping tile')();
|
|
@@ -292,79 +318,103 @@ export class TableTileSource {
|
|
|
292
318
|
function toID(z, x, y) {
|
|
293
319
|
return ((1 << z) * y + x) * 32 + z;
|
|
294
320
|
}
|
|
321
|
+
/*
|
|
322
|
+
|
|
295
323
|
// eslint-disable-next-line max-statements, complexity
|
|
296
|
-
function convertToGeoJSONTable(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
324
|
+
function convertToGeoJSONTable(
|
|
325
|
+
vtTile: ProtoTile,
|
|
326
|
+
props: {
|
|
327
|
+
coordinates: 'local' | 'wgs84' | 'EPSG:4326';
|
|
328
|
+
tileIndex: {x: number; y: number; z: number};
|
|
329
|
+
extent: number;
|
|
330
|
+
}
|
|
331
|
+
): GeoJSONTable | null {
|
|
332
|
+
const features: Feature[] = [];
|
|
333
|
+
for (const rawFeature of vtTile.features) {
|
|
334
|
+
if (!rawFeature || !rawFeature.geometry) {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
let type:
|
|
339
|
+
| 'Point'
|
|
340
|
+
| 'MultiPoint'
|
|
341
|
+
| 'LineString'
|
|
342
|
+
| 'MultiLineString'
|
|
343
|
+
| 'Polygon'
|
|
344
|
+
| 'MultiPolygon';
|
|
345
|
+
|
|
346
|
+
let coordinates: any;
|
|
347
|
+
|
|
348
|
+
// raw geometry
|
|
349
|
+
switch (rawFeature.type) {
|
|
350
|
+
case 1:
|
|
351
|
+
if (rawFeature.geometry.length === 1) {
|
|
352
|
+
type = 'Point';
|
|
353
|
+
coordinates = rawFeature.geometry[0];
|
|
354
|
+
} else {
|
|
355
|
+
type = 'MultiPoint';
|
|
356
|
+
coordinates = rawFeature.geometry;
|
|
301
357
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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;
|
|
358
|
+
break;
|
|
359
|
+
case 2:
|
|
360
|
+
if (rawFeature.geometry.length === 1) {
|
|
361
|
+
type = 'LineString';
|
|
362
|
+
coordinates = rawFeature.geometry[0];
|
|
363
|
+
} else {
|
|
364
|
+
type = 'MultiLineString';
|
|
365
|
+
coordinates = rawFeature.geometry;
|
|
338
366
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
default:
|
|
348
|
-
throw new Error(`Unsupported CRS ${props.coordinates}`);
|
|
367
|
+
break;
|
|
368
|
+
case 3:
|
|
369
|
+
if (rawFeature.geometry.length > 1) {
|
|
370
|
+
type = 'MultiPolygon';
|
|
371
|
+
coordinates = [rawFeature.geometry];
|
|
372
|
+
} else {
|
|
373
|
+
type = 'Polygon';
|
|
374
|
+
coordinates = rawFeature.geometry;
|
|
349
375
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
type,
|
|
354
|
-
coordinates
|
|
355
|
-
},
|
|
356
|
-
properties: rawFeature.tags || {},
|
|
357
|
-
id: rawFeature.id
|
|
358
|
-
};
|
|
359
|
-
features.push(feature);
|
|
376
|
+
break;
|
|
377
|
+
default:
|
|
378
|
+
continue;
|
|
360
379
|
}
|
|
361
|
-
|
|
362
|
-
|
|
380
|
+
|
|
381
|
+
switch (props.coordinates) {
|
|
382
|
+
case 'EPSG:4326':
|
|
383
|
+
case 'wgs84':
|
|
384
|
+
projectToLngLat(coordinates, props.tileIndex, props.extent);
|
|
385
|
+
break;
|
|
386
|
+
|
|
387
|
+
case 'local':
|
|
388
|
+
convertToLocalCoordinates(coordinates, props.extent);
|
|
389
|
+
break;
|
|
390
|
+
|
|
391
|
+
default:
|
|
392
|
+
throw new Error(`Unsupported CRS ${props.coordinates}`);
|
|
363
393
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
394
|
+
|
|
395
|
+
const feature: Feature = {
|
|
396
|
+
type: 'Feature',
|
|
397
|
+
geometry: {
|
|
398
|
+
type,
|
|
399
|
+
coordinates
|
|
400
|
+
},
|
|
401
|
+
properties: rawFeature.tags || {},
|
|
402
|
+
id: rawFeature.id
|
|
368
403
|
};
|
|
369
|
-
|
|
404
|
+
|
|
405
|
+
features.push(feature);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (features.length === 0) {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const table: GeoJSONTable = {
|
|
413
|
+
shape: 'geojson-table',
|
|
414
|
+
type: 'FeatureCollection',
|
|
415
|
+
features
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
return table;
|
|
370
419
|
}
|
|
420
|
+
*/
|
package/dist/tilejson-loader.js
CHANGED
|
@@ -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.3.0-alpha.
|
|
7
|
+
const VERSION = typeof "4.3.0-alpha.3" !== 'undefined' ? "4.3.0-alpha.3" : '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.3.0-alpha.
|
|
4
|
+
"version": "4.3.0-alpha.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
27
|
"import": "./dist/index.js",
|
|
28
28
|
"require": "./dist/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./mvt-worker.js": {
|
|
31
|
+
"import": "./dist/mvt-worker.js"
|
|
29
32
|
}
|
|
30
33
|
},
|
|
31
34
|
"sideEffects": false,
|
|
@@ -41,10 +44,10 @@
|
|
|
41
44
|
"build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
42
45
|
},
|
|
43
46
|
"dependencies": {
|
|
44
|
-
"@loaders.gl/gis": "4.3.0-alpha.
|
|
45
|
-
"@loaders.gl/images": "4.3.0-alpha.
|
|
46
|
-
"@loaders.gl/loader-utils": "4.3.0-alpha.
|
|
47
|
-
"@loaders.gl/schema": "4.3.0-alpha.
|
|
47
|
+
"@loaders.gl/gis": "4.3.0-alpha.4",
|
|
48
|
+
"@loaders.gl/images": "4.3.0-alpha.4",
|
|
49
|
+
"@loaders.gl/loader-utils": "4.3.0-alpha.4",
|
|
50
|
+
"@loaders.gl/schema": "4.3.0-alpha.4",
|
|
48
51
|
"@math.gl/polygon": "^4.0.0",
|
|
49
52
|
"@probe.gl/stats": "^4.0.0",
|
|
50
53
|
"pbf": "^3.2.1"
|
|
@@ -55,5 +58,5 @@
|
|
|
55
58
|
"peerDependencies": {
|
|
56
59
|
"@loaders.gl/core": "^4.0.0"
|
|
57
60
|
},
|
|
58
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "4900ac4c4de20366c050b80cef04dc5b52d167af"
|
|
59
62
|
}
|