@loaders.gl/mvt 4.3.0-alpha.1 → 4.3.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +1289 -807
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +923 -773
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/lib/parse-mvt.d.ts +1 -1
- package/dist/lib/parse-mvt.js +2 -30
- package/dist/lib/parse-tilejson.d.ts +4 -4
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.js +1 -1
- package/dist/lib/utils/geometry-utils.d.ts +38 -1
- package/dist/lib/utils/geometry-utils.d.ts.map +1 -1
- package/dist/lib/utils/geometry-utils.js +65 -6
- package/dist/lib/vector-tile/vector-tile-feature.d.ts +28 -9
- package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/vector-tile/vector-tile-feature.js +47 -50
- package/dist/lib/{geojsonvt/clip.d.ts → vector-tiler/features/clip-features.d.ts} +4 -4
- package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/clip.js → vector-tiler/features/clip-features.js} +4 -4
- package/dist/lib/vector-tiler/features/convert-feature.d.ts +18 -0
- package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
- package/dist/lib/{geojsonvt/simplify.d.ts → vector-tiler/features/simplify-path.d.ts} +2 -2
- package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/simplify.js → vector-tiler/features/simplify-path.js} +3 -3
- package/dist/lib/{geojsonvt/wrap.d.ts → vector-tiler/features/wrap-features.d.ts} +5 -5
- package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
- package/dist/lib/{geojsonvt/wrap.js → vector-tiler/features/wrap-features.js} +33 -26
- package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
- package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/proto-tile.js +138 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
- package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/transform-tile.js +41 -0
- package/dist/mvt-loader.d.ts +1 -1
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-source.d.ts +35 -18
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +30 -10
- package/dist/mvt-worker.js +101 -56
- package/dist/table-tile-source.d.ts +148 -0
- package/dist/table-tile-source.d.ts.map +1 -0
- package/dist/table-tile-source.js +420 -0
- package/dist/tilejson-loader.js +1 -1
- package/package.json +7 -6
- package/src/index.ts +14 -7
- package/src/lib/parse-mvt.ts +4 -33
- package/src/lib/parse-tilejson.ts +6 -6
- package/src/lib/utils/geometry-utils.ts +66 -1
- package/src/lib/vector-tile/vector-tile-feature.ts +65 -56
- package/src/lib/{geojsonvt/clip.ts → vector-tiler/features/clip-features.ts} +8 -8
- package/src/lib/vector-tiler/features/convert-feature.ts +191 -0
- package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
- package/src/lib/{geojsonvt/simplify.ts → vector-tiler/features/simplify-path.ts} +8 -3
- package/src/lib/{geojsonvt/wrap.ts → vector-tiler/features/wrap-features.ts} +44 -29
- package/src/lib/vector-tiler/proto-tile.ts +217 -0
- package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
- package/src/lib/vector-tiler/transform-tile.ts +57 -0
- package/src/mvt-source.ts +47 -24
- package/src/table-tile-source.ts +553 -0
- package/src/tilejson-loader.ts +2 -2
- package/dist/geojson-tile-source.d.ts +0 -79
- package/dist/geojson-tile-source.d.ts.map +0 -1
- package/dist/geojson-tile-source.js +0 -319
- package/dist/lib/geojsonvt/clip.d.ts.map +0 -1
- package/dist/lib/geojsonvt/convert.d.ts +0 -10
- package/dist/lib/geojsonvt/convert.d.ts.map +0 -1
- package/dist/lib/geojsonvt/convert.js +0 -132
- package/dist/lib/geojsonvt/feature.d.ts +0 -3
- package/dist/lib/geojsonvt/feature.d.ts.map +0 -1
- package/dist/lib/geojsonvt/feature.js +0 -44
- package/dist/lib/geojsonvt/simplify.d.ts.map +0 -1
- package/dist/lib/geojsonvt/tile.d.ts +0 -38
- package/dist/lib/geojsonvt/tile.d.ts.map +0 -1
- package/dist/lib/geojsonvt/tile.js +0 -123
- package/dist/lib/geojsonvt/transform.d.ts +0 -7
- package/dist/lib/geojsonvt/transform.d.ts.map +0 -1
- package/dist/lib/geojsonvt/transform.js +0 -41
- package/dist/lib/geojsonvt/wrap.d.ts.map +0 -1
- package/src/geojson-tile-source.ts +0 -422
- package/src/lib/geojsonvt/convert.ts +0 -160
- package/src/lib/geojsonvt/feature.ts +0 -47
- package/src/lib/geojsonvt/tile.ts +0 -187
- package/src/lib/geojsonvt/transform.ts +0 -57
- /package/src/lib/{geojsonvt → vector-tiler}/LICENSE +0 -0
|
@@ -0,0 +1,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"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
+
/**
|
|
6
|
+
* Create a tile from features and tile index
|
|
7
|
+
*/
|
|
8
|
+
export function createProtoTile(features, z, tx, ty, options) {
|
|
9
|
+
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
10
|
+
const tile = {
|
|
11
|
+
protoFeatures: [],
|
|
12
|
+
sourceFeatures: null,
|
|
13
|
+
numPoints: 0,
|
|
14
|
+
numSimplified: 0,
|
|
15
|
+
numFeatures: features.length,
|
|
16
|
+
x: tx,
|
|
17
|
+
y: ty,
|
|
18
|
+
z,
|
|
19
|
+
transformed: false,
|
|
20
|
+
minX: 2,
|
|
21
|
+
minY: 1,
|
|
22
|
+
maxX: -1,
|
|
23
|
+
maxY: 0
|
|
24
|
+
};
|
|
25
|
+
for (const feature of features) {
|
|
26
|
+
addProtoFeature(tile, feature, tolerance, options);
|
|
27
|
+
}
|
|
28
|
+
return tile;
|
|
29
|
+
}
|
|
30
|
+
// eslint-disable-next-line complexity, max-statements
|
|
31
|
+
function addProtoFeature(tile, feature, tolerance, options) {
|
|
32
|
+
const geometry = feature.geometry;
|
|
33
|
+
const type = feature.type;
|
|
34
|
+
const simplifiedGeometry = [];
|
|
35
|
+
tile.minX = Math.min(tile.minX, feature.minX);
|
|
36
|
+
tile.minY = Math.min(tile.minY, feature.minY);
|
|
37
|
+
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
38
|
+
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
39
|
+
let simplifiedType;
|
|
40
|
+
switch (type) {
|
|
41
|
+
case 'Point':
|
|
42
|
+
case 'MultiPoint':
|
|
43
|
+
simplifiedType = 1;
|
|
44
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
45
|
+
simplifiedGeometry.push(geometry[i], geometry[i + 1]);
|
|
46
|
+
tile.numPoints++;
|
|
47
|
+
tile.numSimplified++;
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
case 'LineString':
|
|
51
|
+
simplifiedType = 2;
|
|
52
|
+
addProtoLine(simplifiedGeometry, geometry, tile, tolerance, false, false);
|
|
53
|
+
break;
|
|
54
|
+
case 'MultiLineString':
|
|
55
|
+
simplifiedType = 2;
|
|
56
|
+
for (let i = 0; i < geometry.length; i++) {
|
|
57
|
+
addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, false, i === 0);
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
case 'Polygon':
|
|
61
|
+
simplifiedType = 3;
|
|
62
|
+
for (let i = 0; i < geometry.length; i++) {
|
|
63
|
+
addProtoLine(simplifiedGeometry, geometry[i], tile, tolerance, true, i === 0);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case 'MultiPolygon':
|
|
67
|
+
simplifiedType = 3;
|
|
68
|
+
for (let k = 0; k < geometry.length; k++) {
|
|
69
|
+
const polygon = geometry[k];
|
|
70
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
71
|
+
addProtoLine(simplifiedGeometry, polygon[i], tile, tolerance, true, i === 0);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
throw new Error(`Unknown geometry type: ${type}`);
|
|
77
|
+
}
|
|
78
|
+
if (simplifiedGeometry.length) {
|
|
79
|
+
let tags = feature.tags || null;
|
|
80
|
+
if (type === 'LineString' && options.lineMetrics) {
|
|
81
|
+
tags = {};
|
|
82
|
+
for (const key in feature.tags) {
|
|
83
|
+
tags[key] = feature.tags[key];
|
|
84
|
+
}
|
|
85
|
+
// @ts-expect-error adding fields to arrays
|
|
86
|
+
// eslint-disable-next-line camelcase
|
|
87
|
+
tags.mapbox_clip_start = geometry.start / geometry.size;
|
|
88
|
+
// @ts-expect-error adding fields to arrays
|
|
89
|
+
// eslint-disable-next-line camelcase
|
|
90
|
+
tags.mapbox_clip_end = geometry.end / geometry.size;
|
|
91
|
+
}
|
|
92
|
+
const tileFeature = {
|
|
93
|
+
geometry: simplifiedGeometry,
|
|
94
|
+
simplifiedType,
|
|
95
|
+
// @ts-expect-error
|
|
96
|
+
tags
|
|
97
|
+
};
|
|
98
|
+
if (feature.id !== null) {
|
|
99
|
+
tileFeature.id = feature.id;
|
|
100
|
+
}
|
|
101
|
+
tile.protoFeatures.push(tileFeature);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// eslint-disable-next-line max-params, max-statements
|
|
105
|
+
function addProtoLine(result, geometry, tile, tolerance, isPolygon, isOuter) {
|
|
106
|
+
const sqTolerance = tolerance * tolerance;
|
|
107
|
+
if (tolerance > 0 && geometry.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
108
|
+
tile.numPoints += geometry.length / 3;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const ring = [];
|
|
112
|
+
for (let i = 0; i < geometry.length; i += 3) {
|
|
113
|
+
if (tolerance === 0 || geometry[i + 2] > sqTolerance) {
|
|
114
|
+
tile.numSimplified++;
|
|
115
|
+
ring.push(geometry[i], geometry[i + 1]);
|
|
116
|
+
}
|
|
117
|
+
tile.numPoints++;
|
|
118
|
+
}
|
|
119
|
+
if (isPolygon)
|
|
120
|
+
rewind(ring, isOuter);
|
|
121
|
+
result.push(ring);
|
|
122
|
+
}
|
|
123
|
+
function rewind(ring, clockwise) {
|
|
124
|
+
let area = 0;
|
|
125
|
+
for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
|
|
126
|
+
area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
|
|
127
|
+
}
|
|
128
|
+
if (area > 0 === clockwise) {
|
|
129
|
+
for (let i = 0, len = ring.length; i < len / 2; i += 2) {
|
|
130
|
+
const x = ring[i];
|
|
131
|
+
const y = ring[i + 1];
|
|
132
|
+
ring[i] = ring[len - 2 - i];
|
|
133
|
+
ring[i + 1] = ring[len - 1 - i];
|
|
134
|
+
ring[len - 2 - i] = x;
|
|
135
|
+
ring[len - 1 - i] = y;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ProtoTile } from "./proto-tile.js";
|
|
2
|
+
import { GeoJSONTable } from '@loaders.gl/schema';
|
|
3
|
+
export declare function convertTileToGeoJSON(protoTile: ProtoTile, props: {
|
|
4
|
+
coordinates: 'EPSG:4326' | 'wgs84' | 'local';
|
|
5
|
+
tileIndex: {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
z: number;
|
|
9
|
+
};
|
|
10
|
+
extent: number;
|
|
11
|
+
}): GeoJSONTable | null;
|
|
12
|
+
//# sourceMappingURL=tile-to-geojson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile-to-geojson.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/tile-to-geojson.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,SAAS,EAAC,wBAAqB;AACvC,OAAO,EAAU,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAMzD,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE;IACL,WAAW,EAAE,WAAW,GAAG,OAAO,GAAG,OAAO,CAAC;IAC7C,SAAS,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC;CAChB,GACA,YAAY,GAAG,IAAI,CAqFrB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { projectToLngLat } from "../utils/geometry-utils.js";
|
|
6
|
+
import { convertToLocalCoordinates } from "../utils/geometry-utils.js";
|
|
7
|
+
// eslint-disable-next-line max-statements, complexity
|
|
8
|
+
export function convertTileToGeoJSON(protoTile, props) {
|
|
9
|
+
const features = [];
|
|
10
|
+
for (const rawFeature of protoTile.protoFeatures) {
|
|
11
|
+
if (!rawFeature || !rawFeature.geometry) {
|
|
12
|
+
// eslint-disable-next-line no-continue
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
let type;
|
|
16
|
+
let coordinates;
|
|
17
|
+
// raw geometry
|
|
18
|
+
switch (rawFeature.simplifiedType) {
|
|
19
|
+
case 1:
|
|
20
|
+
if (rawFeature.geometry.length === 1) {
|
|
21
|
+
type = 'Point';
|
|
22
|
+
coordinates = rawFeature.geometry[0];
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
type = 'MultiPoint';
|
|
26
|
+
coordinates = rawFeature.geometry;
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
case 2:
|
|
30
|
+
if (rawFeature.geometry.length === 1) {
|
|
31
|
+
type = 'LineString';
|
|
32
|
+
coordinates = rawFeature.geometry[0];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
type = 'MultiLineString';
|
|
36
|
+
coordinates = rawFeature.geometry;
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
case 3:
|
|
40
|
+
if (rawFeature.geometry.length > 1) {
|
|
41
|
+
type = 'MultiPolygon';
|
|
42
|
+
coordinates = [rawFeature.geometry];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
type = 'Polygon';
|
|
46
|
+
coordinates = rawFeature.geometry;
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
throw new Error(`${rawFeature.simplifiedType}is not a valid simplified type`);
|
|
51
|
+
}
|
|
52
|
+
switch (props.coordinates) {
|
|
53
|
+
case 'EPSG:4326':
|
|
54
|
+
case 'wgs84':
|
|
55
|
+
projectToLngLat(coordinates, props.tileIndex, props.extent);
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
convertToLocalCoordinates(coordinates, props.extent);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
const feature = {
|
|
62
|
+
type: 'Feature',
|
|
63
|
+
geometry: {
|
|
64
|
+
type,
|
|
65
|
+
coordinates
|
|
66
|
+
},
|
|
67
|
+
properties: rawFeature.tags || {},
|
|
68
|
+
id: rawFeature.id
|
|
69
|
+
};
|
|
70
|
+
features.push(feature);
|
|
71
|
+
}
|
|
72
|
+
if (features.length === 0) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const table = {
|
|
76
|
+
shape: 'geojson-table',
|
|
77
|
+
type: 'FeatureCollection',
|
|
78
|
+
features
|
|
79
|
+
};
|
|
80
|
+
return table;
|
|
81
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProtoTile } from "./proto-tile.js";
|
|
2
|
+
/**
|
|
3
|
+
* Transforms the coordinates of each protoFeature in the given protoTile from
|
|
4
|
+
* mercator-projected space into (extent x extent) protoTile space.
|
|
5
|
+
*/
|
|
6
|
+
export declare function transformTile(protoTile: ProtoTile, extent: number): ProtoTile;
|
|
7
|
+
//# sourceMappingURL=transform-tile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-tile.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/transform-tile.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,SAAS,EAAC,wBAAqB;AAE5C;;;GAGG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAiC7E"}
|