@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
|
@@ -1,319 +0,0 @@
|
|
|
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 { convert } from "./lib/geojsonvt/convert.js"; // GeoJSON conversion and preprocessing
|
|
6
|
-
import { clip } from "./lib/geojsonvt/clip.js"; // stripe clipping algorithm
|
|
7
|
-
import { wrap } from "./lib/geojsonvt/wrap.js"; // date line processing
|
|
8
|
-
import { transformTile } from "./lib/geojsonvt/transform.js"; // coordinate transformation
|
|
9
|
-
import { createTile } from "./lib/geojsonvt/tile.js"; // final simplified tile generation
|
|
10
|
-
export class GeoJSONTileSource {
|
|
11
|
-
static defaultOptions = {
|
|
12
|
-
maxZoom: 14, // max zoom to preserve detail on
|
|
13
|
-
indexMaxZoom: 5, // max zoom in the tile index
|
|
14
|
-
indexMaxPoints: 100000, // max number of points per tile in the tile index
|
|
15
|
-
tolerance: 3, // simplification tolerance (higher means simpler)
|
|
16
|
-
extent: 4096, // tile extent
|
|
17
|
-
buffer: 64, // tile buffer on each side
|
|
18
|
-
lineMetrics: false, // whether to calculate line metrics
|
|
19
|
-
// @ts-expect-error
|
|
20
|
-
promoteId: undefined, // name of a feature property to be promoted to feature.id
|
|
21
|
-
generateId: false, // whether to generate feature ids. Cannot be used with promoteId
|
|
22
|
-
debug: 0 // logging level (0, 1 or 2)
|
|
23
|
-
};
|
|
24
|
-
mimeType = 'application/vnd.mapbox-vector-tile';
|
|
25
|
-
options;
|
|
26
|
-
// tiles and tileCoords are part of the public API
|
|
27
|
-
tiles = {};
|
|
28
|
-
tileCoords = [];
|
|
29
|
-
stats = {};
|
|
30
|
-
total = 0;
|
|
31
|
-
/** Sync methods can be called: the input data promise has been resolved and initial top-level tiling is done */
|
|
32
|
-
ready;
|
|
33
|
-
constructor(data, options) {
|
|
34
|
-
this.options = { ...GeoJSONTileSource.defaultOptions, ...options };
|
|
35
|
-
this.getTileData = this.getTileData.bind(this);
|
|
36
|
-
this.ready = this.initializeTilesAsync(data);
|
|
37
|
-
}
|
|
38
|
-
async initializeTilesAsync(dataPromise) {
|
|
39
|
-
const data = await dataPromise;
|
|
40
|
-
this.initializeTilesSync(data);
|
|
41
|
-
}
|
|
42
|
-
initializeTilesSync(data) {
|
|
43
|
-
const options = this.options;
|
|
44
|
-
const debug = options.debug;
|
|
45
|
-
if (debug)
|
|
46
|
-
console.time('preprocess data');
|
|
47
|
-
if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
|
|
48
|
-
throw new Error('maxZoom should be in the 0-24 range');
|
|
49
|
-
}
|
|
50
|
-
if (options.promoteId && this.options.generateId) {
|
|
51
|
-
throw new Error('promoteId and generateId cannot be used together.');
|
|
52
|
-
}
|
|
53
|
-
// projects and adds simplification info
|
|
54
|
-
let features = convert(data, options);
|
|
55
|
-
if (debug) {
|
|
56
|
-
console.timeEnd('preprocess data');
|
|
57
|
-
console.log('index: maxZoom: %d, maxPoints: %d', options.indexMaxZoom, options.indexMaxPoints);
|
|
58
|
-
console.time('generate tiles');
|
|
59
|
-
}
|
|
60
|
-
// wraps features (ie extreme west and extreme east)
|
|
61
|
-
features = wrap(features, this.options);
|
|
62
|
-
// start slicing from the top tile down
|
|
63
|
-
if (features.length) {
|
|
64
|
-
this.splitTile(features, 0, 0, 0);
|
|
65
|
-
}
|
|
66
|
-
if (debug) {
|
|
67
|
-
if (features.length) {
|
|
68
|
-
console.log('features: %d, points: %d', this.tiles[0].numFeatures, this.tiles[0].numPoints);
|
|
69
|
-
}
|
|
70
|
-
console.timeEnd('generate tiles');
|
|
71
|
-
console.log('tiles generated:', this.total, JSON.stringify(this.stats));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async getMetadata() {
|
|
75
|
-
return {};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Get a tile at the specified index
|
|
79
|
-
* @param tileIndex z, x, y of tile
|
|
80
|
-
* @returns
|
|
81
|
-
*/
|
|
82
|
-
async getVectorTile(tileIndex) {
|
|
83
|
-
await this.ready;
|
|
84
|
-
const table = this.getTileSync(tileIndex);
|
|
85
|
-
return table;
|
|
86
|
-
}
|
|
87
|
-
async getTile(tileIndex) {
|
|
88
|
-
await this.ready;
|
|
89
|
-
return this.getTileSync(tileIndex);
|
|
90
|
-
}
|
|
91
|
-
async getTileData(tileParams) {
|
|
92
|
-
const { x, y, z } = tileParams.index;
|
|
93
|
-
return await this.getVectorTile({ x, y, z });
|
|
94
|
-
}
|
|
95
|
-
// Implementation
|
|
96
|
-
/**
|
|
97
|
-
* Synchronously request a tile
|
|
98
|
-
* @note Application must await `source.ready` before calling sync methods.
|
|
99
|
-
*/
|
|
100
|
-
getTileSync(tileIndex) {
|
|
101
|
-
const rawTile = this.getRawTile(tileIndex);
|
|
102
|
-
if (!rawTile) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
return convertToGeoJSONTable(rawTile, this.options.extent);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Return geojsonvt-style "half formed" vector tile
|
|
109
|
-
* @note Application must await `source.ready` before calling sync methods.
|
|
110
|
-
*/
|
|
111
|
-
// eslint-disable-next-line complexity, max-statements
|
|
112
|
-
getRawTile(tileIndex) {
|
|
113
|
-
const { z, y } = tileIndex;
|
|
114
|
-
let { x } = tileIndex;
|
|
115
|
-
// z = +z;
|
|
116
|
-
// x = +x;
|
|
117
|
-
// y = +y;
|
|
118
|
-
const { extent, debug } = this.options;
|
|
119
|
-
if (z < 0 || z > 24) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
const z2 = 1 << z;
|
|
123
|
-
x = (x + z2) & (z2 - 1); // wrap tile x coordinate
|
|
124
|
-
const id = toID(z, x, y);
|
|
125
|
-
if (this.tiles[id]) {
|
|
126
|
-
return transformTile(this.tiles[id], extent);
|
|
127
|
-
}
|
|
128
|
-
if (debug > 1)
|
|
129
|
-
console.log('drilling down to z%d-%d-%d', z, x, y);
|
|
130
|
-
let z0 = z;
|
|
131
|
-
let x0 = x;
|
|
132
|
-
let y0 = y;
|
|
133
|
-
let parent;
|
|
134
|
-
while (!parent && z0 > 0) {
|
|
135
|
-
z0--;
|
|
136
|
-
x0 = x0 >> 1;
|
|
137
|
-
y0 = y0 >> 1;
|
|
138
|
-
parent = this.tiles[toID(z0, x0, y0)];
|
|
139
|
-
}
|
|
140
|
-
if (!parent || !parent.source) {
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
// if we found a parent tile containing the original geometry, we can drill down from it
|
|
144
|
-
if (debug > 1) {
|
|
145
|
-
console.log('found parent tile z%d-%d-%d', z0, x0, y0);
|
|
146
|
-
console.time('drilling down');
|
|
147
|
-
}
|
|
148
|
-
this.splitTile(parent.source, z0, x0, y0, z, x, y);
|
|
149
|
-
if (debug > 1) {
|
|
150
|
-
console.timeEnd('drilling down');
|
|
151
|
-
}
|
|
152
|
-
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* splits features from a parent tile to sub-tiles.
|
|
156
|
-
* @param z, x, and y are the coordinates of the parent tile
|
|
157
|
-
* @param cz, cx, and cy are the coordinates of the target tile
|
|
158
|
-
*
|
|
159
|
-
* If no target tile is specified, splitting stops when we reach the maximum
|
|
160
|
-
* zoom or the number of points is low as specified in the options.
|
|
161
|
-
*/
|
|
162
|
-
// eslint-disable-next-line max-params, max-statements, complexity
|
|
163
|
-
splitTile(features, z, x, y, cz, cx, cy) {
|
|
164
|
-
const stack = [features, z, x, y];
|
|
165
|
-
const options = this.options;
|
|
166
|
-
const debug = options.debug;
|
|
167
|
-
// avoid recursion by using a processing queue
|
|
168
|
-
while (stack.length) {
|
|
169
|
-
y = stack.pop();
|
|
170
|
-
x = stack.pop();
|
|
171
|
-
z = stack.pop();
|
|
172
|
-
features = stack.pop();
|
|
173
|
-
const z2 = 1 << z;
|
|
174
|
-
const id = toID(z, x, y);
|
|
175
|
-
let tile = this.tiles[id];
|
|
176
|
-
if (!tile) {
|
|
177
|
-
if (debug > 1) {
|
|
178
|
-
console.time('creation');
|
|
179
|
-
}
|
|
180
|
-
tile = this.tiles[id] = createTile(features, z, x, y, options);
|
|
181
|
-
this.tileCoords.push({ z, x, y });
|
|
182
|
-
if (debug) {
|
|
183
|
-
if (debug > 1) {
|
|
184
|
-
console.log('tile z%d-%d-%d (features: %d, points: %d, simplified: %d)', z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified);
|
|
185
|
-
console.timeEnd('creation');
|
|
186
|
-
}
|
|
187
|
-
const key = `z${z}`;
|
|
188
|
-
this.stats[key] = (this.stats[key] || 0) + 1;
|
|
189
|
-
this.total++;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// save reference to original geometry in tile so that we can drill down later if we stop now
|
|
193
|
-
tile.source = features;
|
|
194
|
-
// if it's the first-pass tiling
|
|
195
|
-
if (cz === undefined) {
|
|
196
|
-
// stop tiling if we reached max zoom, or if the tile is too simple
|
|
197
|
-
if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
|
|
198
|
-
continue;
|
|
199
|
-
// if a drilldown to a specific tile
|
|
200
|
-
}
|
|
201
|
-
else if (z === options.maxZoom || z === cz) {
|
|
202
|
-
// stop tiling if we reached base zoom or our target tile zoom
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
else if (cz !== undefined) {
|
|
206
|
-
// stop tiling if it's not an ancestor of the target tile
|
|
207
|
-
const zoomSteps = cz - z;
|
|
208
|
-
// @ts-expect-error TODO fix the types of cx cy
|
|
209
|
-
if (x !== cx >> zoomSteps || y !== cy >> zoomSteps)
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
// if we slice further down, no need to keep source geometry
|
|
213
|
-
tile.source = null;
|
|
214
|
-
if (features.length === 0)
|
|
215
|
-
continue;
|
|
216
|
-
if (debug > 1)
|
|
217
|
-
console.time('clipping');
|
|
218
|
-
// values we'll use for clipping
|
|
219
|
-
const k1 = (0.5 * options.buffer) / options.extent;
|
|
220
|
-
const k2 = 0.5 - k1;
|
|
221
|
-
const k3 = 0.5 + k1;
|
|
222
|
-
const k4 = 1 + k1;
|
|
223
|
-
let tl = null;
|
|
224
|
-
let bl = null;
|
|
225
|
-
let tr = null;
|
|
226
|
-
let br = null;
|
|
227
|
-
let left = clip(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, options);
|
|
228
|
-
let right = clip(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, options);
|
|
229
|
-
// @ts-expect-error - unclear why this is needed?
|
|
230
|
-
features = null;
|
|
231
|
-
if (left) {
|
|
232
|
-
tl = clip(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
|
|
233
|
-
bl = clip(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
|
|
234
|
-
left = null;
|
|
235
|
-
}
|
|
236
|
-
if (right) {
|
|
237
|
-
tr = clip(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
|
|
238
|
-
br = clip(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
|
|
239
|
-
right = null;
|
|
240
|
-
}
|
|
241
|
-
if (debug > 1)
|
|
242
|
-
console.timeEnd('clipping');
|
|
243
|
-
stack.push(tl || [], z + 1, x * 2, y * 2);
|
|
244
|
-
stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
|
|
245
|
-
stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
|
|
246
|
-
stack.push(br || [], z + 1, x * 2 + 1, y * 2 + 1);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
function toID(z, x, y) {
|
|
251
|
-
return ((1 << z) * y + x) * 32 + z;
|
|
252
|
-
}
|
|
253
|
-
function convertToGeoJSONTable(vtTile, extent) {
|
|
254
|
-
const features = [];
|
|
255
|
-
for (const rawFeature of vtTile.features) {
|
|
256
|
-
if (!rawFeature || !rawFeature.geometry) {
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
let type;
|
|
260
|
-
let coordinates;
|
|
261
|
-
// raw geometry
|
|
262
|
-
switch (rawFeature.type) {
|
|
263
|
-
case 1:
|
|
264
|
-
if (rawFeature.geometry.length === 1) {
|
|
265
|
-
type = 'Point';
|
|
266
|
-
coordinates = rawFeature.geometry[0];
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
type = 'MultiPoint';
|
|
270
|
-
coordinates = rawFeature.geometry;
|
|
271
|
-
}
|
|
272
|
-
break;
|
|
273
|
-
case 2:
|
|
274
|
-
if (rawFeature.geometry.length === 1) {
|
|
275
|
-
type = 'LineString';
|
|
276
|
-
coordinates = rawFeature.geometry[0];
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
type = 'MultiLineString';
|
|
280
|
-
coordinates = rawFeature.geometry;
|
|
281
|
-
}
|
|
282
|
-
break;
|
|
283
|
-
case 3:
|
|
284
|
-
if (rawFeature.geometry.length > 1) {
|
|
285
|
-
type = 'MultiPolygon';
|
|
286
|
-
coordinates = [rawFeature.geometry];
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
type = 'Polygon';
|
|
290
|
-
coordinates = rawFeature.geometry;
|
|
291
|
-
}
|
|
292
|
-
break;
|
|
293
|
-
default:
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
coordinates = toLngLat(coordinates, extent);
|
|
297
|
-
const feature = {
|
|
298
|
-
type: 'Feature',
|
|
299
|
-
geometry: {
|
|
300
|
-
type,
|
|
301
|
-
coordinates
|
|
302
|
-
},
|
|
303
|
-
properties: rawFeature.tags || {}
|
|
304
|
-
};
|
|
305
|
-
features.push(feature);
|
|
306
|
-
}
|
|
307
|
-
const table = {
|
|
308
|
-
shape: 'geojson-table',
|
|
309
|
-
type: 'FeatureCollection',
|
|
310
|
-
features
|
|
311
|
-
};
|
|
312
|
-
return table;
|
|
313
|
-
}
|
|
314
|
-
function toLngLat(coords, extent) {
|
|
315
|
-
if (Array.isArray(coords[0])) {
|
|
316
|
-
return coords.map((c) => toLngLat(c, extent));
|
|
317
|
-
}
|
|
318
|
-
return [coords[0] / extent, coords[1] / extent];
|
|
319
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/clip.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAK/C;;;;;;;;;;GAUG;AAEH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,kBAAkB,EAAE,EAC9B,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,KAAA,EACJ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAC,WAAW,EAAE,OAAO,CAAA;CAAC,GAC9B,kBAAkB,EAAE,GAAG,IAAI,CA4E7B"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Feature, FeatureCollection } from '@loaders.gl/schema';
|
|
2
|
-
import type { GeoJSONTileFeature } from "./tile.js";
|
|
3
|
-
export declare function convert(data: Feature | FeatureCollection, options: any): GeoJSONTileFeature[];
|
|
4
|
-
export type ConvertFeatureOptions = {
|
|
5
|
-
maxZoom?: number;
|
|
6
|
-
tolerance: number;
|
|
7
|
-
extent: number;
|
|
8
|
-
lineMetrics: boolean;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/convert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAO/C,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,iBAAiB,EAAE,OAAO,KAAA,GAAG,kBAAkB,EAAE,CAcxF;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC"}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
import { simplify } from "./simplify.js";
|
|
6
|
-
import { createFeature } from "./feature.js";
|
|
7
|
-
// converts GeoJSON feature into an intermediate projected JSON vector format with simplification data
|
|
8
|
-
export function convert(data, options) {
|
|
9
|
-
const features = [];
|
|
10
|
-
if (data.type === 'FeatureCollection') {
|
|
11
|
-
for (let i = 0; i < data.features.length; i++) {
|
|
12
|
-
convertFeature(features, data.features[i], options, i);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
else if (data.type === 'Feature') {
|
|
16
|
-
convertFeature(features, data, options);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
// single geometry or a geometry collection
|
|
20
|
-
convertFeature(features, { geometry: data }, options);
|
|
21
|
-
}
|
|
22
|
-
return features;
|
|
23
|
-
}
|
|
24
|
-
function convertFeature(features, geojson, options, index) {
|
|
25
|
-
if (!geojson.geometry) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const coords = geojson.geometry.coordinates;
|
|
29
|
-
const type = geojson.geometry.type;
|
|
30
|
-
const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
|
|
31
|
-
let geometry = [];
|
|
32
|
-
let id = geojson.id;
|
|
33
|
-
if (options.promoteId) {
|
|
34
|
-
id = geojson.properties[options.promoteId];
|
|
35
|
-
}
|
|
36
|
-
else if (options.generateId) {
|
|
37
|
-
id = index || 0;
|
|
38
|
-
}
|
|
39
|
-
if (type === 'Point') {
|
|
40
|
-
convertPoint(coords, geometry);
|
|
41
|
-
}
|
|
42
|
-
else if (type === 'MultiPoint') {
|
|
43
|
-
for (const p of coords) {
|
|
44
|
-
convertPoint(p, geometry);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else if (type === 'LineString') {
|
|
48
|
-
convertLine(coords, geometry, tolerance, false);
|
|
49
|
-
}
|
|
50
|
-
else if (type === 'MultiLineString') {
|
|
51
|
-
if (options.lineMetrics) {
|
|
52
|
-
// explode into linestrings to be able to track metrics
|
|
53
|
-
for (const line of coords) {
|
|
54
|
-
geometry = [];
|
|
55
|
-
convertLine(line, geometry, tolerance, false);
|
|
56
|
-
features.push(createFeature(id, 'LineString', geometry, geojson.properties));
|
|
57
|
-
}
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
convertLines(coords, geometry, tolerance, false);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (type === 'Polygon') {
|
|
65
|
-
convertLines(coords, geometry, tolerance, true);
|
|
66
|
-
}
|
|
67
|
-
else if (type === 'MultiPolygon') {
|
|
68
|
-
for (const polygon of coords) {
|
|
69
|
-
const newPolygon = [];
|
|
70
|
-
convertLines(polygon, newPolygon, tolerance, true);
|
|
71
|
-
geometry.push(newPolygon);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else if (type === 'GeometryCollection') {
|
|
75
|
-
for (const singleGeometry of geojson.geometry.geometries) {
|
|
76
|
-
convertFeature(features, {
|
|
77
|
-
id,
|
|
78
|
-
geometry: singleGeometry,
|
|
79
|
-
properties: geojson.properties
|
|
80
|
-
}, options, index);
|
|
81
|
-
}
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
throw new Error('Input data is not a valid GeoJSON object.');
|
|
86
|
-
}
|
|
87
|
-
features.push(createFeature(id, type, geometry, geojson.properties));
|
|
88
|
-
}
|
|
89
|
-
function convertPoint(coords, out) {
|
|
90
|
-
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
91
|
-
}
|
|
92
|
-
function convertLine(ring, out, tolerance, isPolygon) {
|
|
93
|
-
let x0, y0;
|
|
94
|
-
let size = 0;
|
|
95
|
-
for (let j = 0; j < ring.length; j++) {
|
|
96
|
-
const x = projectX(ring[j][0]);
|
|
97
|
-
const y = projectY(ring[j][1]);
|
|
98
|
-
out.push(x, y, 0);
|
|
99
|
-
if (j > 0) {
|
|
100
|
-
if (isPolygon) {
|
|
101
|
-
size += (x0 * y - x * y0) / 2; // area
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
x0 = x;
|
|
108
|
-
y0 = y;
|
|
109
|
-
}
|
|
110
|
-
const last = out.length - 3;
|
|
111
|
-
out[2] = 1;
|
|
112
|
-
simplify(out, 0, last, tolerance);
|
|
113
|
-
out[last + 2] = 1;
|
|
114
|
-
out.size = Math.abs(size);
|
|
115
|
-
out.start = 0;
|
|
116
|
-
out.end = out.size;
|
|
117
|
-
}
|
|
118
|
-
function convertLines(rings, out, tolerance, isPolygon) {
|
|
119
|
-
for (let i = 0; i < rings.length; i++) {
|
|
120
|
-
const geom = [];
|
|
121
|
-
convertLine(rings[i], geom, tolerance, isPolygon);
|
|
122
|
-
out.push(geom);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function projectX(x) {
|
|
126
|
-
return x / 360 + 0.5;
|
|
127
|
-
}
|
|
128
|
-
function projectY(y) {
|
|
129
|
-
const sin = Math.sin((y * Math.PI) / 180);
|
|
130
|
-
const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
|
|
131
|
-
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
|
|
132
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/feature.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,kBAAkB,EAAC,kBAAe;AAE1C,wBAAgB,aAAa,CAAC,EAAE,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,GAAG,kBAAkB,CA8BtE"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
export function createFeature(id, type, geom, tags) {
|
|
6
|
-
const feature = {
|
|
7
|
-
// eslint-disable-next-line
|
|
8
|
-
id: id == null ? null : id,
|
|
9
|
-
type,
|
|
10
|
-
geometry: geom,
|
|
11
|
-
tags,
|
|
12
|
-
minX: Infinity,
|
|
13
|
-
minY: Infinity,
|
|
14
|
-
maxX: -Infinity,
|
|
15
|
-
maxY: -Infinity
|
|
16
|
-
};
|
|
17
|
-
if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
|
|
18
|
-
calcLineBBox(feature, geom);
|
|
19
|
-
}
|
|
20
|
-
else if (type === 'Polygon') {
|
|
21
|
-
// the outer ring (ie [0]) contains all inner rings
|
|
22
|
-
calcLineBBox(feature, geom[0]);
|
|
23
|
-
}
|
|
24
|
-
else if (type === 'MultiLineString') {
|
|
25
|
-
for (const line of geom) {
|
|
26
|
-
calcLineBBox(feature, line);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else if (type === 'MultiPolygon') {
|
|
30
|
-
for (const polygon of geom) {
|
|
31
|
-
// the outer ring (ie [0]) contains all inner rings
|
|
32
|
-
calcLineBBox(feature, polygon[0]);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return feature;
|
|
36
|
-
}
|
|
37
|
-
function calcLineBBox(feature, geom) {
|
|
38
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
39
|
-
feature.minX = Math.min(feature.minX, geom[i]);
|
|
40
|
-
feature.minY = Math.min(feature.minY, geom[i + 1]);
|
|
41
|
-
feature.maxX = Math.max(feature.maxX, geom[i]);
|
|
42
|
-
feature.maxY = Math.max(feature.maxY, geom[i + 1]);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simplify.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/simplify.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAkCjG"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type GeoJSONTileFeature = {
|
|
2
|
-
type: any;
|
|
3
|
-
geometry: any;
|
|
4
|
-
id?: string;
|
|
5
|
-
tags?: string[];
|
|
6
|
-
minX: number;
|
|
7
|
-
maxX: number;
|
|
8
|
-
minY: number;
|
|
9
|
-
maxY: number;
|
|
10
|
-
};
|
|
11
|
-
export type GeoJSONTile = {
|
|
12
|
-
features: GeoJSONTileFeature[];
|
|
13
|
-
type?: number;
|
|
14
|
-
tags?: Record<string, string>;
|
|
15
|
-
x: number;
|
|
16
|
-
y: number;
|
|
17
|
-
z: number;
|
|
18
|
-
minX: number;
|
|
19
|
-
maxX: number;
|
|
20
|
-
minY: number;
|
|
21
|
-
maxY: number;
|
|
22
|
-
transformed: boolean;
|
|
23
|
-
numPoints: number;
|
|
24
|
-
numSimplified: number;
|
|
25
|
-
numFeatures: number;
|
|
26
|
-
source: any | null;
|
|
27
|
-
};
|
|
28
|
-
export type CreateTileOptions = {
|
|
29
|
-
maxZoom?: number;
|
|
30
|
-
tolerance: number;
|
|
31
|
-
extent: number;
|
|
32
|
-
lineMetrics: boolean;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Create a tile from features and tile index
|
|
36
|
-
*/
|
|
37
|
-
export declare function createTile(features: any[], z: any, tx: any, ty: any, options: CreateTileOptions): GeoJSONTile;
|
|
38
|
-
//# sourceMappingURL=tile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/tile.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,EAAE,GAAG,CAAC;IAGd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAGhB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAG9B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IAGV,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAEb,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,KAAA,EAAE,EAAE,KAAA,EAAE,EAAE,KAAA,EAAE,OAAO,EAAE,iBAAiB,GAAG,WAAW,CAqB9F"}
|