@loaders.gl/mvt 3.4.11 → 3.4.13
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/es5/mvt-loader.js +1 -1
- package/dist/esm/mvt-loader.js +1 -1
- package/dist/mvt-worker.js +1 -1
- package/package.json +5 -5
- package/dist/bundle.js +0 -5
- package/dist/helpers/binary-util-functions.js +0 -118
- package/dist/helpers/mapbox-util-functions.js +0 -82
- package/dist/index.js +0 -9
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +0 -156
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +0 -91
- package/dist/lib/binary-vector-tile/vector-tile.js +0 -29
- package/dist/lib/geojson-tiler/clip.js +0 -209
- package/dist/lib/geojson-tiler/convert.js +0 -134
- package/dist/lib/geojson-tiler/feature.js +0 -46
- package/dist/lib/geojson-tiler/geojson-tiler.js +0 -210
- package/dist/lib/geojson-tiler/simplify.js +0 -68
- package/dist/lib/geojson-tiler/tile.js +0 -125
- package/dist/lib/geojson-tiler/transform.js +0 -43
- package/dist/lib/geojson-tiler/wrap.js +0 -86
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +0 -170
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +0 -89
- package/dist/lib/mapbox-vector-tile/vector-tile.js +0 -29
- package/dist/lib/parse-mvt.js +0 -167
- package/dist/lib/types.js +0 -2
- package/dist/mvt-loader.js +0 -47
- package/dist/workers/mvt-worker.js +0 -5
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.clip = void 0;
|
|
6
|
-
const feature_1 = require("./feature");
|
|
7
|
-
/* eslint-disable no-continue */
|
|
8
|
-
/**
|
|
9
|
-
* Clip features between two vertical or horizontal axis-parallel lines:
|
|
10
|
-
* | |
|
|
11
|
-
* ___|___ | /
|
|
12
|
-
* / | \____|____/
|
|
13
|
-
* | |
|
|
14
|
-
*
|
|
15
|
-
* @param k1 and k2 are the line coordinates
|
|
16
|
-
* @param axis: 0 for x, 1 for y
|
|
17
|
-
* @param minAll and maxAll: minimum and maximum coordinate value for all features
|
|
18
|
-
*/
|
|
19
|
-
// eslint-disable-next-line max-params, complexity, max-statements
|
|
20
|
-
function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
21
|
-
k1 /= scale;
|
|
22
|
-
k2 /= scale;
|
|
23
|
-
if (minAll >= k1 && maxAll < k2) {
|
|
24
|
-
return features;
|
|
25
|
-
}
|
|
26
|
-
// trivial accept
|
|
27
|
-
else if (maxAll < k1 || minAll >= k2) {
|
|
28
|
-
return null; // trivial reject
|
|
29
|
-
}
|
|
30
|
-
const clipped = [];
|
|
31
|
-
for (const feature of features) {
|
|
32
|
-
const geometry = feature.geometry;
|
|
33
|
-
let type = feature.type;
|
|
34
|
-
const min = axis === 0 ? feature.minX : feature.minY;
|
|
35
|
-
const max = axis === 0 ? feature.maxX : feature.maxY;
|
|
36
|
-
if (min >= k1 && max < k2) {
|
|
37
|
-
// trivial accept
|
|
38
|
-
clipped.push(feature);
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
else if (max < k1 || min >= k2) {
|
|
42
|
-
// trivial reject
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
let newGeometry = [];
|
|
46
|
-
if (type === 'Point' || type === 'MultiPoint') {
|
|
47
|
-
clipPoints(geometry, newGeometry, k1, k2, axis);
|
|
48
|
-
}
|
|
49
|
-
else if (type === 'LineString') {
|
|
50
|
-
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
|
|
51
|
-
}
|
|
52
|
-
else if (type === 'MultiLineString') {
|
|
53
|
-
clipLines(geometry, newGeometry, k1, k2, axis, false);
|
|
54
|
-
}
|
|
55
|
-
else if (type === 'Polygon') {
|
|
56
|
-
clipLines(geometry, newGeometry, k1, k2, axis, true);
|
|
57
|
-
}
|
|
58
|
-
else if (type === 'MultiPolygon') {
|
|
59
|
-
for (const polygon of geometry) {
|
|
60
|
-
const newPolygon = [];
|
|
61
|
-
clipLines(polygon, newPolygon, k1, k2, axis, true);
|
|
62
|
-
if (newPolygon.length) {
|
|
63
|
-
newGeometry.push(newPolygon);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (newGeometry.length) {
|
|
68
|
-
if (options.lineMetrics && type === 'LineString') {
|
|
69
|
-
for (const line of newGeometry) {
|
|
70
|
-
clipped.push((0, feature_1.createFeature)(feature.id, type, line, feature.tags));
|
|
71
|
-
}
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (type === 'LineString' || type === 'MultiLineString') {
|
|
75
|
-
if (newGeometry.length === 1) {
|
|
76
|
-
type = 'LineString';
|
|
77
|
-
// @ts-expect-error TODO - use proper GeoJSON geometry types
|
|
78
|
-
newGeometry = newGeometry[0];
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
type = 'MultiLineString';
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (type === 'Point' || type === 'MultiPoint') {
|
|
85
|
-
type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
|
|
86
|
-
}
|
|
87
|
-
clipped.push((0, feature_1.createFeature)(feature.id, type, newGeometry, feature.tags));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return clipped.length ? clipped : null;
|
|
91
|
-
}
|
|
92
|
-
exports.clip = clip;
|
|
93
|
-
function clipPoints(geom, newGeom, k1, k2, axis) {
|
|
94
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
95
|
-
const a = geom[i + axis];
|
|
96
|
-
if (a >= k1 && a <= k2) {
|
|
97
|
-
addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
// eslint-disable-next-line max-params, complexity, max-statements
|
|
102
|
-
function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
|
|
103
|
-
let slice = newSlice(geom);
|
|
104
|
-
const intersect = axis === 0 ? intersectX : intersectY;
|
|
105
|
-
let len = geom.start;
|
|
106
|
-
let segLen;
|
|
107
|
-
let t;
|
|
108
|
-
for (let i = 0; i < geom.length - 3; i += 3) {
|
|
109
|
-
const ax = geom[i];
|
|
110
|
-
const ay = geom[i + 1];
|
|
111
|
-
const az = geom[i + 2];
|
|
112
|
-
const bx = geom[i + 3];
|
|
113
|
-
const by = geom[i + 4];
|
|
114
|
-
const a = axis === 0 ? ax : ay;
|
|
115
|
-
const b = axis === 0 ? bx : by;
|
|
116
|
-
let exited = false;
|
|
117
|
-
if (trackMetrics) {
|
|
118
|
-
segLen = Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2));
|
|
119
|
-
}
|
|
120
|
-
if (a < k1) {
|
|
121
|
-
// ---|--> | (line enters the clip region from the left)
|
|
122
|
-
if (b > k1) {
|
|
123
|
-
t = intersect(slice, ax, ay, bx, by, k1);
|
|
124
|
-
if (trackMetrics) {
|
|
125
|
-
slice.start = len + segLen * t;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else if (a > k2) {
|
|
130
|
-
// | <--|--- (line enters the clip region from the right)
|
|
131
|
-
if (b < k2) {
|
|
132
|
-
t = intersect(slice, ax, ay, bx, by, k2);
|
|
133
|
-
if (trackMetrics) {
|
|
134
|
-
slice.start = len + segLen * t;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
addPoint(slice, ax, ay, az);
|
|
140
|
-
}
|
|
141
|
-
if (b < k1 && a >= k1) {
|
|
142
|
-
// <--|--- | or <--|-----|--- (line exits the clip region on the left)
|
|
143
|
-
t = intersect(slice, ax, ay, bx, by, k1);
|
|
144
|
-
exited = true;
|
|
145
|
-
}
|
|
146
|
-
if (b > k2 && a <= k2) {
|
|
147
|
-
// | ---|--> or ---|-----|--> (line exits the clip region on the right)
|
|
148
|
-
t = intersect(slice, ax, ay, bx, by, k2);
|
|
149
|
-
exited = true;
|
|
150
|
-
}
|
|
151
|
-
if (!isPolygon && exited) {
|
|
152
|
-
if (trackMetrics) {
|
|
153
|
-
slice.end = len + segLen * t;
|
|
154
|
-
}
|
|
155
|
-
newGeom.push(slice);
|
|
156
|
-
slice = newSlice(geom);
|
|
157
|
-
}
|
|
158
|
-
if (trackMetrics) {
|
|
159
|
-
len += segLen;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
// add the last point
|
|
163
|
-
let last = geom.length - 3;
|
|
164
|
-
const ax = geom[last];
|
|
165
|
-
const ay = geom[last + 1];
|
|
166
|
-
const az = geom[last + 2];
|
|
167
|
-
const a = axis === 0 ? ax : ay;
|
|
168
|
-
if (a >= k1 && a <= k2)
|
|
169
|
-
addPoint(slice, ax, ay, az);
|
|
170
|
-
// close the polygon if its endpoints are not the same after clipping
|
|
171
|
-
last = slice.length - 3;
|
|
172
|
-
if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
|
|
173
|
-
addPoint(slice, slice[0], slice[1], slice[2]);
|
|
174
|
-
}
|
|
175
|
-
// add the final slice
|
|
176
|
-
if (slice.length) {
|
|
177
|
-
newGeom.push(slice);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
class Slice extends Array {
|
|
181
|
-
}
|
|
182
|
-
function newSlice(line) {
|
|
183
|
-
const slice = [];
|
|
184
|
-
slice.size = line.size;
|
|
185
|
-
slice.start = line.start;
|
|
186
|
-
slice.end = line.end;
|
|
187
|
-
return slice;
|
|
188
|
-
}
|
|
189
|
-
// eslint-disable-next-line max-params
|
|
190
|
-
function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
|
|
191
|
-
for (const line of geom) {
|
|
192
|
-
clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
function addPoint(out, x, y, z) {
|
|
196
|
-
out.push(x, y, z);
|
|
197
|
-
}
|
|
198
|
-
// eslint-disable-next-line max-params
|
|
199
|
-
function intersectX(out, ax, ay, bx, by, x) {
|
|
200
|
-
const t = (x - ax) / (bx - ax);
|
|
201
|
-
addPoint(out, x, ay + (by - ay) * t, 1);
|
|
202
|
-
return t;
|
|
203
|
-
}
|
|
204
|
-
// eslint-disable-next-line max-params
|
|
205
|
-
function intersectY(out, ax, ay, bx, by, y) {
|
|
206
|
-
const t = (y - ay) / (by - ay);
|
|
207
|
-
addPoint(out, ax + (bx - ax) * t, y, 1);
|
|
208
|
-
return t;
|
|
209
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.convert = void 0;
|
|
6
|
-
const simplify_1 = require("./simplify");
|
|
7
|
-
const feature_1 = require("./feature");
|
|
8
|
-
// converts GeoJSON feature into an intermediate projected JSON vector format with simplification data
|
|
9
|
-
function convert(data, options) {
|
|
10
|
-
const features = [];
|
|
11
|
-
if (data.type === 'FeatureCollection') {
|
|
12
|
-
for (let i = 0; i < data.features.length; i++) {
|
|
13
|
-
convertFeature(features, data.features[i], options, i);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
else if (data.type === 'Feature') {
|
|
17
|
-
convertFeature(features, data, options);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
// single geometry or a geometry collection
|
|
21
|
-
convertFeature(features, { geometry: data }, options);
|
|
22
|
-
}
|
|
23
|
-
return features;
|
|
24
|
-
}
|
|
25
|
-
exports.convert = convert;
|
|
26
|
-
function convertFeature(features, geojson, options, index) {
|
|
27
|
-
if (!geojson.geometry) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const coords = geojson.geometry.coordinates;
|
|
31
|
-
const type = geojson.geometry.type;
|
|
32
|
-
const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
|
|
33
|
-
let geometry = [];
|
|
34
|
-
let id = geojson.id;
|
|
35
|
-
if (options.promoteId) {
|
|
36
|
-
id = geojson.properties[options.promoteId];
|
|
37
|
-
}
|
|
38
|
-
else if (options.generateId) {
|
|
39
|
-
id = index || 0;
|
|
40
|
-
}
|
|
41
|
-
if (type === 'Point') {
|
|
42
|
-
convertPoint(coords, geometry);
|
|
43
|
-
}
|
|
44
|
-
else if (type === 'MultiPoint') {
|
|
45
|
-
for (const p of coords) {
|
|
46
|
-
convertPoint(p, geometry);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
else if (type === 'LineString') {
|
|
50
|
-
convertLine(coords, geometry, tolerance, false);
|
|
51
|
-
}
|
|
52
|
-
else if (type === 'MultiLineString') {
|
|
53
|
-
if (options.lineMetrics) {
|
|
54
|
-
// explode into linestrings to be able to track metrics
|
|
55
|
-
for (const line of coords) {
|
|
56
|
-
geometry = [];
|
|
57
|
-
convertLine(line, geometry, tolerance, false);
|
|
58
|
-
features.push((0, feature_1.createFeature)(id, 'LineString', geometry, geojson.properties));
|
|
59
|
-
}
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
convertLines(coords, geometry, tolerance, false);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else if (type === 'Polygon') {
|
|
67
|
-
convertLines(coords, geometry, tolerance, true);
|
|
68
|
-
}
|
|
69
|
-
else if (type === 'MultiPolygon') {
|
|
70
|
-
for (const polygon of coords) {
|
|
71
|
-
const newPolygon = [];
|
|
72
|
-
convertLines(polygon, newPolygon, tolerance, true);
|
|
73
|
-
geometry.push(newPolygon);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else if (type === 'GeometryCollection') {
|
|
77
|
-
for (const singleGeometry of geojson.geometry.geometries) {
|
|
78
|
-
convertFeature(features, {
|
|
79
|
-
id,
|
|
80
|
-
geometry: singleGeometry,
|
|
81
|
-
properties: geojson.properties
|
|
82
|
-
}, options, index);
|
|
83
|
-
}
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
throw new Error('Input data is not a valid GeoJSON object.');
|
|
88
|
-
}
|
|
89
|
-
features.push((0, feature_1.createFeature)(id, type, geometry, geojson.properties));
|
|
90
|
-
}
|
|
91
|
-
function convertPoint(coords, out) {
|
|
92
|
-
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
93
|
-
}
|
|
94
|
-
function convertLine(ring, out, tolerance, isPolygon) {
|
|
95
|
-
let x0, y0;
|
|
96
|
-
let size = 0;
|
|
97
|
-
for (let j = 0; j < ring.length; j++) {
|
|
98
|
-
const x = projectX(ring[j][0]);
|
|
99
|
-
const y = projectY(ring[j][1]);
|
|
100
|
-
out.push(x, y, 0);
|
|
101
|
-
if (j > 0) {
|
|
102
|
-
if (isPolygon) {
|
|
103
|
-
size += (x0 * y - x * y0) / 2; // area
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
x0 = x;
|
|
110
|
-
y0 = y;
|
|
111
|
-
}
|
|
112
|
-
const last = out.length - 3;
|
|
113
|
-
out[2] = 1;
|
|
114
|
-
(0, simplify_1.simplify)(out, 0, last, tolerance);
|
|
115
|
-
out[last + 2] = 1;
|
|
116
|
-
out.size = Math.abs(size);
|
|
117
|
-
out.start = 0;
|
|
118
|
-
out.end = out.size;
|
|
119
|
-
}
|
|
120
|
-
function convertLines(rings, out, tolerance, isPolygon) {
|
|
121
|
-
for (let i = 0; i < rings.length; i++) {
|
|
122
|
-
const geom = [];
|
|
123
|
-
convertLine(rings[i], geom, tolerance, isPolygon);
|
|
124
|
-
out.push(geom);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function projectX(x) {
|
|
128
|
-
return x / 360 + 0.5;
|
|
129
|
-
}
|
|
130
|
-
function projectY(y) {
|
|
131
|
-
const sin = Math.sin((y * Math.PI) / 180);
|
|
132
|
-
const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
|
|
133
|
-
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
|
|
134
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.createFeature = void 0;
|
|
6
|
-
function createFeature(id, type, geom, tags) {
|
|
7
|
-
const feature = {
|
|
8
|
-
// eslint-disable-next-line
|
|
9
|
-
id: id == null ? null : id,
|
|
10
|
-
type,
|
|
11
|
-
geometry: geom,
|
|
12
|
-
tags,
|
|
13
|
-
minX: Infinity,
|
|
14
|
-
minY: Infinity,
|
|
15
|
-
maxX: -Infinity,
|
|
16
|
-
maxY: -Infinity
|
|
17
|
-
};
|
|
18
|
-
if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
|
|
19
|
-
calcLineBBox(feature, geom);
|
|
20
|
-
}
|
|
21
|
-
else if (type === 'Polygon') {
|
|
22
|
-
// the outer ring (ie [0]) contains all inner rings
|
|
23
|
-
calcLineBBox(feature, geom[0]);
|
|
24
|
-
}
|
|
25
|
-
else if (type === 'MultiLineString') {
|
|
26
|
-
for (const line of geom) {
|
|
27
|
-
calcLineBBox(feature, line);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else if (type === 'MultiPolygon') {
|
|
31
|
-
for (const polygon of geom) {
|
|
32
|
-
// the outer ring (ie [0]) contains all inner rings
|
|
33
|
-
calcLineBBox(feature, polygon[0]);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return feature;
|
|
37
|
-
}
|
|
38
|
-
exports.createFeature = createFeature;
|
|
39
|
-
function calcLineBBox(feature, geom) {
|
|
40
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
41
|
-
feature.minX = Math.min(feature.minX, geom[i]);
|
|
42
|
-
feature.minY = Math.min(feature.minY, geom[i + 1]);
|
|
43
|
-
feature.maxX = Math.max(feature.maxX, geom[i]);
|
|
44
|
-
feature.maxY = Math.max(feature.maxY, geom[i + 1]);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.GeoJSONTiler = void 0;
|
|
6
|
-
const convert_1 = require("./convert"); // GeoJSON conversion and preprocessing
|
|
7
|
-
const clip_1 = require("./clip"); // stripe clipping algorithm
|
|
8
|
-
const wrap_1 = require("./wrap"); // date line processing
|
|
9
|
-
const transform_1 = require("./transform"); // coordinate transformation
|
|
10
|
-
const tile_1 = require("./tile"); // final simplified tile generation
|
|
11
|
-
const DEFAULT_OPTIONS = {
|
|
12
|
-
maxZoom: 14,
|
|
13
|
-
indexMaxZoom: 5,
|
|
14
|
-
indexMaxPoints: 100000,
|
|
15
|
-
tolerance: 3,
|
|
16
|
-
extent: 4096,
|
|
17
|
-
buffer: 64,
|
|
18
|
-
lineMetrics: false,
|
|
19
|
-
// @ts-expect-error Ensures all these required params have defaults
|
|
20
|
-
promoteId: undefined,
|
|
21
|
-
generateId: false,
|
|
22
|
-
debug: 0 // logging level (0, 1 or 2)
|
|
23
|
-
};
|
|
24
|
-
class GeoJSONTiler {
|
|
25
|
-
constructor(data, options) {
|
|
26
|
-
// tiles and tileCoords are part of the public API
|
|
27
|
-
this.tiles = {};
|
|
28
|
-
this.tileCoords = [];
|
|
29
|
-
this.stats = {};
|
|
30
|
-
this.total = 0;
|
|
31
|
-
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
32
|
-
options = this.options;
|
|
33
|
-
const debug = options.debug;
|
|
34
|
-
if (debug)
|
|
35
|
-
console.time('preprocess data');
|
|
36
|
-
if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
|
|
37
|
-
throw new Error('maxZoom should be in the 0-24 range');
|
|
38
|
-
}
|
|
39
|
-
if (options.promoteId && this.options.generateId) {
|
|
40
|
-
throw new Error('promoteId and generateId cannot be used together.');
|
|
41
|
-
}
|
|
42
|
-
// projects and adds simplification info
|
|
43
|
-
let features = (0, convert_1.convert)(data, options);
|
|
44
|
-
if (debug) {
|
|
45
|
-
console.timeEnd('preprocess data');
|
|
46
|
-
console.log('index: maxZoom: %d, maxPoints: %d', options.indexMaxZoom, options.indexMaxPoints);
|
|
47
|
-
console.time('generate tiles');
|
|
48
|
-
}
|
|
49
|
-
// wraps features (ie extreme west and extreme east)
|
|
50
|
-
features = (0, wrap_1.wrap)(features, this.options);
|
|
51
|
-
// start slicing from the top tile down
|
|
52
|
-
if (features.length) {
|
|
53
|
-
this.splitTile(features, 0, 0, 0);
|
|
54
|
-
}
|
|
55
|
-
if (debug) {
|
|
56
|
-
if (features.length) {
|
|
57
|
-
console.log('features: %d, points: %d', this.tiles[0].numFeatures, this.tiles[0].numPoints);
|
|
58
|
-
}
|
|
59
|
-
console.timeEnd('generate tiles');
|
|
60
|
-
console.log('tiles generated:', this.total, JSON.stringify(this.stats));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Get a tile at the specified index
|
|
65
|
-
* @param z
|
|
66
|
-
* @param x
|
|
67
|
-
* @param y
|
|
68
|
-
* @returns
|
|
69
|
-
*/
|
|
70
|
-
// eslint-disable-next-line complexity, max-statements
|
|
71
|
-
getTile(z, x, y) {
|
|
72
|
-
// z = +z;
|
|
73
|
-
// x = +x;
|
|
74
|
-
// y = +y;
|
|
75
|
-
const { extent, debug } = this.options;
|
|
76
|
-
if (z < 0 || z > 24) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
const z2 = 1 << z;
|
|
80
|
-
x = (x + z2) & (z2 - 1); // wrap tile x coordinate
|
|
81
|
-
const id = toID(z, x, y);
|
|
82
|
-
if (this.tiles[id]) {
|
|
83
|
-
return (0, transform_1.transformTile)(this.tiles[id], extent);
|
|
84
|
-
}
|
|
85
|
-
if (debug > 1)
|
|
86
|
-
console.log('drilling down to z%d-%d-%d', z, x, y);
|
|
87
|
-
let z0 = z;
|
|
88
|
-
let x0 = x;
|
|
89
|
-
let y0 = y;
|
|
90
|
-
let parent;
|
|
91
|
-
while (!parent && z0 > 0) {
|
|
92
|
-
z0--;
|
|
93
|
-
x0 = x0 >> 1;
|
|
94
|
-
y0 = y0 >> 1;
|
|
95
|
-
parent = this.tiles[toID(z0, x0, y0)];
|
|
96
|
-
}
|
|
97
|
-
if (!parent || !parent.source) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
// if we found a parent tile containing the original geometry, we can drill down from it
|
|
101
|
-
if (debug > 1) {
|
|
102
|
-
console.log('found parent tile z%d-%d-%d', z0, x0, y0);
|
|
103
|
-
console.time('drilling down');
|
|
104
|
-
}
|
|
105
|
-
this.splitTile(parent.source, z0, x0, y0, z, x, y);
|
|
106
|
-
if (debug > 1) {
|
|
107
|
-
console.timeEnd('drilling down');
|
|
108
|
-
}
|
|
109
|
-
return this.tiles[id] ? (0, transform_1.transformTile)(this.tiles[id], extent) : null;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* splits features from a parent tile to sub-tiles.
|
|
113
|
-
* @param z, x, and y are the coordinates of the parent tile
|
|
114
|
-
* @param cz, cx, and cy are the coordinates of the target tile
|
|
115
|
-
*
|
|
116
|
-
* If no target tile is specified, splitting stops when we reach the maximum
|
|
117
|
-
* zoom or the number of points is low as specified in the options.
|
|
118
|
-
*/
|
|
119
|
-
// eslint-disable-next-line max-params, max-statements, complexity
|
|
120
|
-
splitTile(features, z, x, y, cz, cx, cy) {
|
|
121
|
-
const stack = [features, z, x, y];
|
|
122
|
-
const options = this.options;
|
|
123
|
-
const debug = options.debug;
|
|
124
|
-
// avoid recursion by using a processing queue
|
|
125
|
-
while (stack.length) {
|
|
126
|
-
y = stack.pop();
|
|
127
|
-
x = stack.pop();
|
|
128
|
-
z = stack.pop();
|
|
129
|
-
features = stack.pop();
|
|
130
|
-
const z2 = 1 << z;
|
|
131
|
-
const id = toID(z, x, y);
|
|
132
|
-
let tile = this.tiles[id];
|
|
133
|
-
if (!tile) {
|
|
134
|
-
if (debug > 1) {
|
|
135
|
-
console.time('creation');
|
|
136
|
-
}
|
|
137
|
-
tile = this.tiles[id] = (0, tile_1.createTile)(features, z, x, y, options);
|
|
138
|
-
this.tileCoords.push({ z, x, y });
|
|
139
|
-
if (debug) {
|
|
140
|
-
if (debug > 1) {
|
|
141
|
-
console.log('tile z%d-%d-%d (features: %d, points: %d, simplified: %d)', z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified);
|
|
142
|
-
console.timeEnd('creation');
|
|
143
|
-
}
|
|
144
|
-
const key = `z${z}`;
|
|
145
|
-
this.stats[key] = (this.stats[key] || 0) + 1;
|
|
146
|
-
this.total++;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
// save reference to original geometry in tile so that we can drill down later if we stop now
|
|
150
|
-
tile.source = features;
|
|
151
|
-
// if it's the first-pass tiling
|
|
152
|
-
if (cz === undefined) {
|
|
153
|
-
// stop tiling if we reached max zoom, or if the tile is too simple
|
|
154
|
-
if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
|
|
155
|
-
continue;
|
|
156
|
-
// if a drilldown to a specific tile
|
|
157
|
-
}
|
|
158
|
-
else if (z === options.maxZoom || z === cz) {
|
|
159
|
-
// stop tiling if we reached base zoom or our target tile zoom
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
else if (cz !== undefined) {
|
|
163
|
-
// stop tiling if it's not an ancestor of the target tile
|
|
164
|
-
const zoomSteps = cz - z;
|
|
165
|
-
// @ts-expect-error TODO fix the types of cx cy
|
|
166
|
-
if (x !== cx >> zoomSteps || y !== cy >> zoomSteps)
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
// if we slice further down, no need to keep source geometry
|
|
170
|
-
tile.source = null;
|
|
171
|
-
if (features.length === 0)
|
|
172
|
-
continue;
|
|
173
|
-
if (debug > 1)
|
|
174
|
-
console.time('clipping');
|
|
175
|
-
// values we'll use for clipping
|
|
176
|
-
const k1 = (0.5 * options.buffer) / options.extent;
|
|
177
|
-
const k2 = 0.5 - k1;
|
|
178
|
-
const k3 = 0.5 + k1;
|
|
179
|
-
const k4 = 1 + k1;
|
|
180
|
-
let tl = null;
|
|
181
|
-
let bl = null;
|
|
182
|
-
let tr = null;
|
|
183
|
-
let br = null;
|
|
184
|
-
let left = (0, clip_1.clip)(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, options);
|
|
185
|
-
let right = (0, clip_1.clip)(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, options);
|
|
186
|
-
// @ts-expect-error - unclear why this is needed?
|
|
187
|
-
features = null;
|
|
188
|
-
if (left) {
|
|
189
|
-
tl = (0, clip_1.clip)(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
|
|
190
|
-
bl = (0, clip_1.clip)(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
|
|
191
|
-
left = null;
|
|
192
|
-
}
|
|
193
|
-
if (right) {
|
|
194
|
-
tr = (0, clip_1.clip)(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
|
|
195
|
-
br = (0, clip_1.clip)(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
|
|
196
|
-
right = null;
|
|
197
|
-
}
|
|
198
|
-
if (debug > 1)
|
|
199
|
-
console.timeEnd('clipping');
|
|
200
|
-
stack.push(tl || [], z + 1, x * 2, y * 2);
|
|
201
|
-
stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
|
|
202
|
-
stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
|
|
203
|
-
stack.push(br || [], z + 1, x * 2 + 1, y * 2 + 1);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
exports.GeoJSONTiler = GeoJSONTiler;
|
|
208
|
-
function toID(z, x, y) {
|
|
209
|
-
return ((1 << z) * y + x) * 32 + z;
|
|
210
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.simplify = void 0;
|
|
6
|
-
/**
|
|
7
|
-
* Calculate simplification data using optimized Douglas-Peucker algorithm
|
|
8
|
-
*
|
|
9
|
-
* @param coords contiguous list of coordinates
|
|
10
|
-
* @param first first coord to simplify
|
|
11
|
-
* @param last last coord to simplify
|
|
12
|
-
* @param sqTolerance tolerance (square distance)
|
|
13
|
-
*/
|
|
14
|
-
function simplify(coords, first, last, sqTolerance) {
|
|
15
|
-
let maxSqDist = sqTolerance;
|
|
16
|
-
const mid = (last - first) >> 1;
|
|
17
|
-
let minPosToMid = last - first;
|
|
18
|
-
let index;
|
|
19
|
-
const ax = coords[first];
|
|
20
|
-
const ay = coords[first + 1];
|
|
21
|
-
const bx = coords[last];
|
|
22
|
-
const by = coords[last + 1];
|
|
23
|
-
for (let i = first + 3; i < last; i += 3) {
|
|
24
|
-
const d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);
|
|
25
|
-
if (d > maxSqDist) {
|
|
26
|
-
index = i;
|
|
27
|
-
maxSqDist = d;
|
|
28
|
-
}
|
|
29
|
-
else if (d === maxSqDist) {
|
|
30
|
-
// a workaround to ensure we choose a pivot close to the middle of the list,
|
|
31
|
-
// reducing recursion depth, for certain degenerate inputs
|
|
32
|
-
// https://github.com/mapbox/geojson-vt/issues/104
|
|
33
|
-
const posToMid = Math.abs(i - mid);
|
|
34
|
-
if (posToMid < minPosToMid) {
|
|
35
|
-
index = i;
|
|
36
|
-
minPosToMid = posToMid;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (maxSqDist > sqTolerance) {
|
|
41
|
-
if (index - first > 3)
|
|
42
|
-
simplify(coords, first, index, sqTolerance);
|
|
43
|
-
coords[index + 2] = maxSqDist;
|
|
44
|
-
if (last - index > 3)
|
|
45
|
-
simplify(coords, index, last, sqTolerance);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.simplify = simplify;
|
|
49
|
-
/** square distance from a point to a segment */
|
|
50
|
-
// eslint-disable-next-line max-params
|
|
51
|
-
function getSqSegDist(px, py, x, y, bx, by) {
|
|
52
|
-
let dx = bx - x;
|
|
53
|
-
let dy = by - y;
|
|
54
|
-
if (dx !== 0 || dy !== 0) {
|
|
55
|
-
const t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);
|
|
56
|
-
if (t > 1) {
|
|
57
|
-
x = bx;
|
|
58
|
-
y = by;
|
|
59
|
-
}
|
|
60
|
-
else if (t > 0) {
|
|
61
|
-
x += dx * t;
|
|
62
|
-
y += dy * t;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
dx = px - x;
|
|
66
|
-
dy = py - y;
|
|
67
|
-
return dx * dx + dy * dy;
|
|
68
|
-
}
|