@loaders.gl/mvt 3.2.12 → 3.3.0-alpha.10
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.min.js +782 -10
- package/dist/es5/bundle.js +0 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/helpers/binary-util-functions.js +2 -12
- package/dist/es5/helpers/binary-util-functions.js.map +1 -1
- package/dist/es5/helpers/mapbox-util-functions.js +2 -10
- package/dist/es5/helpers/mapbox-util-functions.js.map +1 -1
- package/dist/es5/index.js +7 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +14 -35
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +3 -14
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +3 -10
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -1
- package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
- package/dist/es5/lib/geojson-tiler/clip.js +247 -0
- package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/convert.js +163 -0
- package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/feature.js +63 -0
- package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js +203 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/simplify.js +54 -0
- package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/tile.js +127 -0
- package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/transform.js +52 -0
- package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/wrap.js +127 -0
- package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +8 -35
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +4 -14
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +3 -10
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -1
- package/dist/es5/lib/parse-mvt.js +3 -37
- package/dist/es5/lib/parse-mvt.js.map +1 -1
- package/dist/es5/lib/types.js.map +1 -1
- package/dist/es5/mvt-loader.js +9 -18
- package/dist/es5/mvt-loader.js.map +1 -1
- package/dist/es5/workers/mvt-worker.js +0 -2
- package/dist/es5/workers/mvt-worker.js.map +1 -1
- package/dist/esm/bundle.js +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/helpers/binary-util-functions.js +5 -10
- package/dist/esm/helpers/binary-util-functions.js.map +1 -1
- package/dist/esm/helpers/mapbox-util-functions.js +5 -8
- package/dist/esm/helpers/mapbox-util-functions.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +6 -25
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +2 -14
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile.js +1 -3
- package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -1
- package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
- package/dist/esm/lib/geojson-tiler/clip.js +184 -0
- package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/convert.js +120 -0
- package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/feature.js +37 -0
- package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js +189 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/simplify.js +49 -0
- package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/tile.js +108 -0
- package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/transform.js +35 -0
- package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/wrap.js +75 -0
- package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +2 -36
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +2 -14
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +1 -3
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -1
- package/dist/esm/lib/parse-mvt.js +0 -26
- package/dist/esm/lib/parse-mvt.js.map +1 -1
- package/dist/esm/lib/types.js.map +1 -1
- package/dist/esm/mvt-loader.js +9 -3
- package/dist/esm/mvt-loader.js.map +1 -1
- package/dist/esm/workers/mvt-worker.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/lib/geojson-tiler/clip.d.ts +16 -0
- package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/clip.js +209 -0
- package/dist/lib/geojson-tiler/convert.d.ts +10 -0
- package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/convert.js +134 -0
- package/dist/lib/geojson-tiler/feature.d.ts +3 -0
- package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/feature.js +46 -0
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
- package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
- package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/simplify.js +68 -0
- package/dist/lib/geojson-tiler/tile.d.ts +38 -0
- package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/tile.js +125 -0
- package/dist/lib/geojson-tiler/transform.d.ts +7 -0
- package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/transform.js +43 -0
- package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
- package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/wrap.js +86 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +3 -3
- package/dist/lib/types.d.ts +6 -6
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/mvt-worker.js +10 -11
- package/package.json +5 -5
- package/src/index.ts +7 -0
- package/src/lib/geojson-tiler/LICENSE +19 -0
- package/src/lib/geojson-tiler/clip.ts +248 -0
- package/src/lib/geojson-tiler/convert.ts +158 -0
- package/src/lib/geojson-tiler/feature.ts +45 -0
- package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
- package/src/lib/geojson-tiler/simplify.ts +77 -0
- package/src/lib/geojson-tiler/tile.ts +185 -0
- package/src/lib/geojson-tiler/transform.ts +55 -0
- package/src/lib/geojson-tiler/wrap.ts +108 -0
package/dist/dist.min.js
CHANGED
|
@@ -29,6 +29,12 @@
|
|
|
29
29
|
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
|
|
33
|
+
var init_defineProperty = __esm({
|
|
34
|
+
"../../node_modules/@babel/runtime/helpers/esm/defineProperty.js"() {
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
32
38
|
// ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
|
|
33
39
|
function getPolygonSignedArea(points, options = {}) {
|
|
34
40
|
const {
|
|
@@ -51,16 +57,16 @@
|
|
|
51
57
|
// ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
|
|
52
58
|
var init_polygon = __esm({
|
|
53
59
|
"../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
|
|
60
|
+
init_defineProperty();
|
|
54
61
|
init_polygon_utils();
|
|
55
62
|
}
|
|
56
63
|
});
|
|
57
64
|
|
|
58
65
|
// ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
|
|
59
|
-
function earcut(
|
|
60
|
-
dim = dim || 2;
|
|
66
|
+
function earcut(positions, holeIndices, dim = 2, areas) {
|
|
61
67
|
const hasHoles = holeIndices && holeIndices.length;
|
|
62
|
-
const outerLen = hasHoles ? holeIndices[0] * dim :
|
|
63
|
-
let outerNode = linkedList(
|
|
68
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
|
|
69
|
+
let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0]);
|
|
64
70
|
const triangles = [];
|
|
65
71
|
if (!outerNode || outerNode.next === outerNode.prev)
|
|
66
72
|
return triangles;
|
|
@@ -72,13 +78,13 @@
|
|
|
72
78
|
let x2;
|
|
73
79
|
let y2;
|
|
74
80
|
if (hasHoles)
|
|
75
|
-
outerNode = eliminateHoles(
|
|
76
|
-
if (
|
|
77
|
-
minX = maxX =
|
|
78
|
-
minY = maxY =
|
|
81
|
+
outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
|
|
82
|
+
if (positions.length > 80 * dim) {
|
|
83
|
+
minX = maxX = positions[0];
|
|
84
|
+
minY = maxY = positions[1];
|
|
79
85
|
for (let i2 = dim; i2 < outerLen; i2 += dim) {
|
|
80
|
-
x2 =
|
|
81
|
-
y2 =
|
|
86
|
+
x2 = positions[i2];
|
|
87
|
+
y2 = positions[i2 + 1];
|
|
82
88
|
if (x2 < minX)
|
|
83
89
|
minX = x2;
|
|
84
90
|
if (y2 < minY)
|
|
@@ -2305,15 +2311,781 @@
|
|
|
2305
2311
|
}
|
|
2306
2312
|
});
|
|
2307
2313
|
|
|
2314
|
+
// src/lib/geojson-tiler/simplify.ts
|
|
2315
|
+
function simplify(coords, first, last, sqTolerance) {
|
|
2316
|
+
let maxSqDist = sqTolerance;
|
|
2317
|
+
const mid = last - first >> 1;
|
|
2318
|
+
let minPosToMid = last - first;
|
|
2319
|
+
let index;
|
|
2320
|
+
const ax = coords[first];
|
|
2321
|
+
const ay = coords[first + 1];
|
|
2322
|
+
const bx = coords[last];
|
|
2323
|
+
const by = coords[last + 1];
|
|
2324
|
+
for (let i2 = first + 3; i2 < last; i2 += 3) {
|
|
2325
|
+
const d = getSqSegDist(coords[i2], coords[i2 + 1], ax, ay, bx, by);
|
|
2326
|
+
if (d > maxSqDist) {
|
|
2327
|
+
index = i2;
|
|
2328
|
+
maxSqDist = d;
|
|
2329
|
+
} else if (d === maxSqDist) {
|
|
2330
|
+
const posToMid = Math.abs(i2 - mid);
|
|
2331
|
+
if (posToMid < minPosToMid) {
|
|
2332
|
+
index = i2;
|
|
2333
|
+
minPosToMid = posToMid;
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
if (maxSqDist > sqTolerance) {
|
|
2338
|
+
if (index - first > 3)
|
|
2339
|
+
simplify(coords, first, index, sqTolerance);
|
|
2340
|
+
coords[index + 2] = maxSqDist;
|
|
2341
|
+
if (last - index > 3)
|
|
2342
|
+
simplify(coords, index, last, sqTolerance);
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
function getSqSegDist(px, py, x2, y2, bx, by) {
|
|
2346
|
+
let dx = bx - x2;
|
|
2347
|
+
let dy = by - y2;
|
|
2348
|
+
if (dx !== 0 || dy !== 0) {
|
|
2349
|
+
const t = ((px - x2) * dx + (py - y2) * dy) / (dx * dx + dy * dy);
|
|
2350
|
+
if (t > 1) {
|
|
2351
|
+
x2 = bx;
|
|
2352
|
+
y2 = by;
|
|
2353
|
+
} else if (t > 0) {
|
|
2354
|
+
x2 += dx * t;
|
|
2355
|
+
y2 += dy * t;
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
dx = px - x2;
|
|
2359
|
+
dy = py - y2;
|
|
2360
|
+
return dx * dx + dy * dy;
|
|
2361
|
+
}
|
|
2362
|
+
var init_simplify = __esm({
|
|
2363
|
+
"src/lib/geojson-tiler/simplify.ts"() {
|
|
2364
|
+
}
|
|
2365
|
+
});
|
|
2366
|
+
|
|
2367
|
+
// src/lib/geojson-tiler/feature.ts
|
|
2368
|
+
function createFeature(id, type, geom, tags) {
|
|
2369
|
+
const feature = {
|
|
2370
|
+
id: id == null ? null : id,
|
|
2371
|
+
type,
|
|
2372
|
+
geometry: geom,
|
|
2373
|
+
tags,
|
|
2374
|
+
minX: Infinity,
|
|
2375
|
+
minY: Infinity,
|
|
2376
|
+
maxX: -Infinity,
|
|
2377
|
+
maxY: -Infinity
|
|
2378
|
+
};
|
|
2379
|
+
if (type === "Point" || type === "MultiPoint" || type === "LineString") {
|
|
2380
|
+
calcLineBBox(feature, geom);
|
|
2381
|
+
} else if (type === "Polygon") {
|
|
2382
|
+
calcLineBBox(feature, geom[0]);
|
|
2383
|
+
} else if (type === "MultiLineString") {
|
|
2384
|
+
for (const line of geom) {
|
|
2385
|
+
calcLineBBox(feature, line);
|
|
2386
|
+
}
|
|
2387
|
+
} else if (type === "MultiPolygon") {
|
|
2388
|
+
for (const polygon of geom) {
|
|
2389
|
+
calcLineBBox(feature, polygon[0]);
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
return feature;
|
|
2393
|
+
}
|
|
2394
|
+
function calcLineBBox(feature, geom) {
|
|
2395
|
+
for (let i2 = 0; i2 < geom.length; i2 += 3) {
|
|
2396
|
+
feature.minX = Math.min(feature.minX, geom[i2]);
|
|
2397
|
+
feature.minY = Math.min(feature.minY, geom[i2 + 1]);
|
|
2398
|
+
feature.maxX = Math.max(feature.maxX, geom[i2]);
|
|
2399
|
+
feature.maxY = Math.max(feature.maxY, geom[i2 + 1]);
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
var init_feature = __esm({
|
|
2403
|
+
"src/lib/geojson-tiler/feature.ts"() {
|
|
2404
|
+
}
|
|
2405
|
+
});
|
|
2406
|
+
|
|
2407
|
+
// src/lib/geojson-tiler/convert.ts
|
|
2408
|
+
function convert(data, options) {
|
|
2409
|
+
const features = [];
|
|
2410
|
+
if (data.type === "FeatureCollection") {
|
|
2411
|
+
for (let i2 = 0; i2 < data.features.length; i2++) {
|
|
2412
|
+
convertFeature(features, data.features[i2], options, i2);
|
|
2413
|
+
}
|
|
2414
|
+
} else if (data.type === "Feature") {
|
|
2415
|
+
convertFeature(features, data, options);
|
|
2416
|
+
} else {
|
|
2417
|
+
convertFeature(features, { geometry: data }, options);
|
|
2418
|
+
}
|
|
2419
|
+
return features;
|
|
2420
|
+
}
|
|
2421
|
+
function convertFeature(features, geojson, options, index) {
|
|
2422
|
+
if (!geojson.geometry) {
|
|
2423
|
+
return;
|
|
2424
|
+
}
|
|
2425
|
+
const coords = geojson.geometry.coordinates;
|
|
2426
|
+
const type = geojson.geometry.type;
|
|
2427
|
+
const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
|
|
2428
|
+
let geometry = [];
|
|
2429
|
+
let id = geojson.id;
|
|
2430
|
+
if (options.promoteId) {
|
|
2431
|
+
id = geojson.properties[options.promoteId];
|
|
2432
|
+
} else if (options.generateId) {
|
|
2433
|
+
id = index || 0;
|
|
2434
|
+
}
|
|
2435
|
+
if (type === "Point") {
|
|
2436
|
+
convertPoint(coords, geometry);
|
|
2437
|
+
} else if (type === "MultiPoint") {
|
|
2438
|
+
for (const p of coords) {
|
|
2439
|
+
convertPoint(p, geometry);
|
|
2440
|
+
}
|
|
2441
|
+
} else if (type === "LineString") {
|
|
2442
|
+
convertLine(coords, geometry, tolerance, false);
|
|
2443
|
+
} else if (type === "MultiLineString") {
|
|
2444
|
+
if (options.lineMetrics) {
|
|
2445
|
+
for (const line of coords) {
|
|
2446
|
+
geometry = [];
|
|
2447
|
+
convertLine(line, geometry, tolerance, false);
|
|
2448
|
+
features.push(createFeature(id, "LineString", geometry, geojson.properties));
|
|
2449
|
+
}
|
|
2450
|
+
return;
|
|
2451
|
+
} else {
|
|
2452
|
+
convertLines(coords, geometry, tolerance, false);
|
|
2453
|
+
}
|
|
2454
|
+
} else if (type === "Polygon") {
|
|
2455
|
+
convertLines(coords, geometry, tolerance, true);
|
|
2456
|
+
} else if (type === "MultiPolygon") {
|
|
2457
|
+
for (const polygon of coords) {
|
|
2458
|
+
const newPolygon = [];
|
|
2459
|
+
convertLines(polygon, newPolygon, tolerance, true);
|
|
2460
|
+
geometry.push(newPolygon);
|
|
2461
|
+
}
|
|
2462
|
+
} else if (type === "GeometryCollection") {
|
|
2463
|
+
for (const singleGeometry of geojson.geometry.geometries) {
|
|
2464
|
+
convertFeature(features, {
|
|
2465
|
+
id,
|
|
2466
|
+
geometry: singleGeometry,
|
|
2467
|
+
properties: geojson.properties
|
|
2468
|
+
}, options, index);
|
|
2469
|
+
}
|
|
2470
|
+
return;
|
|
2471
|
+
} else {
|
|
2472
|
+
throw new Error("Input data is not a valid GeoJSON object.");
|
|
2473
|
+
}
|
|
2474
|
+
features.push(createFeature(id, type, geometry, geojson.properties));
|
|
2475
|
+
}
|
|
2476
|
+
function convertPoint(coords, out) {
|
|
2477
|
+
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
2478
|
+
}
|
|
2479
|
+
function convertLine(ring, out, tolerance, isPolygon) {
|
|
2480
|
+
let x0, y0;
|
|
2481
|
+
let size = 0;
|
|
2482
|
+
for (let j = 0; j < ring.length; j++) {
|
|
2483
|
+
const x2 = projectX(ring[j][0]);
|
|
2484
|
+
const y2 = projectY(ring[j][1]);
|
|
2485
|
+
out.push(x2, y2, 0);
|
|
2486
|
+
if (j > 0) {
|
|
2487
|
+
if (isPolygon) {
|
|
2488
|
+
size += (x0 * y2 - x2 * y0) / 2;
|
|
2489
|
+
} else {
|
|
2490
|
+
size += Math.sqrt(Math.pow(x2 - x0, 2) + Math.pow(y2 - y0, 2));
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
x0 = x2;
|
|
2494
|
+
y0 = y2;
|
|
2495
|
+
}
|
|
2496
|
+
const last = out.length - 3;
|
|
2497
|
+
out[2] = 1;
|
|
2498
|
+
simplify(out, 0, last, tolerance);
|
|
2499
|
+
out[last + 2] = 1;
|
|
2500
|
+
out.size = Math.abs(size);
|
|
2501
|
+
out.start = 0;
|
|
2502
|
+
out.end = out.size;
|
|
2503
|
+
}
|
|
2504
|
+
function convertLines(rings, out, tolerance, isPolygon) {
|
|
2505
|
+
for (let i2 = 0; i2 < rings.length; i2++) {
|
|
2506
|
+
const geom = [];
|
|
2507
|
+
convertLine(rings[i2], geom, tolerance, isPolygon);
|
|
2508
|
+
out.push(geom);
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
function projectX(x2) {
|
|
2512
|
+
return x2 / 360 + 0.5;
|
|
2513
|
+
}
|
|
2514
|
+
function projectY(y2) {
|
|
2515
|
+
const sin = Math.sin(y2 * Math.PI / 180);
|
|
2516
|
+
const y22 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
|
|
2517
|
+
return y22 < 0 ? 0 : y22 > 1 ? 1 : y22;
|
|
2518
|
+
}
|
|
2519
|
+
var init_convert = __esm({
|
|
2520
|
+
"src/lib/geojson-tiler/convert.ts"() {
|
|
2521
|
+
init_simplify();
|
|
2522
|
+
init_feature();
|
|
2523
|
+
}
|
|
2524
|
+
});
|
|
2525
|
+
|
|
2526
|
+
// src/lib/geojson-tiler/clip.ts
|
|
2527
|
+
function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
2528
|
+
k1 /= scale;
|
|
2529
|
+
k2 /= scale;
|
|
2530
|
+
if (minAll >= k1 && maxAll < k2) {
|
|
2531
|
+
return features;
|
|
2532
|
+
} else if (maxAll < k1 || minAll >= k2) {
|
|
2533
|
+
return null;
|
|
2534
|
+
}
|
|
2535
|
+
const clipped = [];
|
|
2536
|
+
for (const feature of features) {
|
|
2537
|
+
const geometry = feature.geometry;
|
|
2538
|
+
let type = feature.type;
|
|
2539
|
+
const min = axis === 0 ? feature.minX : feature.minY;
|
|
2540
|
+
const max = axis === 0 ? feature.maxX : feature.maxY;
|
|
2541
|
+
if (min >= k1 && max < k2) {
|
|
2542
|
+
clipped.push(feature);
|
|
2543
|
+
continue;
|
|
2544
|
+
} else if (max < k1 || min >= k2) {
|
|
2545
|
+
continue;
|
|
2546
|
+
}
|
|
2547
|
+
let newGeometry = [];
|
|
2548
|
+
if (type === "Point" || type === "MultiPoint") {
|
|
2549
|
+
clipPoints(geometry, newGeometry, k1, k2, axis);
|
|
2550
|
+
} else if (type === "LineString") {
|
|
2551
|
+
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
|
|
2552
|
+
} else if (type === "MultiLineString") {
|
|
2553
|
+
clipLines(geometry, newGeometry, k1, k2, axis, false);
|
|
2554
|
+
} else if (type === "Polygon") {
|
|
2555
|
+
clipLines(geometry, newGeometry, k1, k2, axis, true);
|
|
2556
|
+
} else if (type === "MultiPolygon") {
|
|
2557
|
+
for (const polygon of geometry) {
|
|
2558
|
+
const newPolygon = [];
|
|
2559
|
+
clipLines(polygon, newPolygon, k1, k2, axis, true);
|
|
2560
|
+
if (newPolygon.length) {
|
|
2561
|
+
newGeometry.push(newPolygon);
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
if (newGeometry.length) {
|
|
2566
|
+
if (options.lineMetrics && type === "LineString") {
|
|
2567
|
+
for (const line of newGeometry) {
|
|
2568
|
+
clipped.push(createFeature(feature.id, type, line, feature.tags));
|
|
2569
|
+
}
|
|
2570
|
+
continue;
|
|
2571
|
+
}
|
|
2572
|
+
if (type === "LineString" || type === "MultiLineString") {
|
|
2573
|
+
if (newGeometry.length === 1) {
|
|
2574
|
+
type = "LineString";
|
|
2575
|
+
newGeometry = newGeometry[0];
|
|
2576
|
+
} else {
|
|
2577
|
+
type = "MultiLineString";
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
if (type === "Point" || type === "MultiPoint") {
|
|
2581
|
+
type = newGeometry.length === 3 ? "Point" : "MultiPoint";
|
|
2582
|
+
}
|
|
2583
|
+
clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
return clipped.length ? clipped : null;
|
|
2587
|
+
}
|
|
2588
|
+
function clipPoints(geom, newGeom, k1, k2, axis) {
|
|
2589
|
+
for (let i2 = 0; i2 < geom.length; i2 += 3) {
|
|
2590
|
+
const a = geom[i2 + axis];
|
|
2591
|
+
if (a >= k1 && a <= k2) {
|
|
2592
|
+
addPoint(newGeom, geom[i2], geom[i2 + 1], geom[i2 + 2]);
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
|
|
2597
|
+
let slice = newSlice(geom);
|
|
2598
|
+
const intersect2 = axis === 0 ? intersectX : intersectY;
|
|
2599
|
+
let len = geom.start;
|
|
2600
|
+
let segLen;
|
|
2601
|
+
let t;
|
|
2602
|
+
for (let i2 = 0; i2 < geom.length - 3; i2 += 3) {
|
|
2603
|
+
const ax2 = geom[i2];
|
|
2604
|
+
const ay2 = geom[i2 + 1];
|
|
2605
|
+
const az2 = geom[i2 + 2];
|
|
2606
|
+
const bx = geom[i2 + 3];
|
|
2607
|
+
const by = geom[i2 + 4];
|
|
2608
|
+
const a2 = axis === 0 ? ax2 : ay2;
|
|
2609
|
+
const b = axis === 0 ? bx : by;
|
|
2610
|
+
let exited = false;
|
|
2611
|
+
if (trackMetrics) {
|
|
2612
|
+
segLen = Math.sqrt(Math.pow(ax2 - bx, 2) + Math.pow(ay2 - by, 2));
|
|
2613
|
+
}
|
|
2614
|
+
if (a2 < k1) {
|
|
2615
|
+
if (b > k1) {
|
|
2616
|
+
t = intersect2(slice, ax2, ay2, bx, by, k1);
|
|
2617
|
+
if (trackMetrics) {
|
|
2618
|
+
slice.start = len + segLen * t;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
} else if (a2 > k2) {
|
|
2622
|
+
if (b < k2) {
|
|
2623
|
+
t = intersect2(slice, ax2, ay2, bx, by, k2);
|
|
2624
|
+
if (trackMetrics) {
|
|
2625
|
+
slice.start = len + segLen * t;
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
} else {
|
|
2629
|
+
addPoint(slice, ax2, ay2, az2);
|
|
2630
|
+
}
|
|
2631
|
+
if (b < k1 && a2 >= k1) {
|
|
2632
|
+
t = intersect2(slice, ax2, ay2, bx, by, k1);
|
|
2633
|
+
exited = true;
|
|
2634
|
+
}
|
|
2635
|
+
if (b > k2 && a2 <= k2) {
|
|
2636
|
+
t = intersect2(slice, ax2, ay2, bx, by, k2);
|
|
2637
|
+
exited = true;
|
|
2638
|
+
}
|
|
2639
|
+
if (!isPolygon && exited) {
|
|
2640
|
+
if (trackMetrics) {
|
|
2641
|
+
slice.end = len + segLen * t;
|
|
2642
|
+
}
|
|
2643
|
+
newGeom.push(slice);
|
|
2644
|
+
slice = newSlice(geom);
|
|
2645
|
+
}
|
|
2646
|
+
if (trackMetrics) {
|
|
2647
|
+
len += segLen;
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
let last = geom.length - 3;
|
|
2651
|
+
const ax = geom[last];
|
|
2652
|
+
const ay = geom[last + 1];
|
|
2653
|
+
const az = geom[last + 2];
|
|
2654
|
+
const a = axis === 0 ? ax : ay;
|
|
2655
|
+
if (a >= k1 && a <= k2)
|
|
2656
|
+
addPoint(slice, ax, ay, az);
|
|
2657
|
+
last = slice.length - 3;
|
|
2658
|
+
if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
|
|
2659
|
+
addPoint(slice, slice[0], slice[1], slice[2]);
|
|
2660
|
+
}
|
|
2661
|
+
if (slice.length) {
|
|
2662
|
+
newGeom.push(slice);
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
function newSlice(line) {
|
|
2666
|
+
const slice = [];
|
|
2667
|
+
slice.size = line.size;
|
|
2668
|
+
slice.start = line.start;
|
|
2669
|
+
slice.end = line.end;
|
|
2670
|
+
return slice;
|
|
2671
|
+
}
|
|
2672
|
+
function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
|
|
2673
|
+
for (const line of geom) {
|
|
2674
|
+
clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
function addPoint(out, x2, y2, z) {
|
|
2678
|
+
out.push(x2, y2, z);
|
|
2679
|
+
}
|
|
2680
|
+
function intersectX(out, ax, ay, bx, by, x2) {
|
|
2681
|
+
const t = (x2 - ax) / (bx - ax);
|
|
2682
|
+
addPoint(out, x2, ay + (by - ay) * t, 1);
|
|
2683
|
+
return t;
|
|
2684
|
+
}
|
|
2685
|
+
function intersectY(out, ax, ay, bx, by, y2) {
|
|
2686
|
+
const t = (y2 - ay) / (by - ay);
|
|
2687
|
+
addPoint(out, ax + (bx - ax) * t, y2, 1);
|
|
2688
|
+
return t;
|
|
2689
|
+
}
|
|
2690
|
+
var init_clip = __esm({
|
|
2691
|
+
"src/lib/geojson-tiler/clip.ts"() {
|
|
2692
|
+
init_feature();
|
|
2693
|
+
}
|
|
2694
|
+
});
|
|
2695
|
+
|
|
2696
|
+
// src/lib/geojson-tiler/wrap.ts
|
|
2697
|
+
function wrap(features, options) {
|
|
2698
|
+
const buffer = options.buffer / options.extent;
|
|
2699
|
+
let merged = features;
|
|
2700
|
+
const left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options);
|
|
2701
|
+
const right = clip(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
|
|
2702
|
+
if (left || right) {
|
|
2703
|
+
merged = clip(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
|
|
2704
|
+
if (left) {
|
|
2705
|
+
merged = shiftFeatureCoords(left, 1).concat(merged);
|
|
2706
|
+
}
|
|
2707
|
+
if (right) {
|
|
2708
|
+
merged = merged.concat(shiftFeatureCoords(right, -1));
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
return merged;
|
|
2712
|
+
}
|
|
2713
|
+
function shiftFeatureCoords(features, offset) {
|
|
2714
|
+
const newFeatures = [];
|
|
2715
|
+
for (let i2 = 0; i2 < features.length; i2++) {
|
|
2716
|
+
const feature = features[i2];
|
|
2717
|
+
const type = feature.type;
|
|
2718
|
+
let newGeometry;
|
|
2719
|
+
if (type === "Point" || type === "MultiPoint" || type === "LineString") {
|
|
2720
|
+
newGeometry = shiftCoords(feature.geometry, offset);
|
|
2721
|
+
} else if (type === "MultiLineString" || type === "Polygon") {
|
|
2722
|
+
newGeometry = [];
|
|
2723
|
+
for (const line of feature.geometry) {
|
|
2724
|
+
newGeometry.push(shiftCoords(line, offset));
|
|
2725
|
+
}
|
|
2726
|
+
} else if (type === "MultiPolygon") {
|
|
2727
|
+
newGeometry = [];
|
|
2728
|
+
for (const polygon of feature.geometry) {
|
|
2729
|
+
const newPolygon = [];
|
|
2730
|
+
for (const line of polygon) {
|
|
2731
|
+
newPolygon.push(shiftCoords(line, offset));
|
|
2732
|
+
}
|
|
2733
|
+
newGeometry.push(newPolygon);
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags));
|
|
2737
|
+
}
|
|
2738
|
+
return newFeatures;
|
|
2739
|
+
}
|
|
2740
|
+
function shiftCoords(points, offset) {
|
|
2741
|
+
const newPoints = [];
|
|
2742
|
+
newPoints.size = points.size;
|
|
2743
|
+
if (points.start !== void 0) {
|
|
2744
|
+
newPoints.start = points.start;
|
|
2745
|
+
newPoints.end = points.end;
|
|
2746
|
+
}
|
|
2747
|
+
for (let i2 = 0; i2 < points.length; i2 += 3) {
|
|
2748
|
+
newPoints.push(points[i2] + offset, points[i2 + 1], points[i2 + 2]);
|
|
2749
|
+
}
|
|
2750
|
+
return newPoints;
|
|
2751
|
+
}
|
|
2752
|
+
var init_wrap = __esm({
|
|
2753
|
+
"src/lib/geojson-tiler/wrap.ts"() {
|
|
2754
|
+
init_clip();
|
|
2755
|
+
init_feature();
|
|
2756
|
+
}
|
|
2757
|
+
});
|
|
2758
|
+
|
|
2759
|
+
// src/lib/geojson-tiler/transform.ts
|
|
2760
|
+
function transformTile(tile, extent) {
|
|
2761
|
+
if (tile.transformed) {
|
|
2762
|
+
return tile;
|
|
2763
|
+
}
|
|
2764
|
+
const z2 = 1 << tile.z;
|
|
2765
|
+
const tx = tile.x;
|
|
2766
|
+
const ty = tile.y;
|
|
2767
|
+
for (const feature of tile.features) {
|
|
2768
|
+
const geom = feature.geometry;
|
|
2769
|
+
const type = feature.type;
|
|
2770
|
+
feature.geometry = [];
|
|
2771
|
+
if (type === 1) {
|
|
2772
|
+
for (let j = 0; j < geom.length; j += 2) {
|
|
2773
|
+
feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
|
|
2774
|
+
}
|
|
2775
|
+
} else {
|
|
2776
|
+
for (let j = 0; j < geom.length; j++) {
|
|
2777
|
+
const ring = [];
|
|
2778
|
+
for (let k = 0; k < geom[j].length; k += 2) {
|
|
2779
|
+
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
|
|
2780
|
+
}
|
|
2781
|
+
feature.geometry.push(ring);
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
tile.transformed = true;
|
|
2786
|
+
return tile;
|
|
2787
|
+
}
|
|
2788
|
+
function transformPoint(x2, y2, extent, z2, tx, ty) {
|
|
2789
|
+
return [Math.round(extent * (x2 * z2 - tx)), Math.round(extent * (y2 * z2 - ty))];
|
|
2790
|
+
}
|
|
2791
|
+
var init_transform = __esm({
|
|
2792
|
+
"src/lib/geojson-tiler/transform.ts"() {
|
|
2793
|
+
}
|
|
2794
|
+
});
|
|
2795
|
+
|
|
2796
|
+
// src/lib/geojson-tiler/tile.ts
|
|
2797
|
+
function createTile(features, z, tx, ty, options) {
|
|
2798
|
+
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
2799
|
+
const tile = {
|
|
2800
|
+
features: [],
|
|
2801
|
+
numPoints: 0,
|
|
2802
|
+
numSimplified: 0,
|
|
2803
|
+
numFeatures: features.length,
|
|
2804
|
+
source: null,
|
|
2805
|
+
x: tx,
|
|
2806
|
+
y: ty,
|
|
2807
|
+
z,
|
|
2808
|
+
transformed: false,
|
|
2809
|
+
minX: 2,
|
|
2810
|
+
minY: 1,
|
|
2811
|
+
maxX: -1,
|
|
2812
|
+
maxY: 0
|
|
2813
|
+
};
|
|
2814
|
+
for (const feature of features) {
|
|
2815
|
+
addFeature(tile, feature, tolerance, options);
|
|
2816
|
+
}
|
|
2817
|
+
return tile;
|
|
2818
|
+
}
|
|
2819
|
+
function addFeature(tile, feature, tolerance, options) {
|
|
2820
|
+
const geom = feature.geometry;
|
|
2821
|
+
const type = feature.type;
|
|
2822
|
+
const simplified = [];
|
|
2823
|
+
tile.minX = Math.min(tile.minX, feature.minX);
|
|
2824
|
+
tile.minY = Math.min(tile.minY, feature.minY);
|
|
2825
|
+
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
2826
|
+
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
2827
|
+
if (type === "Point" || type === "MultiPoint") {
|
|
2828
|
+
for (let i2 = 0; i2 < geom.length; i2 += 3) {
|
|
2829
|
+
simplified.push(geom[i2], geom[i2 + 1]);
|
|
2830
|
+
tile.numPoints++;
|
|
2831
|
+
tile.numSimplified++;
|
|
2832
|
+
}
|
|
2833
|
+
} else if (type === "LineString") {
|
|
2834
|
+
addLine(simplified, geom, tile, tolerance, false, false);
|
|
2835
|
+
} else if (type === "MultiLineString" || type === "Polygon") {
|
|
2836
|
+
for (let i2 = 0; i2 < geom.length; i2++) {
|
|
2837
|
+
addLine(simplified, geom[i2], tile, tolerance, type === "Polygon", i2 === 0);
|
|
2838
|
+
}
|
|
2839
|
+
} else if (type === "MultiPolygon") {
|
|
2840
|
+
for (let k = 0; k < geom.length; k++) {
|
|
2841
|
+
const polygon = geom[k];
|
|
2842
|
+
for (let i2 = 0; i2 < polygon.length; i2++) {
|
|
2843
|
+
addLine(simplified, polygon[i2], tile, tolerance, true, i2 === 0);
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
if (simplified.length) {
|
|
2848
|
+
let tags = feature.tags || null;
|
|
2849
|
+
if (type === "LineString" && options.lineMetrics) {
|
|
2850
|
+
tags = {};
|
|
2851
|
+
for (const key in feature.tags)
|
|
2852
|
+
tags[key] = feature.tags[key];
|
|
2853
|
+
tags.mapbox_clip_start = geom.start / geom.size;
|
|
2854
|
+
tags.mapbox_clip_end = geom.end / geom.size;
|
|
2855
|
+
}
|
|
2856
|
+
const tileFeature = {
|
|
2857
|
+
geometry: simplified,
|
|
2858
|
+
type: type === "Polygon" || type === "MultiPolygon" ? 3 : type === "LineString" || type === "MultiLineString" ? 2 : 1,
|
|
2859
|
+
tags
|
|
2860
|
+
};
|
|
2861
|
+
if (feature.id !== null) {
|
|
2862
|
+
tileFeature.id = feature.id;
|
|
2863
|
+
}
|
|
2864
|
+
tile.features.push(tileFeature);
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
|
|
2868
|
+
const sqTolerance = tolerance * tolerance;
|
|
2869
|
+
if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
2870
|
+
tile.numPoints += geom.length / 3;
|
|
2871
|
+
return;
|
|
2872
|
+
}
|
|
2873
|
+
const ring = [];
|
|
2874
|
+
for (let i2 = 0; i2 < geom.length; i2 += 3) {
|
|
2875
|
+
if (tolerance === 0 || geom[i2 + 2] > sqTolerance) {
|
|
2876
|
+
tile.numSimplified++;
|
|
2877
|
+
ring.push(geom[i2], geom[i2 + 1]);
|
|
2878
|
+
}
|
|
2879
|
+
tile.numPoints++;
|
|
2880
|
+
}
|
|
2881
|
+
if (isPolygon)
|
|
2882
|
+
rewind(ring, isOuter);
|
|
2883
|
+
result.push(ring);
|
|
2884
|
+
}
|
|
2885
|
+
function rewind(ring, clockwise) {
|
|
2886
|
+
let area2 = 0;
|
|
2887
|
+
for (let i2 = 0, j = ring.length - 2; i2 < ring.length; j = i2, i2 += 2) {
|
|
2888
|
+
area2 += (ring[i2] - ring[j]) * (ring[i2 + 1] + ring[j + 1]);
|
|
2889
|
+
}
|
|
2890
|
+
if (area2 > 0 === clockwise) {
|
|
2891
|
+
for (let i2 = 0, len = ring.length; i2 < len / 2; i2 += 2) {
|
|
2892
|
+
const x2 = ring[i2];
|
|
2893
|
+
const y2 = ring[i2 + 1];
|
|
2894
|
+
ring[i2] = ring[len - 2 - i2];
|
|
2895
|
+
ring[i2 + 1] = ring[len - 1 - i2];
|
|
2896
|
+
ring[len - 2 - i2] = x2;
|
|
2897
|
+
ring[len - 1 - i2] = y2;
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
var init_tile = __esm({
|
|
2902
|
+
"src/lib/geojson-tiler/tile.ts"() {
|
|
2903
|
+
}
|
|
2904
|
+
});
|
|
2905
|
+
|
|
2906
|
+
// src/lib/geojson-tiler/geojson-tiler.ts
|
|
2907
|
+
function toID(z, x2, y2) {
|
|
2908
|
+
return ((1 << z) * y2 + x2) * 32 + z;
|
|
2909
|
+
}
|
|
2910
|
+
var DEFAULT_OPTIONS, GeoJSONTiler;
|
|
2911
|
+
var init_geojson_tiler = __esm({
|
|
2912
|
+
"src/lib/geojson-tiler/geojson-tiler.ts"() {
|
|
2913
|
+
init_convert();
|
|
2914
|
+
init_clip();
|
|
2915
|
+
init_wrap();
|
|
2916
|
+
init_transform();
|
|
2917
|
+
init_tile();
|
|
2918
|
+
DEFAULT_OPTIONS = {
|
|
2919
|
+
maxZoom: 14,
|
|
2920
|
+
indexMaxZoom: 5,
|
|
2921
|
+
indexMaxPoints: 1e5,
|
|
2922
|
+
tolerance: 3,
|
|
2923
|
+
extent: 4096,
|
|
2924
|
+
buffer: 64,
|
|
2925
|
+
lineMetrics: false,
|
|
2926
|
+
promoteId: void 0,
|
|
2927
|
+
generateId: false,
|
|
2928
|
+
debug: 0
|
|
2929
|
+
};
|
|
2930
|
+
GeoJSONTiler = class {
|
|
2931
|
+
constructor(data, options) {
|
|
2932
|
+
this.tiles = {};
|
|
2933
|
+
this.tileCoords = [];
|
|
2934
|
+
this.stats = {};
|
|
2935
|
+
this.total = 0;
|
|
2936
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
2937
|
+
options = this.options;
|
|
2938
|
+
const debug = options.debug;
|
|
2939
|
+
if (debug)
|
|
2940
|
+
console.time("preprocess data");
|
|
2941
|
+
if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
|
|
2942
|
+
throw new Error("maxZoom should be in the 0-24 range");
|
|
2943
|
+
}
|
|
2944
|
+
if (options.promoteId && this.options.generateId) {
|
|
2945
|
+
throw new Error("promoteId and generateId cannot be used together.");
|
|
2946
|
+
}
|
|
2947
|
+
let features = convert(data, options);
|
|
2948
|
+
if (debug) {
|
|
2949
|
+
console.timeEnd("preprocess data");
|
|
2950
|
+
console.log("index: maxZoom: %d, maxPoints: %d", options.indexMaxZoom, options.indexMaxPoints);
|
|
2951
|
+
console.time("generate tiles");
|
|
2952
|
+
}
|
|
2953
|
+
features = wrap(features, this.options);
|
|
2954
|
+
if (features.length) {
|
|
2955
|
+
this.splitTile(features, 0, 0, 0);
|
|
2956
|
+
}
|
|
2957
|
+
if (debug) {
|
|
2958
|
+
if (features.length) {
|
|
2959
|
+
console.log("features: %d, points: %d", this.tiles[0].numFeatures, this.tiles[0].numPoints);
|
|
2960
|
+
}
|
|
2961
|
+
console.timeEnd("generate tiles");
|
|
2962
|
+
console.log("tiles generated:", this.total, JSON.stringify(this.stats));
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
getTile(z, x2, y2) {
|
|
2966
|
+
const { extent, debug } = this.options;
|
|
2967
|
+
if (z < 0 || z > 24) {
|
|
2968
|
+
return null;
|
|
2969
|
+
}
|
|
2970
|
+
const z2 = 1 << z;
|
|
2971
|
+
x2 = x2 + z2 & z2 - 1;
|
|
2972
|
+
const id = toID(z, x2, y2);
|
|
2973
|
+
if (this.tiles[id]) {
|
|
2974
|
+
return transformTile(this.tiles[id], extent);
|
|
2975
|
+
}
|
|
2976
|
+
if (debug > 1)
|
|
2977
|
+
console.log("drilling down to z%d-%d-%d", z, x2, y2);
|
|
2978
|
+
let z0 = z;
|
|
2979
|
+
let x0 = x2;
|
|
2980
|
+
let y0 = y2;
|
|
2981
|
+
let parent;
|
|
2982
|
+
while (!parent && z0 > 0) {
|
|
2983
|
+
z0--;
|
|
2984
|
+
x0 = x0 >> 1;
|
|
2985
|
+
y0 = y0 >> 1;
|
|
2986
|
+
parent = this.tiles[toID(z0, x0, y0)];
|
|
2987
|
+
}
|
|
2988
|
+
if (!parent || !parent.source) {
|
|
2989
|
+
return null;
|
|
2990
|
+
}
|
|
2991
|
+
if (debug > 1) {
|
|
2992
|
+
console.log("found parent tile z%d-%d-%d", z0, x0, y0);
|
|
2993
|
+
console.time("drilling down");
|
|
2994
|
+
}
|
|
2995
|
+
this.splitTile(parent.source, z0, x0, y0, z, x2, y2);
|
|
2996
|
+
if (debug > 1) {
|
|
2997
|
+
console.timeEnd("drilling down");
|
|
2998
|
+
}
|
|
2999
|
+
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
|
|
3000
|
+
}
|
|
3001
|
+
splitTile(features, z, x2, y2, cz, cx, cy) {
|
|
3002
|
+
const stack = [features, z, x2, y2];
|
|
3003
|
+
const options = this.options;
|
|
3004
|
+
const debug = options.debug;
|
|
3005
|
+
while (stack.length) {
|
|
3006
|
+
y2 = stack.pop();
|
|
3007
|
+
x2 = stack.pop();
|
|
3008
|
+
z = stack.pop();
|
|
3009
|
+
features = stack.pop();
|
|
3010
|
+
const z2 = 1 << z;
|
|
3011
|
+
const id = toID(z, x2, y2);
|
|
3012
|
+
let tile = this.tiles[id];
|
|
3013
|
+
if (!tile) {
|
|
3014
|
+
if (debug > 1) {
|
|
3015
|
+
console.time("creation");
|
|
3016
|
+
}
|
|
3017
|
+
tile = this.tiles[id] = createTile(features, z, x2, y2, options);
|
|
3018
|
+
this.tileCoords.push({ z, x: x2, y: y2 });
|
|
3019
|
+
if (debug) {
|
|
3020
|
+
if (debug > 1) {
|
|
3021
|
+
console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x2, y2, tile.numFeatures, tile.numPoints, tile.numSimplified);
|
|
3022
|
+
console.timeEnd("creation");
|
|
3023
|
+
}
|
|
3024
|
+
const key = `z${z}`;
|
|
3025
|
+
this.stats[key] = (this.stats[key] || 0) + 1;
|
|
3026
|
+
this.total++;
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
tile.source = features;
|
|
3030
|
+
if (cz === void 0) {
|
|
3031
|
+
if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
|
|
3032
|
+
continue;
|
|
3033
|
+
} else if (z === options.maxZoom || z === cz) {
|
|
3034
|
+
continue;
|
|
3035
|
+
} else if (cz !== void 0) {
|
|
3036
|
+
const zoomSteps = cz - z;
|
|
3037
|
+
if (x2 !== cx >> zoomSteps || y2 !== cy >> zoomSteps)
|
|
3038
|
+
continue;
|
|
3039
|
+
}
|
|
3040
|
+
tile.source = null;
|
|
3041
|
+
if (features.length === 0)
|
|
3042
|
+
continue;
|
|
3043
|
+
if (debug > 1)
|
|
3044
|
+
console.time("clipping");
|
|
3045
|
+
const k1 = 0.5 * options.buffer / options.extent;
|
|
3046
|
+
const k2 = 0.5 - k1;
|
|
3047
|
+
const k3 = 0.5 + k1;
|
|
3048
|
+
const k4 = 1 + k1;
|
|
3049
|
+
let tl = null;
|
|
3050
|
+
let bl = null;
|
|
3051
|
+
let tr = null;
|
|
3052
|
+
let br = null;
|
|
3053
|
+
let left = clip(features, z2, x2 - k1, x2 + k3, 0, tile.minX, tile.maxX, options);
|
|
3054
|
+
let right = clip(features, z2, x2 + k2, x2 + k4, 0, tile.minX, tile.maxX, options);
|
|
3055
|
+
features = null;
|
|
3056
|
+
if (left) {
|
|
3057
|
+
tl = clip(left, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
|
|
3058
|
+
bl = clip(left, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
|
|
3059
|
+
left = null;
|
|
3060
|
+
}
|
|
3061
|
+
if (right) {
|
|
3062
|
+
tr = clip(right, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
|
|
3063
|
+
br = clip(right, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
|
|
3064
|
+
right = null;
|
|
3065
|
+
}
|
|
3066
|
+
if (debug > 1)
|
|
3067
|
+
console.timeEnd("clipping");
|
|
3068
|
+
stack.push(tl || [], z + 1, x2 * 2, y2 * 2);
|
|
3069
|
+
stack.push(bl || [], z + 1, x2 * 2, y2 * 2 + 1);
|
|
3070
|
+
stack.push(tr || [], z + 1, x2 * 2 + 1, y2 * 2);
|
|
3071
|
+
stack.push(br || [], z + 1, x2 * 2 + 1, y2 * 2 + 1);
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
};
|
|
3075
|
+
}
|
|
3076
|
+
});
|
|
3077
|
+
|
|
2308
3078
|
// src/index.ts
|
|
2309
3079
|
var src_exports = {};
|
|
2310
3080
|
__export(src_exports, {
|
|
3081
|
+
GeoJSONTiler: () => GeoJSONTiler,
|
|
2311
3082
|
MVTLoader: () => MVTLoader,
|
|
2312
3083
|
MVTWorkerLoader: () => MVTWorkerLoader
|
|
2313
3084
|
});
|
|
2314
3085
|
var init_src2 = __esm({
|
|
2315
3086
|
"src/index.ts"() {
|
|
2316
3087
|
init_mvt_loader();
|
|
3088
|
+
init_geojson_tiler();
|
|
2317
3089
|
}
|
|
2318
3090
|
});
|
|
2319
3091
|
|