@loaders.gl/mvt 4.3.0-alpha.1 → 4.3.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +1289 -807
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +923 -773
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/lib/parse-mvt.d.ts +1 -1
- package/dist/lib/parse-mvt.js +2 -30
- package/dist/lib/parse-tilejson.d.ts +4 -4
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.js +1 -1
- package/dist/lib/utils/geometry-utils.d.ts +38 -1
- package/dist/lib/utils/geometry-utils.d.ts.map +1 -1
- package/dist/lib/utils/geometry-utils.js +65 -6
- package/dist/lib/vector-tile/vector-tile-feature.d.ts +28 -9
- package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/vector-tile/vector-tile-feature.js +47 -50
- package/dist/lib/{geojsonvt/clip.d.ts → vector-tiler/features/clip-features.d.ts} +4 -4
- package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/clip.js → vector-tiler/features/clip-features.js} +4 -4
- package/dist/lib/vector-tiler/features/convert-feature.d.ts +18 -0
- 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/{geojsonvt/simplify.d.ts → vector-tiler/features/simplify-path.d.ts} +2 -2
- package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/simplify.js → vector-tiler/features/simplify-path.js} +3 -3
- package/dist/lib/{geojsonvt/wrap.d.ts → vector-tiler/features/wrap-features.d.ts} +5 -5
- package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/wrap.js → vector-tiler/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 +1 -1
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-source.d.ts +35 -18
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +30 -10
- package/dist/mvt-worker.js +101 -56
- package/dist/table-tile-source.d.ts +148 -0
- package/dist/table-tile-source.d.ts.map +1 -0
- package/dist/table-tile-source.js +420 -0
- package/dist/tilejson-loader.js +1 -1
- package/package.json +7 -6
- package/src/index.ts +14 -7
- package/src/lib/parse-mvt.ts +4 -33
- package/src/lib/parse-tilejson.ts +6 -6
- package/src/lib/utils/geometry-utils.ts +66 -1
- package/src/lib/vector-tile/vector-tile-feature.ts +65 -56
- package/src/lib/{geojsonvt/clip.ts → vector-tiler/features/clip-features.ts} +8 -8
- package/src/lib/vector-tiler/features/convert-feature.ts +191 -0
- package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
- package/src/lib/{geojsonvt/simplify.ts → vector-tiler/features/simplify-path.ts} +8 -3
- package/src/lib/{geojsonvt/wrap.ts → vector-tiler/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-source.ts +47 -24
- package/src/table-tile-source.ts +553 -0
- package/src/tilejson-loader.ts +2 -2
- package/dist/geojson-tile-source.d.ts +0 -79
- package/dist/geojson-tile-source.d.ts.map +0 -1
- package/dist/geojson-tile-source.js +0 -319
- package/dist/lib/geojsonvt/clip.d.ts.map +0 -1
- package/dist/lib/geojsonvt/convert.d.ts +0 -10
- package/dist/lib/geojsonvt/convert.d.ts.map +0 -1
- package/dist/lib/geojsonvt/convert.js +0 -132
- package/dist/lib/geojsonvt/feature.d.ts +0 -3
- package/dist/lib/geojsonvt/feature.d.ts.map +0 -1
- package/dist/lib/geojsonvt/feature.js +0 -44
- package/dist/lib/geojsonvt/simplify.d.ts.map +0 -1
- package/dist/lib/geojsonvt/tile.d.ts +0 -38
- package/dist/lib/geojsonvt/tile.d.ts.map +0 -1
- package/dist/lib/geojsonvt/tile.js +0 -123
- package/dist/lib/geojsonvt/transform.d.ts +0 -7
- package/dist/lib/geojsonvt/transform.d.ts.map +0 -1
- package/dist/lib/geojsonvt/transform.js +0 -41
- package/dist/lib/geojsonvt/wrap.d.ts.map +0 -1
- package/src/geojson-tile-source.ts +0 -422
- package/src/lib/geojsonvt/convert.ts +0 -160
- package/src/lib/geojsonvt/feature.ts +0 -47
- package/src/lib/geojsonvt/tile.ts +0 -187
- package/src/lib/geojsonvt/transform.ts +0 -57
- /package/src/lib/{geojsonvt → vector-tiler}/LICENSE +0 -0
|
@@ -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-source.ts
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {Source} from '@loaders.gl/loader-utils';
|
|
6
|
+
import type {ImageType, DataSourceProps} from '@loaders.gl/loader-utils';
|
|
6
7
|
import type {ImageTileSource, VectorTileSource} from '@loaders.gl/loader-utils';
|
|
8
|
+
import type {GetTileParameters, GetTileDataParameters} from '@loaders.gl/loader-utils';
|
|
7
9
|
import {DataSource, resolvePath} from '@loaders.gl/loader-utils';
|
|
8
10
|
import {ImageLoader, ImageLoaderOptions, getBinaryImageMetadata} from '@loaders.gl/images';
|
|
9
11
|
import {
|
|
@@ -14,20 +16,42 @@ import {
|
|
|
14
16
|
TileJSONLoaderOptions
|
|
15
17
|
} from '@loaders.gl/mvt';
|
|
16
18
|
|
|
17
|
-
|
|
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>;
|
|
18
41
|
|
|
19
42
|
/** Properties for a Mapbox Vector Tile Source */
|
|
20
|
-
export type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
};
|
|
31
55
|
};
|
|
32
56
|
|
|
33
57
|
/**
|
|
@@ -37,8 +61,8 @@ export type MVTSourceProps = DataSourceProps & {
|
|
|
37
61
|
* A PMTiles data source
|
|
38
62
|
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
39
63
|
*/
|
|
40
|
-
export class
|
|
41
|
-
readonly props:
|
|
64
|
+
export class MVTTileSource extends DataSource implements ImageTileSource, VectorTileSource {
|
|
65
|
+
readonly props: MVTTileSourceProps;
|
|
42
66
|
readonly url: string;
|
|
43
67
|
readonly metadataUrl: string | null = null;
|
|
44
68
|
data: string;
|
|
@@ -47,13 +71,12 @@ export class MVTSource extends DataSource implements ImageTileSource, VectorTile
|
|
|
47
71
|
extension: string;
|
|
48
72
|
mimeType: string | null = null;
|
|
49
73
|
|
|
50
|
-
constructor(props:
|
|
74
|
+
constructor(url: string, props: MVTTileSourceProps) {
|
|
51
75
|
super(props);
|
|
52
76
|
this.props = props;
|
|
53
|
-
this.url = resolvePath(
|
|
54
|
-
this.metadataUrl =
|
|
55
|
-
|
|
56
|
-
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';
|
|
57
80
|
this.data = this.url;
|
|
58
81
|
|
|
59
82
|
this.getTileData = this.getTileData.bind(this);
|
|
@@ -101,8 +124,8 @@ export class MVTSource extends DataSource implements ImageTileSource, VectorTile
|
|
|
101
124
|
return this.mimeType;
|
|
102
125
|
}
|
|
103
126
|
|
|
104
|
-
async getTile(
|
|
105
|
-
const {x, y, z} =
|
|
127
|
+
async getTile(parameters: GetTileParameters): Promise<ArrayBuffer | null> {
|
|
128
|
+
const {x, y, z} = parameters;
|
|
106
129
|
const tileUrl = this.getTileURL(x, y, z);
|
|
107
130
|
const response = await this.fetch(tileUrl);
|
|
108
131
|
if (!response.ok) {
|
|
@@ -115,8 +138,8 @@ export class MVTSource extends DataSource implements ImageTileSource, VectorTile
|
|
|
115
138
|
// Tile Source interface implementation: deck.gl compatible API
|
|
116
139
|
// TODO - currently only handles image tiles, not vector tiles
|
|
117
140
|
|
|
118
|
-
async getTileData(
|
|
119
|
-
const {x, y, z} =
|
|
141
|
+
async getTileData(parameters: GetTileDataParameters): Promise<any> {
|
|
142
|
+
const {x, y, z} = parameters.index;
|
|
120
143
|
// const metadata = await this.metadata;
|
|
121
144
|
// mimeType = metadata?.tileMIMEType || 'application/vnd.mapbox-vector-tile';
|
|
122
145
|
|