@loaders.gl/mvt 4.3.0-alpha.2 → 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 +777 -688
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +746 -659
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/lib/parse-tilejson.js +1 -1
- package/dist/lib/utils/geometry-utils.js +1 -1
- package/dist/lib/vector-tiler/{clip.d.ts → features/clip-features.d.ts} +4 -4
- package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{clip.js → features/clip-features.js} +4 -4
- package/dist/lib/vector-tiler/{convert.d.ts → features/convert-feature.d.ts} +7 -7
- package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
- package/dist/lib/vector-tiler/{simplify.d.ts → features/simplify-path.d.ts} +2 -2
- package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{simplify.js → features/simplify-path.js} +3 -3
- package/dist/lib/vector-tiler/{wrap.d.ts → features/wrap-features.d.ts} +5 -5
- package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{wrap.js → features/wrap-features.js} +33 -26
- package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
- package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/proto-tile.js +138 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
- package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/transform-tile.js +41 -0
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-source.d.ts +31 -14
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +26 -6
- package/dist/mvt-worker.js +4 -4
- package/dist/table-tile-source.d.ts +66 -36
- package/dist/table-tile-source.d.ts.map +1 -1
- package/dist/table-tile-source.js +167 -117
- package/dist/tilejson-loader.js +1 -1
- package/package.json +6 -6
- package/src/index.ts +13 -6
- package/src/lib/parse-tilejson.ts +1 -1
- package/src/lib/utils/geometry-utils.ts +1 -1
- package/src/lib/vector-tiler/{clip.ts → features/clip-features.ts} +8 -8
- package/src/lib/vector-tiler/{convert.ts → features/convert-feature.ts} +91 -70
- package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
- package/src/lib/vector-tiler/{simplify.ts → features/simplify-path.ts} +8 -3
- package/src/lib/vector-tiler/{wrap.ts → features/wrap-features.ts} +44 -29
- package/src/lib/vector-tiler/proto-tile.ts +217 -0
- package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
- package/src/lib/vector-tiler/transform-tile.ts +57 -0
- package/src/mvt-source.ts +42 -18
- package/src/table-tile-source.ts +130 -85
- package/src/tilejson-loader.ts +2 -2
- package/dist/lib/vector-tiler/clip.d.ts.map +0 -1
- package/dist/lib/vector-tiler/convert.d.ts.map +0 -1
- package/dist/lib/vector-tiler/convert.js +0 -139
- package/dist/lib/vector-tiler/feature.d.ts +0 -3
- package/dist/lib/vector-tiler/feature.d.ts.map +0 -1
- package/dist/lib/vector-tiler/feature.js +0 -44
- package/dist/lib/vector-tiler/simplify.d.ts.map +0 -1
- package/dist/lib/vector-tiler/tile.d.ts +0 -38
- package/dist/lib/vector-tiler/tile.d.ts.map +0 -1
- package/dist/lib/vector-tiler/tile.js +0 -123
- package/dist/lib/vector-tiler/transform.d.ts +0 -7
- package/dist/lib/vector-tiler/transform.d.ts.map +0 -1
- package/dist/lib/vector-tiler/transform.js +0 -41
- package/dist/lib/vector-tiler/wrap.d.ts.map +0 -1
- package/src/lib/vector-tiler/feature.ts +0 -47
- package/src/lib/vector-tiler/tile.ts +0 -187
- package/src/lib/vector-tiler/transform.ts +0 -57
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export type { MVTLoaderOptions } from "./mvt-loader.js";
|
|
2
|
-
export { MVTLoader, MVTWorkerLoader } from "./mvt-loader.js";
|
|
3
|
-
export type { TileJSON } from "./lib/parse-tilejson.js";
|
|
4
|
-
export type { TileJSONLoaderOptions } from "./tilejson-loader.js";
|
|
5
1
|
export { TileJSONLoader } from "./tilejson-loader.js";
|
|
2
|
+
export type { TileJSONLoaderOptions } from "./tilejson-loader.js";
|
|
3
|
+
export type { TileJSON } from "./lib/parse-tilejson.js";
|
|
4
|
+
export { MVTLoader, MVTWorkerLoader } from "./mvt-loader.js";
|
|
5
|
+
export type { MVTLoaderOptions } from "./mvt-loader.js";
|
|
6
6
|
export { MVTSource } from "./mvt-source.js";
|
|
7
|
-
export type {
|
|
7
|
+
export type { MVTTileSource, MVTTileSourceProps } from "./mvt-source.js";
|
|
8
8
|
export { TableTileSource } from "./table-tile-source.js";
|
|
9
|
+
export type { DynamicVectorTileSource, DynamicVectorTileSourceProps } from "./table-tile-source.js";
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,cAAc,EAAC,6BAA0B;AACjD,YAAY,EAAC,qBAAqB,EAAC,6BAA0B;AAC7D,YAAY,EAAC,QAAQ,EAAC,gCAA6B;AAInD,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,wBAAqB;AACxD,YAAY,EAAC,gBAAgB,EAAC,wBAAqB;AAInD,OAAO,EAAC,SAAS,EAAC,wBAAqB;AACvC,YAAY,EAAC,aAAa,EAAE,kBAAkB,EAAC,wBAAqB;AAIpE,OAAO,EAAC,eAAe,EAAC,+BAA4B;AACpD,YAAY,EAAC,uBAAuB,EAAE,4BAA4B,EAAC,+BAA4B"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
4
|
+
// TileJSONLoader
|
|
5
5
|
export { TileJSONLoader } from "./tilejson-loader.js";
|
|
6
|
+
// MVTLoader
|
|
7
|
+
export { MVTLoader, MVTWorkerLoader } from "./mvt-loader.js";
|
|
8
|
+
// MVTSource
|
|
6
9
|
export { MVTSource } from "./mvt-source.js";
|
|
10
|
+
// TableTileSource (dynamically tiles a table)
|
|
7
11
|
export { TableTileSource } from "./table-tile-source.js";
|
|
@@ -260,7 +260,7 @@ function attributeTypeToFieldType(aType) {
|
|
|
260
260
|
const type = aType.toLowerCase();
|
|
261
261
|
if (!type || !attrTypeMap[type]) {
|
|
262
262
|
// console.warn(
|
|
263
|
-
// `cannot convert
|
|
263
|
+
// `cannot convert feature type ${type} to loaders.gl data type, use string by default`
|
|
264
264
|
// );
|
|
265
265
|
}
|
|
266
266
|
return attrTypeMap[type] || { type: 'string' };
|
|
@@ -43,7 +43,7 @@ export function convertToLocalCoordinates(coordinates, extent) {
|
|
|
43
43
|
* @param feature
|
|
44
44
|
*/
|
|
45
45
|
export function convertToLocalCoordinatesFlat(data, extent) {
|
|
46
|
-
for (let i = 0
|
|
46
|
+
for (let i = 0; i < data.length; ++i) {
|
|
47
47
|
data[i] /= extent;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProtoFeature } from "./proto-feature.js";
|
|
2
2
|
/**
|
|
3
3
|
* Clip features between two vertical or horizontal axis-parallel lines:
|
|
4
4
|
* | |
|
|
@@ -10,7 +10,7 @@ import type { TableTileFeature } from "./tile.js";
|
|
|
10
10
|
* @param axis: 0 for x, 1 for y
|
|
11
11
|
* @param minAll and maxAll: minimum and maximum coordinate value for all features
|
|
12
12
|
*/
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function clipFeatures(features: ProtoFeature[], scale: number, k1: number, k2: number, axis: any, minAll: number, maxAll: number, options: {
|
|
14
14
|
lineMetrics: boolean;
|
|
15
|
-
}):
|
|
16
|
-
//# sourceMappingURL=clip.d.ts.map
|
|
15
|
+
}): ProtoFeature[] | null;
|
|
16
|
+
//# sourceMappingURL=clip-features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clip-features.d.ts","sourceRoot":"","sources":["../../../../src/lib/vector-tiler/features/clip-features.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,YAAY,EAAC,2BAAwB;AAKlD;;;;;;;;;;GAUG;AAEH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,YAAY,EAAE,EACxB,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,YAAY,EAAE,GAAG,IAAI,CA4EvB"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
import {
|
|
5
|
+
import { createProtoFeature } from "./proto-feature.js";
|
|
6
6
|
/* eslint-disable no-continue */
|
|
7
7
|
/**
|
|
8
8
|
* Clip features between two vertical or horizontal axis-parallel lines:
|
|
@@ -16,7 +16,7 @@ import { createFeature } from "./feature.js";
|
|
|
16
16
|
* @param minAll and maxAll: minimum and maximum coordinate value for all features
|
|
17
17
|
*/
|
|
18
18
|
// eslint-disable-next-line max-params, complexity, max-statements
|
|
19
|
-
export function
|
|
19
|
+
export function clipFeatures(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
20
20
|
k1 /= scale;
|
|
21
21
|
k2 /= scale;
|
|
22
22
|
if (minAll >= k1 && maxAll < k2) {
|
|
@@ -66,7 +66,7 @@ export function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
|
66
66
|
if (newGeometry.length) {
|
|
67
67
|
if (options.lineMetrics && type === 'LineString') {
|
|
68
68
|
for (const line of newGeometry) {
|
|
69
|
-
clipped.push(
|
|
69
|
+
clipped.push(createProtoFeature(feature.id, type, line, feature.tags));
|
|
70
70
|
}
|
|
71
71
|
continue;
|
|
72
72
|
}
|
|
@@ -83,7 +83,7 @@ export function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
|
83
83
|
if (type === 'Point' || type === 'MultiPoint') {
|
|
84
84
|
type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
|
|
85
85
|
}
|
|
86
|
-
clipped.push(
|
|
86
|
+
clipped.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
return clipped.length ? clipped : null;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { Feature, FeatureCollection } from '@loaders.gl/schema';
|
|
2
|
-
import type {
|
|
3
|
-
/**
|
|
4
|
-
* converts a GeoJSON feature into an intermediate projected JSON vector format
|
|
5
|
-
* with simplification data
|
|
6
|
-
*/
|
|
7
|
-
export declare function convert(data: Feature | FeatureCollection, options: any): TableTileFeature[];
|
|
2
|
+
import type { ProtoFeature } from "./proto-feature.js";
|
|
8
3
|
export type ConvertFeatureOptions = {
|
|
9
4
|
/** max zoom to preserve detail on */
|
|
10
5
|
maxZoom?: number;
|
|
@@ -15,4 +10,9 @@ export type ConvertFeatureOptions = {
|
|
|
15
10
|
/** whether to calculate line metrics */
|
|
16
11
|
lineMetrics?: boolean;
|
|
17
12
|
};
|
|
18
|
-
|
|
13
|
+
/**
|
|
14
|
+
* converts a GeoJSON feature into an intermediate projected JSON vector format
|
|
15
|
+
* with simplification data
|
|
16
|
+
*/
|
|
17
|
+
export declare function convertFeaturesToProtoFeature(data: Feature | FeatureCollection, options: ConvertFeatureOptions): ProtoFeature[];
|
|
18
|
+
//# sourceMappingURL=convert-feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-feature.d.ts","sourceRoot":"","sources":["../../../../src/lib/vector-tiler/features/convert-feature.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAC,YAAY,EAAC,2BAAwB;AAKlD,MAAM,MAAM,qBAAqB,GAAG;IAClC,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GAAG,iBAAiB,EACjC,OAAO,EAAE,qBAAqB,GAC7B,YAAY,EAAE,CAkBhB"}
|
|
@@ -0,0 +1,140 @@
|
|
|
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 { createProtoFeature } from "./proto-feature.js";
|
|
6
|
+
import { simplifyPath } from "./simplify-path.js";
|
|
7
|
+
/**
|
|
8
|
+
* converts a GeoJSON feature into an intermediate projected JSON vector format
|
|
9
|
+
* with simplification data
|
|
10
|
+
*/
|
|
11
|
+
export function convertFeaturesToProtoFeature(data, options) {
|
|
12
|
+
const protoFeatures = [];
|
|
13
|
+
switch (data.type) {
|
|
14
|
+
case 'FeatureCollection':
|
|
15
|
+
let i = 0;
|
|
16
|
+
for (const feature of data.features) {
|
|
17
|
+
protoFeatures.push(convertFeature(feature, options, i++));
|
|
18
|
+
}
|
|
19
|
+
break;
|
|
20
|
+
case 'Feature':
|
|
21
|
+
protoFeatures.push(convertFeature(data, options));
|
|
22
|
+
break;
|
|
23
|
+
default:
|
|
24
|
+
// single geometry or a geometry collection
|
|
25
|
+
protoFeatures.push(convertFeature({ geometry: data }, options));
|
|
26
|
+
}
|
|
27
|
+
return protoFeatures;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* converts a GeoJSON feature into an intermediate projected JSON vector format
|
|
31
|
+
* with simplification data
|
|
32
|
+
*/
|
|
33
|
+
function convertFeature(geojson, options, index) {
|
|
34
|
+
// GeoJSON geometries can be null, but no vector tile will include them.
|
|
35
|
+
if (!geojson.geometry) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const coords = geojson.geometry.coordinates;
|
|
39
|
+
const type = geojson.geometry.type;
|
|
40
|
+
const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
|
|
41
|
+
let geometry = [];
|
|
42
|
+
let id = geojson.id;
|
|
43
|
+
if (options.promoteId) {
|
|
44
|
+
id = geojson.properties[options.promoteId];
|
|
45
|
+
}
|
|
46
|
+
else if (options.generateId) {
|
|
47
|
+
id = index || 0;
|
|
48
|
+
}
|
|
49
|
+
switch (type) {
|
|
50
|
+
case 'Point':
|
|
51
|
+
convertPoint(coords, geometry);
|
|
52
|
+
break;
|
|
53
|
+
case 'MultiPoint':
|
|
54
|
+
for (const p of coords) {
|
|
55
|
+
convertPoint(p, geometry);
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 'LineString':
|
|
59
|
+
convertLine(coords, geometry, tolerance, false);
|
|
60
|
+
break;
|
|
61
|
+
case 'MultiLineString':
|
|
62
|
+
if (options.lineMetrics) {
|
|
63
|
+
// explode into linestrings to be able to track metrics
|
|
64
|
+
for (const line of coords) {
|
|
65
|
+
geometry = [];
|
|
66
|
+
convertLine(line, geometry, tolerance, false);
|
|
67
|
+
features.push(createProtoFeature(id, 'LineString', geometry, geojson.properties));
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
convertLines(coords, geometry, tolerance, false);
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
case 'Polygon':
|
|
74
|
+
convertLines(coords, geometry, tolerance, true);
|
|
75
|
+
break;
|
|
76
|
+
case 'MultiPolygon':
|
|
77
|
+
for (const polygon of coords) {
|
|
78
|
+
const newPolygon = [];
|
|
79
|
+
convertLines(polygon, newPolygon, tolerance, true);
|
|
80
|
+
geometry.push(newPolygon);
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case 'GeometryCollection':
|
|
84
|
+
for (const singleGeometry of geojson.geometry.geometries) {
|
|
85
|
+
convertFeature(features, {
|
|
86
|
+
id,
|
|
87
|
+
geometry: singleGeometry,
|
|
88
|
+
properties: geojson.properties
|
|
89
|
+
}, options, index);
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
throw new Error('Input data is not a valid GeoJSON object.');
|
|
94
|
+
}
|
|
95
|
+
return createProtoFeature(id, type, geometry, geojson.properties);
|
|
96
|
+
}
|
|
97
|
+
function convertPoint(coords, out) {
|
|
98
|
+
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
99
|
+
}
|
|
100
|
+
function convertLine(ring, out, tolerance, isPolygon) {
|
|
101
|
+
let x0, y0;
|
|
102
|
+
let size = 0;
|
|
103
|
+
for (let j = 0; j < ring.length; j++) {
|
|
104
|
+
const x = projectX(ring[j][0]);
|
|
105
|
+
const y = projectY(ring[j][1]);
|
|
106
|
+
out.push(x, y, 0);
|
|
107
|
+
if (j > 0) {
|
|
108
|
+
if (isPolygon) {
|
|
109
|
+
size += (x0 * y - x * y0) / 2; // area
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
x0 = x;
|
|
116
|
+
y0 = y;
|
|
117
|
+
}
|
|
118
|
+
const last = out.length - 3;
|
|
119
|
+
out[2] = 1;
|
|
120
|
+
simplifyPath(out, 0, last, tolerance);
|
|
121
|
+
out[last + 2] = 1;
|
|
122
|
+
out.size = Math.abs(size);
|
|
123
|
+
out.start = 0;
|
|
124
|
+
out.end = out.size;
|
|
125
|
+
}
|
|
126
|
+
function convertLines(rings, out, tolerance, isPolygon) {
|
|
127
|
+
for (let i = 0; i < rings.length; i++) {
|
|
128
|
+
const geom = [];
|
|
129
|
+
convertLine(rings[i], geom, tolerance, isPolygon);
|
|
130
|
+
out.push(geom);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function projectX(x) {
|
|
134
|
+
return x / 360 + 0.5;
|
|
135
|
+
}
|
|
136
|
+
function projectY(y) {
|
|
137
|
+
const sin = Math.sin((y * Math.PI) / 180);
|
|
138
|
+
const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
|
|
139
|
+
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
|
|
140
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type ProtoFeature = {
|
|
2
|
+
type: 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon';
|
|
3
|
+
simplifiedType: 1 | 2 | 3;
|
|
4
|
+
geometry: any[];
|
|
5
|
+
id?: string;
|
|
6
|
+
tags?: Record<string, unknown>;
|
|
7
|
+
/** spatial extents */
|
|
8
|
+
minX: number;
|
|
9
|
+
/** spatial extents */
|
|
10
|
+
maxX: number;
|
|
11
|
+
/** spatial extents */
|
|
12
|
+
minY: number;
|
|
13
|
+
/** spatial extents */
|
|
14
|
+
maxY: number;
|
|
15
|
+
};
|
|
16
|
+
export type GeoJSONTileGeometry = GeoJSONTilePointGeometry | GeoJSONTileLineGeometry | GeoJSONTilePolygonGeometry;
|
|
17
|
+
export type GeoJSONTilePointGeometry = {
|
|
18
|
+
simplifiedType: 1;
|
|
19
|
+
geometry: number[];
|
|
20
|
+
};
|
|
21
|
+
export type GeoJSONTileLineGeometry = {
|
|
22
|
+
simplifiedType: 1;
|
|
23
|
+
geometry: number[][];
|
|
24
|
+
};
|
|
25
|
+
export type GeoJSONTilePolygonGeometry = {
|
|
26
|
+
simplifiedType: 1;
|
|
27
|
+
geometry: number[][][];
|
|
28
|
+
};
|
|
29
|
+
export declare function createProtoFeature(id: any, type: 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon', geometry: any[], tags: any): ProtoFeature;
|
|
30
|
+
//# sourceMappingURL=proto-feature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proto-feature.d.ts","sourceRoot":"","sources":["../../../../src/lib/vector-tiler/features/proto-feature.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,iBAAiB,GAAG,SAAS,GAAG,cAAc,CAAC;IAC7F,cAAc,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC1B,QAAQ,EAAE,GAAG,EAAE,CAAC;IAGhB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE/B,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAC3B,wBAAwB,GACxB,uBAAuB,GACvB,0BAA0B,CAAC;AAE/B,MAAM,MAAM,wBAAwB,GAAG;IACrC,cAAc,EAAE,CAAC,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,cAAc,EAAE,CAAC,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,cAAc,EAAE,CAAC,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;CACxB,CAAC;AAEF,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,GAAG,EACP,IAAI,EAAE,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,iBAAiB,GAAG,SAAS,GAAG,cAAc,EAC5F,QAAQ,EAAE,GAAG,EAAE,EACf,IAAI,KAAA,GACH,YAAY,CA6Cd"}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 createProtoFeature(id, type, geometry, tags) {
|
|
6
|
+
const feature = {
|
|
7
|
+
// eslint-disable-next-line
|
|
8
|
+
id: id == null ? null : id,
|
|
9
|
+
type,
|
|
10
|
+
simplifiedType: undefined, // TODO
|
|
11
|
+
geometry,
|
|
12
|
+
tags,
|
|
13
|
+
minX: Infinity,
|
|
14
|
+
minY: Infinity,
|
|
15
|
+
maxX: -Infinity,
|
|
16
|
+
maxY: -Infinity
|
|
17
|
+
};
|
|
18
|
+
// TODO break out into separate function
|
|
19
|
+
switch (type) {
|
|
20
|
+
case 'Point':
|
|
21
|
+
case 'MultiPoint':
|
|
22
|
+
case 'LineString':
|
|
23
|
+
calcLineBBox(feature, geometry);
|
|
24
|
+
break;
|
|
25
|
+
case 'MultiLineString':
|
|
26
|
+
for (const line of geometry) {
|
|
27
|
+
calcLineBBox(feature, line);
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
30
|
+
case 'Polygon':
|
|
31
|
+
// the outer ring (ie [0]) contains all inner rings
|
|
32
|
+
calcLineBBox(feature, geometry[0]);
|
|
33
|
+
break;
|
|
34
|
+
case 'MultiPolygon':
|
|
35
|
+
for (const polygon of geometry) {
|
|
36
|
+
// the outer ring (ie [0]) contains all inner rings
|
|
37
|
+
calcLineBBox(feature, polygon[0]);
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(String(type));
|
|
42
|
+
}
|
|
43
|
+
return feature;
|
|
44
|
+
}
|
|
45
|
+
function calcLineBBox(feature, geometry) {
|
|
46
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
47
|
+
feature.minX = Math.min(feature.minX, geometry[i]);
|
|
48
|
+
feature.minY = Math.min(feature.minY, geometry[i + 1]);
|
|
49
|
+
feature.maxX = Math.max(feature.maxX, geometry[i]);
|
|
50
|
+
feature.maxY = Math.max(feature.maxY, geometry[i + 1]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* @param last last coord to simplify
|
|
7
7
|
* @param sqTolerance tolerance (square distance)
|
|
8
8
|
*/
|
|
9
|
-
export declare function
|
|
10
|
-
//# sourceMappingURL=simplify.d.ts.map
|
|
9
|
+
export declare function simplifyPath(coords: number[], first: number, last: number, sqTolerance: number): void;
|
|
10
|
+
//# sourceMappingURL=simplify-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplify-path.d.ts","sourceRoot":"","sources":["../../../../src/lib/vector-tiler/features/simplify-path.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EAAE,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,IAAI,CAkCN"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @param last last coord to simplify
|
|
11
11
|
* @param sqTolerance tolerance (square distance)
|
|
12
12
|
*/
|
|
13
|
-
export function
|
|
13
|
+
export function simplifyPath(coords, first, last, sqTolerance) {
|
|
14
14
|
let maxSqDist = sqTolerance;
|
|
15
15
|
const mid = (last - first) >> 1;
|
|
16
16
|
let minPosToMid = last - first;
|
|
@@ -38,10 +38,10 @@ export function simplify(coords, first, last, sqTolerance) {
|
|
|
38
38
|
}
|
|
39
39
|
if (maxSqDist > sqTolerance) {
|
|
40
40
|
if (index - first > 3)
|
|
41
|
-
|
|
41
|
+
simplifyPath(coords, first, index, sqTolerance);
|
|
42
42
|
coords[index + 2] = maxSqDist;
|
|
43
43
|
if (last - index > 3)
|
|
44
|
-
|
|
44
|
+
simplifyPath(coords, index, last, sqTolerance);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
/** square distance from a point to a segment */
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProtoFeature } from "./proto-feature.js";
|
|
2
2
|
/**
|
|
3
3
|
* Options for wrap()
|
|
4
4
|
*/
|
|
5
|
-
export type
|
|
5
|
+
export type WrapFeaturesOptions = {
|
|
6
6
|
buffer: number /** number of pixels of buffer for the tile */;
|
|
7
7
|
extent: number /** extent of each tile */;
|
|
8
8
|
lineMetrics: boolean;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Wrap across antemeridian, by clipping into two tiles, shifting the overflowing x coordinates
|
|
12
|
-
* @param
|
|
12
|
+
* @param list of features to be wrapped
|
|
13
13
|
* @param options buffer and extent
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
export declare function
|
|
17
|
-
//# sourceMappingURL=wrap.d.ts.map
|
|
16
|
+
export declare function wrapFeatures(features: ProtoFeature[], options: WrapFeaturesOptions): ProtoFeature[];
|
|
17
|
+
//# sourceMappingURL=wrap-features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap-features.d.ts","sourceRoot":"","sources":["../../../../src/lib/vector-tiler/features/wrap-features.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,YAAY,EAAC,2BAAwB;AAIlD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC,8CAA8C,CAAC;IAC9D,MAAM,EAAE,MAAM,CAAC,0BAA0B,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,YAAY,EAAE,EACxB,OAAO,EAAE,mBAAmB,GAC3B,YAAY,EAAE,CAkBhB"}
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { createProtoFeature } from "./proto-feature.js";
|
|
6
|
+
import { clipFeatures } from "./clip-features.js";
|
|
7
7
|
/**
|
|
8
8
|
* Wrap across antemeridian, by clipping into two tiles, shifting the overflowing x coordinates
|
|
9
|
-
* @param
|
|
9
|
+
* @param list of features to be wrapped
|
|
10
10
|
* @param options buffer and extent
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
|
-
export function
|
|
13
|
+
export function wrapFeatures(features, options) {
|
|
14
14
|
const buffer = options.buffer / options.extent;
|
|
15
15
|
let merged = features;
|
|
16
|
-
const left =
|
|
17
|
-
const right =
|
|
16
|
+
const left = clipFeatures(features, 1, -1 - buffer, buffer, 0, -1, 2, options); // left world copy
|
|
17
|
+
const right = clipFeatures(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options); // right world copy
|
|
18
18
|
if (left || right) {
|
|
19
|
-
merged =
|
|
19
|
+
merged = clipFeatures(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || []; // center world copy
|
|
20
20
|
if (left) {
|
|
21
21
|
merged = shiftFeatureCoords(left, 1).concat(merged); // merge left into center
|
|
22
22
|
}
|
|
@@ -38,27 +38,34 @@ function shiftFeatureCoords(features, offset) {
|
|
|
38
38
|
const feature = features[i];
|
|
39
39
|
const type = feature.type;
|
|
40
40
|
let newGeometry;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
switch (type) {
|
|
42
|
+
case 'Point':
|
|
43
|
+
case 'MultiPoint':
|
|
44
|
+
case 'LineString':
|
|
45
|
+
newGeometry = shiftCoords(feature.geometry, offset);
|
|
46
|
+
break;
|
|
47
|
+
case 'MultiLineString':
|
|
48
|
+
case 'Polygon':
|
|
49
|
+
newGeometry = [];
|
|
50
|
+
for (const line of feature.geometry) {
|
|
51
|
+
newGeometry.push(shiftCoords(line, offset));
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
case 'MultiPolygon':
|
|
55
|
+
newGeometry = [];
|
|
56
|
+
for (const polygon of feature.geometry) {
|
|
57
|
+
const newPolygon = [];
|
|
58
|
+
for (const line of polygon) {
|
|
59
|
+
// @ts-expect-error TODO
|
|
60
|
+
newPolygon.push(shiftCoords(line, offset));
|
|
61
|
+
}
|
|
62
|
+
newGeometry.push(newPolygon);
|
|
57
63
|
}
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
throw new Error(String(type));
|
|
60
67
|
}
|
|
61
|
-
newFeatures.push(
|
|
68
|
+
newFeatures.push(createProtoFeature(feature.id, type, newGeometry, feature.tags));
|
|
62
69
|
}
|
|
63
70
|
return newFeatures;
|
|
64
71
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ProtoFeature } from "./features/proto-feature.js";
|
|
2
|
+
export type ProtoTile = {
|
|
3
|
+
/** Processed features */
|
|
4
|
+
protoFeatures: ProtoFeature[];
|
|
5
|
+
/** if we slice further down, no need to keep source geometry */
|
|
6
|
+
sourceFeatures: ProtoFeature[] | null;
|
|
7
|
+
/** Properties */
|
|
8
|
+
tags?: Record<string, string>;
|
|
9
|
+
/** tile x coordinate */
|
|
10
|
+
x: number;
|
|
11
|
+
/** tile y coordinate */
|
|
12
|
+
y: number;
|
|
13
|
+
/** tile z coordinate */
|
|
14
|
+
z: number;
|
|
15
|
+
/** spatial extent */
|
|
16
|
+
minX: number;
|
|
17
|
+
/** spatial extent */
|
|
18
|
+
maxX: number;
|
|
19
|
+
/** spatial extent */
|
|
20
|
+
minY: number;
|
|
21
|
+
/** spatial extent */
|
|
22
|
+
maxY: number;
|
|
23
|
+
/** Whether this tile has been transformed */
|
|
24
|
+
transformed: boolean;
|
|
25
|
+
numPoints: number;
|
|
26
|
+
numSimplified: number;
|
|
27
|
+
/** Number of features in this tile */
|
|
28
|
+
numFeatures: number;
|
|
29
|
+
};
|
|
30
|
+
export type CreateTileOptions = {
|
|
31
|
+
maxZoom?: number;
|
|
32
|
+
tolerance: number;
|
|
33
|
+
extent: number;
|
|
34
|
+
lineMetrics: boolean;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Create a tile from features and tile index
|
|
38
|
+
*/
|
|
39
|
+
export declare function createProtoTile(features: ProtoFeature[], z: any, tx: any, ty: any, options: CreateTileOptions): ProtoTile;
|
|
40
|
+
//# sourceMappingURL=proto-tile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proto-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/proto-tile.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,YAAY,EAAC,oCAAiC;AAE3D,MAAM,MAAM,SAAS,GAAG;IACtB,yBAAyB;IACzB,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,gEAAgE;IAChE,cAAc,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAEtC,iBAAiB;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE9B,wBAAwB;IACxB,CAAC,EAAE,MAAM,CAAC;IACV,wBAAwB;IACxB,CAAC,EAAE,MAAM,CAAC;IACV,wBAAwB;IACxB,CAAC,EAAE,MAAM,CAAC;IAEV,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IAEb,6CAA6C;IAC7C,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;CACrB,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,eAAe,CAC7B,QAAQ,EAAE,YAAY,EAAE,EACxB,CAAC,KAAA,EACD,EAAE,KAAA,EACF,EAAE,KAAA,EACF,OAAO,EAAE,iBAAiB,GACzB,SAAS,CAqBX"}
|