@loaders.gl/mvt 4.2.0-alpha.4 → 4.2.0-alpha.6
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 +312 -244
- package/dist/dist.min.js +14 -0
- package/dist/helpers/binary-util-functions.d.ts +1 -1
- package/dist/helpers/binary-util-functions.d.ts.map +1 -1
- package/dist/helpers/binary-util-functions.js +99 -61
- package/dist/helpers/mapbox-util-functions.d.ts +2 -2
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -1
- package/dist/helpers/mapbox-util-functions.js +67 -33
- package/dist/index.cjs +86 -68
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +144 -118
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -38
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +1 -1
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile.js +18 -12
- package/dist/lib/geojson-tiler/clip.d.ts +1 -1
- package/dist/lib/geojson-tiler/clip.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/clip.js +180 -142
- package/dist/lib/geojson-tiler/convert.d.ts +1 -1
- package/dist/lib/geojson-tiler/convert.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/convert.js +116 -100
- package/dist/lib/geojson-tiler/feature.d.ts +1 -1
- package/dist/lib/geojson-tiler/feature.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/feature.js +38 -29
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts +1 -1
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/geojson-tiler.js +198 -159
- package/dist/lib/geojson-tiler/simplify.js +60 -40
- package/dist/lib/geojson-tiler/tile.js +108 -88
- package/dist/lib/geojson-tiler/transform.d.ts +1 -1
- package/dist/lib/geojson-tiler/transform.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/transform.js +35 -26
- package/dist/lib/geojson-tiler/wrap.d.ts +1 -1
- package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/wrap.js +74 -53
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +164 -151
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -38
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.js +18 -12
- package/dist/lib/parse-mvt.d.ts +1 -1
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +142 -115
- package/dist/lib/parse-tilejson.js +234 -176
- package/dist/lib/types.js +0 -1
- package/dist/mvt-loader.d.ts +1 -1
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +42 -22
- package/dist/mvt-source.js +153 -139
- package/dist/mvt-worker.js +39 -2
- package/dist/tilejson-loader.d.ts +1 -1
- package/dist/tilejson-loader.d.ts.map +1 -1
- package/dist/tilejson-loader.js +32 -31
- package/dist/workers/mvt-worker.js +0 -1
- package/package.json +12 -8
- package/dist/helpers/binary-util-functions.js.map +0 -1
- package/dist/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/binary-vector-tile/LICENSE.txt +0 -31
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/geojson-tiler/LICENSE +0 -19
- package/dist/lib/geojson-tiler/clip.js.map +0 -1
- package/dist/lib/geojson-tiler/convert.js.map +0 -1
- package/dist/lib/geojson-tiler/feature.js.map +0 -1
- package/dist/lib/geojson-tiler/geojson-tiler.js.map +0 -1
- package/dist/lib/geojson-tiler/simplify.js.map +0 -1
- package/dist/lib/geojson-tiler/tile.js.map +0 -1
- package/dist/lib/geojson-tiler/transform.js.map +0 -1
- package/dist/lib/geojson-tiler/wrap.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/LICENSE.txt +0 -31
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/parse-mvt.js.map +0 -1
- package/dist/lib/parse-tilejson.js.map +0 -1
- package/dist/lib/types.js.map +0 -1
- package/dist/mvt-loader.js.map +0 -1
- package/dist/mvt-source.js.map +0 -1
- package/dist/tilejson-loader.js.map +0 -1
- package/dist/workers/mvt-worker.js.map +0 -1
|
@@ -1,172 +1,210 @@
|
|
|
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
|
|
1
5
|
import { createFeature } from "./feature.js";
|
|
6
|
+
/* eslint-disable no-continue */
|
|
7
|
+
/**
|
|
8
|
+
* Clip features between two vertical or horizontal axis-parallel lines:
|
|
9
|
+
* | |
|
|
10
|
+
* ___|___ | /
|
|
11
|
+
* / | \____|____/
|
|
12
|
+
* | |
|
|
13
|
+
*
|
|
14
|
+
* @param k1 and k2 are the line coordinates
|
|
15
|
+
* @param axis: 0 for x, 1 for y
|
|
16
|
+
* @param minAll and maxAll: minimum and maximum coordinate value for all features
|
|
17
|
+
*/
|
|
18
|
+
// eslint-disable-next-line max-params, complexity, max-statements
|
|
2
19
|
export function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} else if (maxAll < k1 || minAll >= k2) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
const clipped = [];
|
|
11
|
-
for (const feature of features) {
|
|
12
|
-
const geometry = feature.geometry;
|
|
13
|
-
let type = feature.type;
|
|
14
|
-
const min = axis === 0 ? feature.minX : feature.minY;
|
|
15
|
-
const max = axis === 0 ? feature.maxX : feature.maxY;
|
|
16
|
-
if (min >= k1 && max < k2) {
|
|
17
|
-
clipped.push(feature);
|
|
18
|
-
continue;
|
|
19
|
-
} else if (max < k1 || min >= k2) {
|
|
20
|
-
continue;
|
|
20
|
+
k1 /= scale;
|
|
21
|
+
k2 /= scale;
|
|
22
|
+
if (minAll >= k1 && maxAll < k2) {
|
|
23
|
+
return features;
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
} else if (type === 'LineString') {
|
|
26
|
-
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
|
|
27
|
-
} else if (type === 'MultiLineString') {
|
|
28
|
-
clipLines(geometry, newGeometry, k1, k2, axis, false);
|
|
29
|
-
} else if (type === 'Polygon') {
|
|
30
|
-
clipLines(geometry, newGeometry, k1, k2, axis, true);
|
|
31
|
-
} else if (type === 'MultiPolygon') {
|
|
32
|
-
for (const polygon of geometry) {
|
|
33
|
-
const newPolygon = [];
|
|
34
|
-
clipLines(polygon, newPolygon, k1, k2, axis, true);
|
|
35
|
-
if (newPolygon.length) {
|
|
36
|
-
newGeometry.push(newPolygon);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
25
|
+
// trivial accept
|
|
26
|
+
else if (maxAll < k1 || minAll >= k2) {
|
|
27
|
+
return null; // trivial reject
|
|
39
28
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
type
|
|
57
|
-
|
|
58
|
-
|
|
29
|
+
const clipped = [];
|
|
30
|
+
for (const feature of features) {
|
|
31
|
+
const geometry = feature.geometry;
|
|
32
|
+
let type = feature.type;
|
|
33
|
+
const min = axis === 0 ? feature.minX : feature.minY;
|
|
34
|
+
const max = axis === 0 ? feature.maxX : feature.maxY;
|
|
35
|
+
if (min >= k1 && max < k2) {
|
|
36
|
+
// trivial accept
|
|
37
|
+
clipped.push(feature);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
else if (max < k1 || min >= k2) {
|
|
41
|
+
// trivial reject
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
let newGeometry = [];
|
|
45
|
+
if (type === 'Point' || type === 'MultiPoint') {
|
|
46
|
+
clipPoints(geometry, newGeometry, k1, k2, axis);
|
|
47
|
+
}
|
|
48
|
+
else if (type === 'LineString') {
|
|
49
|
+
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
|
|
50
|
+
}
|
|
51
|
+
else if (type === 'MultiLineString') {
|
|
52
|
+
clipLines(geometry, newGeometry, k1, k2, axis, false);
|
|
53
|
+
}
|
|
54
|
+
else if (type === 'Polygon') {
|
|
55
|
+
clipLines(geometry, newGeometry, k1, k2, axis, true);
|
|
56
|
+
}
|
|
57
|
+
else if (type === 'MultiPolygon') {
|
|
58
|
+
for (const polygon of geometry) {
|
|
59
|
+
const newPolygon = [];
|
|
60
|
+
clipLines(polygon, newPolygon, k1, k2, axis, true);
|
|
61
|
+
if (newPolygon.length) {
|
|
62
|
+
newGeometry.push(newPolygon);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (newGeometry.length) {
|
|
67
|
+
if (options.lineMetrics && type === 'LineString') {
|
|
68
|
+
for (const line of newGeometry) {
|
|
69
|
+
clipped.push(createFeature(feature.id, type, line, feature.tags));
|
|
70
|
+
}
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (type === 'LineString' || type === 'MultiLineString') {
|
|
74
|
+
if (newGeometry.length === 1) {
|
|
75
|
+
type = 'LineString';
|
|
76
|
+
// @ts-expect-error TODO - use proper GeoJSON geometry types
|
|
77
|
+
newGeometry = newGeometry[0];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
type = 'MultiLineString';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (type === 'Point' || type === 'MultiPoint') {
|
|
84
|
+
type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
|
|
85
|
+
}
|
|
86
|
+
clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
|
|
87
|
+
}
|
|
59
88
|
}
|
|
60
|
-
|
|
61
|
-
return clipped.length ? clipped : null;
|
|
89
|
+
return clipped.length ? clipped : null;
|
|
62
90
|
}
|
|
63
91
|
function clipPoints(geom, newGeom, k1, k2, axis) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
92
|
+
for (let i = 0; i < geom.length; i += 3) {
|
|
93
|
+
const a = geom[i + axis];
|
|
94
|
+
if (a >= k1 && a <= k2) {
|
|
95
|
+
addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
|
|
96
|
+
}
|
|
68
97
|
}
|
|
69
|
-
}
|
|
70
98
|
}
|
|
99
|
+
// eslint-disable-next-line max-params, complexity, max-statements
|
|
71
100
|
function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (trackMetrics) {
|
|
87
|
-
segLen = Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2));
|
|
88
|
-
}
|
|
89
|
-
if (a < k1) {
|
|
90
|
-
if (b > k1) {
|
|
91
|
-
t = intersect(slice, ax, ay, bx, by, k1);
|
|
101
|
+
let slice = newSlice(geom);
|
|
102
|
+
const intersect = axis === 0 ? intersectX : intersectY;
|
|
103
|
+
let len = geom.start;
|
|
104
|
+
let segLen;
|
|
105
|
+
let t;
|
|
106
|
+
for (let i = 0; i < geom.length - 3; i += 3) {
|
|
107
|
+
const ax = geom[i];
|
|
108
|
+
const ay = geom[i + 1];
|
|
109
|
+
const az = geom[i + 2];
|
|
110
|
+
const bx = geom[i + 3];
|
|
111
|
+
const by = geom[i + 4];
|
|
112
|
+
const a = axis === 0 ? ax : ay;
|
|
113
|
+
const b = axis === 0 ? bx : by;
|
|
114
|
+
let exited = false;
|
|
92
115
|
if (trackMetrics) {
|
|
93
|
-
|
|
116
|
+
segLen = Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2));
|
|
117
|
+
}
|
|
118
|
+
if (a < k1) {
|
|
119
|
+
// ---|--> | (line enters the clip region from the left)
|
|
120
|
+
if (b > k1) {
|
|
121
|
+
t = intersect(slice, ax, ay, bx, by, k1);
|
|
122
|
+
if (trackMetrics) {
|
|
123
|
+
slice.start = len + segLen * t;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else if (a > k2) {
|
|
128
|
+
// | <--|--- (line enters the clip region from the right)
|
|
129
|
+
if (b < k2) {
|
|
130
|
+
t = intersect(slice, ax, ay, bx, by, k2);
|
|
131
|
+
if (trackMetrics) {
|
|
132
|
+
slice.start = len + segLen * t;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
addPoint(slice, ax, ay, az);
|
|
138
|
+
}
|
|
139
|
+
if (b < k1 && a >= k1) {
|
|
140
|
+
// <--|--- | or <--|-----|--- (line exits the clip region on the left)
|
|
141
|
+
t = intersect(slice, ax, ay, bx, by, k1);
|
|
142
|
+
exited = true;
|
|
143
|
+
}
|
|
144
|
+
if (b > k2 && a <= k2) {
|
|
145
|
+
// | ---|--> or ---|-----|--> (line exits the clip region on the right)
|
|
146
|
+
t = intersect(slice, ax, ay, bx, by, k2);
|
|
147
|
+
exited = true;
|
|
148
|
+
}
|
|
149
|
+
if (!isPolygon && exited) {
|
|
150
|
+
if (trackMetrics) {
|
|
151
|
+
slice.end = len + segLen * t;
|
|
152
|
+
}
|
|
153
|
+
newGeom.push(slice);
|
|
154
|
+
slice = newSlice(geom);
|
|
94
155
|
}
|
|
95
|
-
}
|
|
96
|
-
} else if (a > k2) {
|
|
97
|
-
if (b < k2) {
|
|
98
|
-
t = intersect(slice, ax, ay, bx, by, k2);
|
|
99
156
|
if (trackMetrics) {
|
|
100
|
-
|
|
157
|
+
len += segLen;
|
|
101
158
|
}
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
addPoint(slice, ax, ay, az);
|
|
105
|
-
}
|
|
106
|
-
if (b < k1 && a >= k1) {
|
|
107
|
-
t = intersect(slice, ax, ay, bx, by, k1);
|
|
108
|
-
exited = true;
|
|
109
|
-
}
|
|
110
|
-
if (b > k2 && a <= k2) {
|
|
111
|
-
t = intersect(slice, ax, ay, bx, by, k2);
|
|
112
|
-
exited = true;
|
|
113
159
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
160
|
+
// add the last point
|
|
161
|
+
let last = geom.length - 3;
|
|
162
|
+
const ax = geom[last];
|
|
163
|
+
const ay = geom[last + 1];
|
|
164
|
+
const az = geom[last + 2];
|
|
165
|
+
const a = axis === 0 ? ax : ay;
|
|
166
|
+
if (a >= k1 && a <= k2)
|
|
167
|
+
addPoint(slice, ax, ay, az);
|
|
168
|
+
// close the polygon if its endpoints are not the same after clipping
|
|
169
|
+
last = slice.length - 3;
|
|
170
|
+
if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
|
|
171
|
+
addPoint(slice, slice[0], slice[1], slice[2]);
|
|
120
172
|
}
|
|
121
|
-
|
|
122
|
-
|
|
173
|
+
// add the final slice
|
|
174
|
+
if (slice.length) {
|
|
175
|
+
newGeom.push(slice);
|
|
123
176
|
}
|
|
124
|
-
}
|
|
125
|
-
let last = geom.length - 3;
|
|
126
|
-
const ax = geom[last];
|
|
127
|
-
const ay = geom[last + 1];
|
|
128
|
-
const az = geom[last + 2];
|
|
129
|
-
const a = axis === 0 ? ax : ay;
|
|
130
|
-
if (a >= k1 && a <= k2) addPoint(slice, ax, ay, az);
|
|
131
|
-
last = slice.length - 3;
|
|
132
|
-
if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
|
|
133
|
-
addPoint(slice, slice[0], slice[1], slice[2]);
|
|
134
|
-
}
|
|
135
|
-
if (slice.length) {
|
|
136
|
-
newGeom.push(slice);
|
|
137
|
-
}
|
|
138
177
|
}
|
|
139
178
|
class Slice extends Array {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.start = void 0;
|
|
144
|
-
this.end = void 0;
|
|
145
|
-
}
|
|
179
|
+
size;
|
|
180
|
+
start;
|
|
181
|
+
end;
|
|
146
182
|
}
|
|
147
183
|
function newSlice(line) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
184
|
+
const slice = [];
|
|
185
|
+
slice.size = line.size;
|
|
186
|
+
slice.start = line.start;
|
|
187
|
+
slice.end = line.end;
|
|
188
|
+
return slice;
|
|
153
189
|
}
|
|
190
|
+
// eslint-disable-next-line max-params
|
|
154
191
|
function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
192
|
+
for (const line of geom) {
|
|
193
|
+
clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
|
|
194
|
+
}
|
|
158
195
|
}
|
|
159
196
|
function addPoint(out, x, y, z) {
|
|
160
|
-
|
|
197
|
+
out.push(x, y, z);
|
|
161
198
|
}
|
|
199
|
+
// eslint-disable-next-line max-params
|
|
162
200
|
function intersectX(out, ax, ay, bx, by, x) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
201
|
+
const t = (x - ax) / (bx - ax);
|
|
202
|
+
addPoint(out, x, ay + (by - ay) * t, 1);
|
|
203
|
+
return t;
|
|
166
204
|
}
|
|
205
|
+
// eslint-disable-next-line max-params
|
|
167
206
|
function intersectY(out, ax, ay, bx, by, y) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
207
|
+
const t = (y - ay) / (by - ay);
|
|
208
|
+
addPoint(out, ax + (bx - ax) * t, y, 1);
|
|
209
|
+
return t;
|
|
171
210
|
}
|
|
172
|
-
//# sourceMappingURL=clip.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Feature } from '@loaders.gl/schema';
|
|
2
|
-
import type { GeoJSONTileFeature } from
|
|
2
|
+
import type { GeoJSONTileFeature } from "./tile.js";
|
|
3
3
|
export declare function convert(data: Feature, options: any): GeoJSONTileFeature[];
|
|
4
4
|
export type ConvertFeatureOptions = {
|
|
5
5
|
maxZoom?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/convert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAC,kBAAkB,EAAC,
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/convert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAO/C,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,KAAA,GAAG,kBAAkB,EAAE,CAcpE;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC"}
|
|
@@ -1,116 +1,132 @@
|
|
|
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
|
|
1
5
|
import { simplify } from "./simplify.js";
|
|
2
6
|
import { createFeature } from "./feature.js";
|
|
7
|
+
// converts GeoJSON feature into an intermediate projected JSON vector format with simplification data
|
|
3
8
|
export function convert(data, options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
const features = [];
|
|
10
|
+
if (data.type === 'FeatureCollection') {
|
|
11
|
+
for (let i = 0; i < data.features.length; i++) {
|
|
12
|
+
convertFeature(features, data.features[i], options, i);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else if (data.type === 'Feature') {
|
|
16
|
+
convertFeature(features, data, options);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// single geometry or a geometry collection
|
|
20
|
+
convertFeature(features, { geometry: data }, options);
|
|
21
|
+
}
|
|
22
|
+
return features;
|
|
17
23
|
}
|
|
18
24
|
function convertFeature(features, geojson, options, index) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
25
|
+
if (!geojson.geometry) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const coords = geojson.geometry.coordinates;
|
|
29
|
+
const type = geojson.geometry.type;
|
|
30
|
+
const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
|
|
31
|
+
let geometry = [];
|
|
32
|
+
let id = geojson.id;
|
|
33
|
+
if (options.promoteId) {
|
|
34
|
+
id = geojson.properties[options.promoteId];
|
|
35
|
+
}
|
|
36
|
+
else if (options.generateId) {
|
|
37
|
+
id = index || 0;
|
|
38
|
+
}
|
|
39
|
+
if (type === 'Point') {
|
|
40
|
+
convertPoint(coords, geometry);
|
|
41
|
+
}
|
|
42
|
+
else if (type === 'MultiPoint') {
|
|
43
|
+
for (const p of coords) {
|
|
44
|
+
convertPoint(p, geometry);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (type === 'LineString') {
|
|
48
|
+
convertLine(coords, geometry, tolerance, false);
|
|
49
|
+
}
|
|
50
|
+
else if (type === 'MultiLineString') {
|
|
51
|
+
if (options.lineMetrics) {
|
|
52
|
+
// explode into linestrings to be able to track metrics
|
|
53
|
+
for (const line of coords) {
|
|
54
|
+
geometry = [];
|
|
55
|
+
convertLine(line, geometry, tolerance, false);
|
|
56
|
+
features.push(createFeature(id, 'LineString', geometry, geojson.properties));
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
convertLines(coords, geometry, tolerance, false);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (type === 'Polygon') {
|
|
65
|
+
convertLines(coords, geometry, tolerance, true);
|
|
66
|
+
}
|
|
67
|
+
else if (type === 'MultiPolygon') {
|
|
68
|
+
for (const polygon of coords) {
|
|
69
|
+
const newPolygon = [];
|
|
70
|
+
convertLines(polygon, newPolygon, tolerance, true);
|
|
71
|
+
geometry.push(newPolygon);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (type === 'GeometryCollection') {
|
|
75
|
+
for (const singleGeometry of geojson.geometry.geometries) {
|
|
76
|
+
convertFeature(features, {
|
|
77
|
+
id,
|
|
78
|
+
geometry: singleGeometry,
|
|
79
|
+
properties: geojson.properties
|
|
80
|
+
}, options, index);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
throw new Error('Input data is not a valid GeoJSON object.');
|
|
86
|
+
}
|
|
87
|
+
features.push(createFeature(id, type, geometry, geojson.properties));
|
|
72
88
|
}
|
|
73
89
|
function convertPoint(coords, out) {
|
|
74
|
-
|
|
90
|
+
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
75
91
|
}
|
|
76
92
|
function convertLine(ring, out, tolerance, isPolygon) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
let x0, y0;
|
|
94
|
+
let size = 0;
|
|
95
|
+
for (let j = 0; j < ring.length; j++) {
|
|
96
|
+
const x = projectX(ring[j][0]);
|
|
97
|
+
const y = projectY(ring[j][1]);
|
|
98
|
+
out.push(x, y, 0);
|
|
99
|
+
if (j > 0) {
|
|
100
|
+
if (isPolygon) {
|
|
101
|
+
size += (x0 * y - x * y0) / 2; // area
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
x0 = x;
|
|
108
|
+
y0 = y;
|
|
109
|
+
}
|
|
110
|
+
const last = out.length - 3;
|
|
111
|
+
out[2] = 1;
|
|
112
|
+
simplify(out, 0, last, tolerance);
|
|
113
|
+
out[last + 2] = 1;
|
|
114
|
+
out.size = Math.abs(size);
|
|
115
|
+
out.start = 0;
|
|
116
|
+
out.end = out.size;
|
|
100
117
|
}
|
|
101
118
|
function convertLines(rings, out, tolerance, isPolygon) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
119
|
+
for (let i = 0; i < rings.length; i++) {
|
|
120
|
+
const geom = [];
|
|
121
|
+
convertLine(rings[i], geom, tolerance, isPolygon);
|
|
122
|
+
out.push(geom);
|
|
123
|
+
}
|
|
107
124
|
}
|
|
108
125
|
function projectX(x) {
|
|
109
|
-
|
|
126
|
+
return x / 360 + 0.5;
|
|
110
127
|
}
|
|
111
128
|
function projectY(y) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
129
|
+
const sin = Math.sin((y * Math.PI) / 180);
|
|
130
|
+
const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
|
|
131
|
+
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
|
|
115
132
|
}
|
|
116
|
-
//# sourceMappingURL=convert.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/feature.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,kBAAkB,EAAC,
|
|
1
|
+
{"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/feature.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,kBAAkB,EAAC,kBAAe;AAE1C,wBAAgB,aAAa,CAAC,EAAE,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,GAAG,kBAAkB,CA8BtE"}
|