@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
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
5
|
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import type {ProtoFeature} from './proto-feature';
|
|
7
|
+
import {createProtoFeature} from './proto-feature';
|
|
8
|
+
import {clipFeatures} from './clip-features';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Options for wrap()
|
|
12
12
|
*/
|
|
13
|
-
export type
|
|
13
|
+
export type WrapFeaturesOptions = {
|
|
14
14
|
buffer: number /** number of pixels of buffer for the tile */;
|
|
15
15
|
extent: number /** extent of each tile */;
|
|
16
16
|
lineMetrics: boolean;
|
|
@@ -18,18 +18,21 @@ export type WrapOptions = {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Wrap across antemeridian, by clipping into two tiles, shifting the overflowing x coordinates
|
|
21
|
-
* @param
|
|
21
|
+
* @param list of features to be wrapped
|
|
22
22
|
* @param options buffer and extent
|
|
23
23
|
* @returns
|
|
24
24
|
*/
|
|
25
|
-
export function
|
|
25
|
+
export function wrapFeatures(
|
|
26
|
+
features: ProtoFeature[],
|
|
27
|
+
options: WrapFeaturesOptions
|
|
28
|
+
): ProtoFeature[] {
|
|
26
29
|
const buffer = options.buffer / options.extent;
|
|
27
|
-
let merged:
|
|
28
|
-
const left =
|
|
29
|
-
const right =
|
|
30
|
+
let merged: ProtoFeature[] = features;
|
|
31
|
+
const left = clipFeatures(features, 1, -1 - buffer, buffer, 0, -1, 2, options); // left world copy
|
|
32
|
+
const right = clipFeatures(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options); // right world copy
|
|
30
33
|
|
|
31
34
|
if (left || right) {
|
|
32
|
-
merged =
|
|
35
|
+
merged = clipFeatures(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || []; // center world copy
|
|
33
36
|
|
|
34
37
|
if (left) {
|
|
35
38
|
merged = shiftFeatureCoords(left, 1).concat(merged); // merge left into center
|
|
@@ -48,8 +51,8 @@ export function wrap(features: TableTileFeature[], options: WrapOptions) {
|
|
|
48
51
|
* @param offset
|
|
49
52
|
* @returns
|
|
50
53
|
*/
|
|
51
|
-
function shiftFeatureCoords(features:
|
|
52
|
-
const newFeatures:
|
|
54
|
+
function shiftFeatureCoords(features: ProtoFeature[], offset: number): ProtoFeature[] {
|
|
55
|
+
const newFeatures: ProtoFeature[] = [];
|
|
53
56
|
|
|
54
57
|
for (let i = 0; i < features.length; i++) {
|
|
55
58
|
const feature = features[i];
|
|
@@ -57,26 +60,38 @@ function shiftFeatureCoords(features: TableTileFeature[], offset: number): Table
|
|
|
57
60
|
|
|
58
61
|
let newGeometry;
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
// @ts-expect-error TODO
|
|
73
|
-
newPolygon.push(shiftCoords(line, offset));
|
|
63
|
+
switch (type) {
|
|
64
|
+
case 'Point':
|
|
65
|
+
case 'MultiPoint':
|
|
66
|
+
case 'LineString':
|
|
67
|
+
newGeometry = shiftCoords(feature.geometry, offset);
|
|
68
|
+
break;
|
|
69
|
+
|
|
70
|
+
case 'MultiLineString':
|
|
71
|
+
case 'Polygon':
|
|
72
|
+
newGeometry = [];
|
|
73
|
+
for (const line of feature.geometry) {
|
|
74
|
+
newGeometry.push(shiftCoords(line, offset));
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
break;
|
|
77
|
+
|
|
78
|
+
case 'MultiPolygon':
|
|
79
|
+
newGeometry = [];
|
|
80
|
+
for (const polygon of feature.geometry) {
|
|
81
|
+
const newPolygon: Points = [];
|
|
82
|
+
for (const line of polygon) {
|
|
83
|
+
// @ts-expect-error TODO
|
|
84
|
+
newPolygon.push(shiftCoords(line, offset));
|
|
85
|
+
}
|
|
86
|
+
newGeometry.push(newPolygon);
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
default:
|
|
91
|
+
throw new Error(String(type));
|
|
77
92
|
}
|
|
78
93
|
|
|
79
|
-
newFeatures.push(
|
|
94
|
+
newFeatures.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
|
|
80
95
|
}
|
|
81
96
|
|
|
82
97
|
return newFeatures;
|
|
@@ -0,0 +1,217 @@
|
|
|
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 {ProtoFeature} from './features/proto-feature';
|
|
7
|
+
|
|
8
|
+
export type ProtoTile = {
|
|
9
|
+
/** Processed features */
|
|
10
|
+
protoFeatures: ProtoFeature[];
|
|
11
|
+
/** if we slice further down, no need to keep source geometry */
|
|
12
|
+
sourceFeatures: ProtoFeature[] | null;
|
|
13
|
+
|
|
14
|
+
/** Properties */
|
|
15
|
+
tags?: Record<string, string>;
|
|
16
|
+
|
|
17
|
+
/** tile x coordinate */
|
|
18
|
+
x: number;
|
|
19
|
+
/** tile y coordinate */
|
|
20
|
+
y: number;
|
|
21
|
+
/** tile z coordinate */
|
|
22
|
+
z: number;
|
|
23
|
+
|
|
24
|
+
/** spatial extent */
|
|
25
|
+
minX: number;
|
|
26
|
+
/** spatial extent */
|
|
27
|
+
maxX: number;
|
|
28
|
+
/** spatial extent */
|
|
29
|
+
minY: number;
|
|
30
|
+
/** spatial extent */
|
|
31
|
+
maxY: number;
|
|
32
|
+
|
|
33
|
+
/** Whether this tile has been transformed */
|
|
34
|
+
transformed: boolean;
|
|
35
|
+
numPoints: number;
|
|
36
|
+
numSimplified: number;
|
|
37
|
+
/** Number of features in this tile */
|
|
38
|
+
numFeatures: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type CreateTileOptions = {
|
|
42
|
+
maxZoom?: number;
|
|
43
|
+
tolerance: number;
|
|
44
|
+
extent: number;
|
|
45
|
+
lineMetrics: boolean;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Create a tile from features and tile index
|
|
50
|
+
*/
|
|
51
|
+
export function createProtoTile(
|
|
52
|
+
features: ProtoFeature[],
|
|
53
|
+
z,
|
|
54
|
+
tx,
|
|
55
|
+
ty,
|
|
56
|
+
options: CreateTileOptions
|
|
57
|
+
): ProtoTile {
|
|
58
|
+
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
59
|
+
const tile: ProtoTile = {
|
|
60
|
+
protoFeatures: [],
|
|
61
|
+
sourceFeatures: null,
|
|
62
|
+
numPoints: 0,
|
|
63
|
+
numSimplified: 0,
|
|
64
|
+
numFeatures: features.length,
|
|
65
|
+
x: tx,
|
|
66
|
+
y: ty,
|
|
67
|
+
z,
|
|
68
|
+
transformed: false,
|
|
69
|
+
minX: 2,
|
|
70
|
+
minY: 1,
|
|
71
|
+
maxX: -1,
|
|
72
|
+
maxY: 0
|
|
73
|
+
};
|
|
74
|
+
for (const feature of features) {
|
|
75
|
+
addProtoFeature(tile, feature, tolerance, options);
|
|
76
|
+
}
|
|
77
|
+
return tile;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// eslint-disable-next-line complexity, max-statements
|
|
81
|
+
function addProtoFeature(
|
|
82
|
+
tile: ProtoTile,
|
|
83
|
+
feature: ProtoFeature,
|
|
84
|
+
tolerance: number,
|
|
85
|
+
options: CreateTileOptions
|
|
86
|
+
) {
|
|
87
|
+
const geometry = feature.geometry;
|
|
88
|
+
const type = feature.type;
|
|
89
|
+
const simplifiedGeometry: number[] = [];
|
|
90
|
+
|
|
91
|
+
tile.minX = Math.min(tile.minX, feature.minX);
|
|
92
|
+
tile.minY = Math.min(tile.minY, feature.minY);
|
|
93
|
+
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
94
|
+
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
95
|
+
|
|
96
|
+
let simplifiedType: 1 | 2 | 3;
|
|
97
|
+
switch (type) {
|
|
98
|
+
case 'Point':
|
|
99
|
+
case 'MultiPoint':
|
|
100
|
+
simplifiedType = 1;
|
|
101
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
102
|
+
simplifiedGeometry.push(geometry[i], geometry[i + 1]);
|
|
103
|
+
tile.numPoints++;
|
|
104
|
+
tile.numSimplified++;
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
|
|
108
|
+
case 'LineString':
|
|
109
|
+
simplifiedType = 2;
|
|
110
|
+
addProtoLine(simplifiedGeometry, geometry, tile, tolerance, false, false);
|
|
111
|
+
break;
|
|
112
|
+
|
|
113
|
+
case 'MultiLineString':
|
|
114
|
+
simplifiedType = 2;
|
|
115
|
+
for (let i = 0; i < geometry.length; i++) {
|
|
116
|
+
addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, false, i === 0);
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
case 'Polygon':
|
|
121
|
+
simplifiedType = 3;
|
|
122
|
+
for (let i = 0; i < geometry.length; i++) {
|
|
123
|
+
addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, true, i === 0);
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
|
|
127
|
+
case 'MultiPolygon':
|
|
128
|
+
simplifiedType = 3;
|
|
129
|
+
for (let k = 0; k < geometry.length; k++) {
|
|
130
|
+
const polygon = geometry[k];
|
|
131
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
132
|
+
addProtoLine(simplifiedGeometry, polygon[i], tile, tolerance, true, i === 0);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
|
|
137
|
+
default:
|
|
138
|
+
throw new Error(`Unknown geometry type: ${type}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (simplifiedGeometry.length) {
|
|
142
|
+
let tags: Record<string, unknown> | null = feature.tags || null;
|
|
143
|
+
|
|
144
|
+
if (type === 'LineString' && options.lineMetrics) {
|
|
145
|
+
tags = {};
|
|
146
|
+
for (const key in feature.tags) {
|
|
147
|
+
tags[key] = feature.tags[key];
|
|
148
|
+
}
|
|
149
|
+
// @ts-expect-error adding fields to arrays
|
|
150
|
+
// eslint-disable-next-line camelcase
|
|
151
|
+
tags.mapbox_clip_start = geometry.start / geometry.size;
|
|
152
|
+
// @ts-expect-error adding fields to arrays
|
|
153
|
+
// eslint-disable-next-line camelcase
|
|
154
|
+
tags.mapbox_clip_end = geometry.end / geometry.size;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const tileFeature: ProtoFeature = {
|
|
158
|
+
geometry: simplifiedGeometry,
|
|
159
|
+
simplifiedType,
|
|
160
|
+
// @ts-expect-error
|
|
161
|
+
tags
|
|
162
|
+
};
|
|
163
|
+
if (feature.id !== null) {
|
|
164
|
+
tileFeature.id = feature.id;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
tile.protoFeatures.push(tileFeature);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// eslint-disable-next-line max-params, max-statements
|
|
172
|
+
function addProtoLine(
|
|
173
|
+
result: any[],
|
|
174
|
+
geometry: any,
|
|
175
|
+
tile: ProtoTile,
|
|
176
|
+
tolerance: number,
|
|
177
|
+
isPolygon: boolean,
|
|
178
|
+
isOuter: boolean
|
|
179
|
+
): void {
|
|
180
|
+
const sqTolerance = tolerance * tolerance;
|
|
181
|
+
|
|
182
|
+
if (tolerance > 0 && geometry.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
183
|
+
tile.numPoints += geometry.length / 3;
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const ring: number[] = [];
|
|
188
|
+
|
|
189
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
190
|
+
if (tolerance === 0 || geometry[i + 2] > sqTolerance) {
|
|
191
|
+
tile.numSimplified++;
|
|
192
|
+
ring.push(geometry[i], geometry[i + 1]);
|
|
193
|
+
}
|
|
194
|
+
tile.numPoints++;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (isPolygon) rewind(ring, isOuter);
|
|
198
|
+
|
|
199
|
+
result.push(ring);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function rewind(ring: number[], clockwise?: boolean): void {
|
|
203
|
+
let area = 0;
|
|
204
|
+
for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
|
|
205
|
+
area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
|
|
206
|
+
}
|
|
207
|
+
if (area > 0 === clockwise) {
|
|
208
|
+
for (let i = 0, len = ring.length; i < len / 2; i += 2) {
|
|
209
|
+
const x = ring[i];
|
|
210
|
+
const y = ring[i + 1];
|
|
211
|
+
ring[i] = ring[len - 2 - i];
|
|
212
|
+
ring[i + 1] = ring[len - 1 - i];
|
|
213
|
+
ring[len - 2 - i] = x;
|
|
214
|
+
ring[len - 1 - i] = y;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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 {ProtoTile} from './proto-tile';
|
|
7
|
+
import {Feature, GeoJSONTable} from '@loaders.gl/schema';
|
|
8
|
+
|
|
9
|
+
import {projectToLngLat} from '../utils/geometry-utils';
|
|
10
|
+
import {convertToLocalCoordinates} from '../utils/geometry-utils';
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line max-statements, complexity
|
|
13
|
+
export function convertTileToGeoJSON(
|
|
14
|
+
protoTile: ProtoTile,
|
|
15
|
+
props: {
|
|
16
|
+
coordinates: 'EPSG:4326' | 'wgs84' | 'local';
|
|
17
|
+
tileIndex: {x: number; y: number; z: number};
|
|
18
|
+
extent: number;
|
|
19
|
+
}
|
|
20
|
+
): GeoJSONTable | null {
|
|
21
|
+
const features: Feature[] = [];
|
|
22
|
+
for (const rawFeature of protoTile.protoFeatures) {
|
|
23
|
+
if (!rawFeature || !rawFeature.geometry) {
|
|
24
|
+
// eslint-disable-next-line no-continue
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let type:
|
|
29
|
+
| 'Point'
|
|
30
|
+
| 'MultiPoint'
|
|
31
|
+
| 'LineString'
|
|
32
|
+
| 'MultiLineString'
|
|
33
|
+
| 'Polygon'
|
|
34
|
+
| 'MultiPolygon';
|
|
35
|
+
|
|
36
|
+
let coordinates: any;
|
|
37
|
+
|
|
38
|
+
// raw geometry
|
|
39
|
+
switch (rawFeature.simplifiedType) {
|
|
40
|
+
case 1:
|
|
41
|
+
if (rawFeature.geometry.length === 1) {
|
|
42
|
+
type = 'Point';
|
|
43
|
+
coordinates = rawFeature.geometry[0];
|
|
44
|
+
} else {
|
|
45
|
+
type = 'MultiPoint';
|
|
46
|
+
coordinates = rawFeature.geometry;
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
case 2:
|
|
50
|
+
if (rawFeature.geometry.length === 1) {
|
|
51
|
+
type = 'LineString';
|
|
52
|
+
coordinates = rawFeature.geometry[0];
|
|
53
|
+
} else {
|
|
54
|
+
type = 'MultiLineString';
|
|
55
|
+
coordinates = rawFeature.geometry;
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 3:
|
|
59
|
+
if (rawFeature.geometry.length > 1) {
|
|
60
|
+
type = 'MultiPolygon';
|
|
61
|
+
coordinates = [rawFeature.geometry];
|
|
62
|
+
} else {
|
|
63
|
+
type = 'Polygon';
|
|
64
|
+
coordinates = rawFeature.geometry;
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
throw new Error(`${rawFeature.simplifiedType}is not a valid simplified type`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
switch (props.coordinates) {
|
|
72
|
+
case 'EPSG:4326':
|
|
73
|
+
case 'wgs84':
|
|
74
|
+
projectToLngLat(coordinates, props.tileIndex, props.extent);
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
convertToLocalCoordinates(coordinates, props.extent);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const feature: Feature = {
|
|
82
|
+
type: 'Feature',
|
|
83
|
+
geometry: {
|
|
84
|
+
type,
|
|
85
|
+
coordinates
|
|
86
|
+
},
|
|
87
|
+
properties: rawFeature.tags || {},
|
|
88
|
+
id: rawFeature.id
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
features.push(feature);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (features.length === 0) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const table: GeoJSONTable = {
|
|
99
|
+
shape: 'geojson-table',
|
|
100
|
+
type: 'FeatureCollection',
|
|
101
|
+
features
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return table;
|
|
105
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 {ProtoTile} from './proto-tile';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Transforms the coordinates of each protoFeature in the given protoTile from
|
|
10
|
+
* mercator-projected space into (extent x extent) protoTile space.
|
|
11
|
+
*/
|
|
12
|
+
export function transformTile(protoTile: ProtoTile, extent: number): ProtoTile {
|
|
13
|
+
if (protoTile.transformed) {
|
|
14
|
+
return protoTile;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const z2 = 1 << protoTile.z;
|
|
18
|
+
const tx = protoTile.x;
|
|
19
|
+
const ty = protoTile.y;
|
|
20
|
+
|
|
21
|
+
for (const protoFeature of protoTile.protoFeatures) {
|
|
22
|
+
const geom = protoFeature.geometry;
|
|
23
|
+
const simplifiedType = protoFeature.simplifiedType;
|
|
24
|
+
|
|
25
|
+
protoFeature.geometry = [];
|
|
26
|
+
|
|
27
|
+
if (simplifiedType === 1) {
|
|
28
|
+
for (let j = 0; j < geom.length; j += 2) {
|
|
29
|
+
protoFeature.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
|
+
protoFeature.geometry.push(ring);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protoTile.transformed = true;
|
|
43
|
+
|
|
44
|
+
return protoTile;
|
|
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
|
+
}
|
package/src/mvt-loader.ts
CHANGED
|
@@ -26,6 +26,8 @@ export type MVTLoaderOptions = LoaderOptions & {
|
|
|
26
26
|
workerUrl?: string;
|
|
27
27
|
};
|
|
28
28
|
gis?: {
|
|
29
|
+
/** @deprecated Use options.mvt.shape === 'binary-geometry' */
|
|
30
|
+
binary?: boolean;
|
|
29
31
|
/** @deprecated. Use options.mvt.shape */
|
|
30
32
|
format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
31
33
|
};
|
package/src/mvt-source.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import type {Source} from '@loaders.gl/loader-utils';
|
|
5
6
|
import type {ImageType, DataSourceProps} from '@loaders.gl/loader-utils';
|
|
6
7
|
import type {ImageTileSource, VectorTileSource} from '@loaders.gl/loader-utils';
|
|
7
8
|
import type {GetTileParameters, GetTileDataParameters} from '@loaders.gl/loader-utils';
|
|
@@ -15,18 +16,42 @@ import {
|
|
|
15
16
|
TileJSONLoaderOptions
|
|
16
17
|
} from '@loaders.gl/mvt';
|
|
17
18
|
|
|
19
|
+
/** Creates an MVTTileSource */
|
|
20
|
+
export const MVTSource = {
|
|
21
|
+
name: 'MVT',
|
|
22
|
+
id: 'mvt',
|
|
23
|
+
module: 'mvt',
|
|
24
|
+
version: '0.0.0',
|
|
25
|
+
extensions: ['mvt'],
|
|
26
|
+
mimeTypes: ['application/octet-stream'],
|
|
27
|
+
options: {
|
|
28
|
+
mvt: {
|
|
29
|
+
// TODO - add options here
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
type: 'mvt',
|
|
33
|
+
fromUrl: true,
|
|
34
|
+
fromBlob: false,
|
|
35
|
+
|
|
36
|
+
testURL: (url: string): boolean => true,
|
|
37
|
+
createDataSource(url: string, props: MVTTileSourceProps): MVTTileSource {
|
|
38
|
+
return new MVTTileSource(url, props);
|
|
39
|
+
}
|
|
40
|
+
} as const satisfies Source<MVTTileSource, MVTTileSourceProps>;
|
|
41
|
+
|
|
18
42
|
/** Properties for a Mapbox Vector Tile Source */
|
|
19
|
-
export type
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
export type MVTTileSourceProps = DataSourceProps & {
|
|
44
|
+
mvt?: {
|
|
45
|
+
// TODO - add options here
|
|
46
|
+
/** if not supplied, loads tilejson.json, If null does not load metadata */
|
|
47
|
+
metadataUrl?: string | null;
|
|
48
|
+
/** Override extension (necessary if no metadata) */
|
|
49
|
+
extension?: string;
|
|
50
|
+
/** Additional attribution, adds to any attribution loaded from tileset metadata */
|
|
51
|
+
attributions?: string[];
|
|
52
|
+
/** Specify load options for all sub loaders */
|
|
53
|
+
loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
|
|
54
|
+
};
|
|
30
55
|
};
|
|
31
56
|
|
|
32
57
|
/**
|
|
@@ -36,8 +61,8 @@ export type MVTSourceProps = DataSourceProps & {
|
|
|
36
61
|
* A PMTiles data source
|
|
37
62
|
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
38
63
|
*/
|
|
39
|
-
export class
|
|
40
|
-
readonly props:
|
|
64
|
+
export class MVTTileSource extends DataSource implements ImageTileSource, VectorTileSource {
|
|
65
|
+
readonly props: MVTTileSourceProps;
|
|
41
66
|
readonly url: string;
|
|
42
67
|
readonly metadataUrl: string | null = null;
|
|
43
68
|
data: string;
|
|
@@ -46,13 +71,12 @@ export class MVTSource extends DataSource implements ImageTileSource, VectorTile
|
|
|
46
71
|
extension: string;
|
|
47
72
|
mimeType: string | null = null;
|
|
48
73
|
|
|
49
|
-
constructor(props:
|
|
74
|
+
constructor(url: string, props: MVTTileSourceProps) {
|
|
50
75
|
super(props);
|
|
51
76
|
this.props = props;
|
|
52
|
-
this.url = resolvePath(
|
|
53
|
-
this.metadataUrl =
|
|
54
|
-
|
|
55
|
-
this.extension = props.extension || '.png';
|
|
77
|
+
this.url = resolvePath(url);
|
|
78
|
+
this.metadataUrl = props.mvt?.metadataUrl || `${this.url}/tilejson.json`;
|
|
79
|
+
this.extension = props.mvt?.extension || '.png';
|
|
56
80
|
this.data = this.url;
|
|
57
81
|
|
|
58
82
|
this.getTileData = this.getTileData.bind(this);
|