@loaders.gl/mvt 4.0.0-alpha.8 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.min.js +228 -24
- package/dist/es5/index.js +7 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/parse-mvt.js +8 -7
- package/dist/es5/lib/parse-mvt.js.map +1 -1
- package/dist/es5/lib/parse-tilejson.js +186 -0
- package/dist/es5/lib/parse-tilejson.js.map +1 -0
- package/dist/es5/lib/types.js.map +1 -1
- package/dist/es5/mvt-loader.js +10 -11
- package/dist/es5/mvt-loader.js.map +1 -1
- package/dist/es5/tilejson-loader.js +50 -0
- package/dist/es5/tilejson-loader.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/parse-mvt.js +8 -7
- package/dist/esm/lib/parse-mvt.js.map +1 -1
- package/dist/esm/lib/parse-tilejson.js +157 -0
- package/dist/esm/lib/parse-tilejson.js.map +1 -0
- package/dist/esm/lib/types.js.map +1 -1
- package/dist/esm/mvt-loader.js +10 -11
- package/dist/esm/mvt-loader.js.map +1 -1
- package/dist/esm/tilejson-loader.js +25 -0
- package/dist/esm/tilejson-loader.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/parse-mvt.d.ts +3 -3
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.d.ts +46 -0
- package/dist/lib/parse-tilejson.d.ts.map +1 -0
- package/dist/lib/types.d.ts +4 -4
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/mvt-loader.d.ts +5 -2
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-worker.js +40 -26
- package/dist/tilejson-loader.d.ts +10 -0
- package/dist/tilejson-loader.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/index.ts +5 -0
- package/src/lib/parse-mvt.ts +15 -11
- package/src/lib/parse-tilejson.ts +314 -0
- package/src/lib/types.ts +4 -4
- package/src/mvt-loader.ts +27 -13
- package/src/tilejson-loader.ts +39 -0
- 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,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
|
-
}
|
|
@@ -1,125 +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.createTile = void 0;
|
|
6
|
-
/**
|
|
7
|
-
* Create a tile from features and tile index
|
|
8
|
-
*/
|
|
9
|
-
function createTile(features, z, tx, ty, options) {
|
|
10
|
-
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
11
|
-
const tile = {
|
|
12
|
-
features: [],
|
|
13
|
-
numPoints: 0,
|
|
14
|
-
numSimplified: 0,
|
|
15
|
-
numFeatures: features.length,
|
|
16
|
-
source: null,
|
|
17
|
-
x: tx,
|
|
18
|
-
y: ty,
|
|
19
|
-
z,
|
|
20
|
-
transformed: false,
|
|
21
|
-
minX: 2,
|
|
22
|
-
minY: 1,
|
|
23
|
-
maxX: -1,
|
|
24
|
-
maxY: 0
|
|
25
|
-
};
|
|
26
|
-
for (const feature of features) {
|
|
27
|
-
addFeature(tile, feature, tolerance, options);
|
|
28
|
-
}
|
|
29
|
-
return tile;
|
|
30
|
-
}
|
|
31
|
-
exports.createTile = createTile;
|
|
32
|
-
// eslint-disable-next-line complexity, max-statements
|
|
33
|
-
function addFeature(tile, feature, tolerance, options) {
|
|
34
|
-
const geom = feature.geometry;
|
|
35
|
-
const type = feature.type;
|
|
36
|
-
const simplified = [];
|
|
37
|
-
tile.minX = Math.min(tile.minX, feature.minX);
|
|
38
|
-
tile.minY = Math.min(tile.minY, feature.minY);
|
|
39
|
-
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
40
|
-
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
41
|
-
if (type === 'Point' || type === 'MultiPoint') {
|
|
42
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
43
|
-
simplified.push(geom[i], geom[i + 1]);
|
|
44
|
-
tile.numPoints++;
|
|
45
|
-
tile.numSimplified++;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else if (type === 'LineString') {
|
|
49
|
-
addLine(simplified, geom, tile, tolerance, false, false);
|
|
50
|
-
}
|
|
51
|
-
else if (type === 'MultiLineString' || type === 'Polygon') {
|
|
52
|
-
for (let i = 0; i < geom.length; i++) {
|
|
53
|
-
addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else if (type === 'MultiPolygon') {
|
|
57
|
-
for (let k = 0; k < geom.length; k++) {
|
|
58
|
-
const polygon = geom[k];
|
|
59
|
-
for (let i = 0; i < polygon.length; i++) {
|
|
60
|
-
addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (simplified.length) {
|
|
65
|
-
let tags = feature.tags || null;
|
|
66
|
-
if (type === 'LineString' && options.lineMetrics) {
|
|
67
|
-
tags = {};
|
|
68
|
-
for (const key in feature.tags)
|
|
69
|
-
tags[key] = feature.tags[key];
|
|
70
|
-
// eslint-disable-next-line camelcase
|
|
71
|
-
tags.mapbox_clip_start = geom.start / geom.size;
|
|
72
|
-
// eslint-disable-next-line camelcase
|
|
73
|
-
tags.mapbox_clip_end = geom.end / geom.size;
|
|
74
|
-
}
|
|
75
|
-
// @ts-expect-error TODO - create sub type?
|
|
76
|
-
const tileFeature = {
|
|
77
|
-
geometry: simplified,
|
|
78
|
-
type: type === 'Polygon' || type === 'MultiPolygon'
|
|
79
|
-
? 3
|
|
80
|
-
: type === 'LineString' || type === 'MultiLineString'
|
|
81
|
-
? 2
|
|
82
|
-
: 1,
|
|
83
|
-
tags
|
|
84
|
-
};
|
|
85
|
-
if (feature.id !== null) {
|
|
86
|
-
tileFeature.id = feature.id;
|
|
87
|
-
}
|
|
88
|
-
tile.features.push(tileFeature);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// eslint-disable-next-line max-params, max-statements
|
|
92
|
-
function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
|
|
93
|
-
const sqTolerance = tolerance * tolerance;
|
|
94
|
-
if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
95
|
-
tile.numPoints += geom.length / 3;
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const ring = [];
|
|
99
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
100
|
-
if (tolerance === 0 || geom[i + 2] > sqTolerance) {
|
|
101
|
-
tile.numSimplified++;
|
|
102
|
-
ring.push(geom[i], geom[i + 1]);
|
|
103
|
-
}
|
|
104
|
-
tile.numPoints++;
|
|
105
|
-
}
|
|
106
|
-
if (isPolygon)
|
|
107
|
-
rewind(ring, isOuter);
|
|
108
|
-
result.push(ring);
|
|
109
|
-
}
|
|
110
|
-
function rewind(ring, clockwise) {
|
|
111
|
-
let area = 0;
|
|
112
|
-
for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
|
|
113
|
-
area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
|
|
114
|
-
}
|
|
115
|
-
if (area > 0 === clockwise) {
|
|
116
|
-
for (let i = 0, len = ring.length; i < len / 2; i += 2) {
|
|
117
|
-
const x = ring[i];
|
|
118
|
-
const y = ring[i + 1];
|
|
119
|
-
ring[i] = ring[len - 2 - i];
|
|
120
|
-
ring[i + 1] = ring[len - 1 - i];
|
|
121
|
-
ring[len - 2 - i] = x;
|
|
122
|
-
ring[len - 1 - i] = y;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,43 +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.transformTile = void 0;
|
|
6
|
-
/**
|
|
7
|
-
* Transforms the coordinates of each feature in the given tile from
|
|
8
|
-
* mercator-projected space into (extent x extent) tile space.
|
|
9
|
-
*/
|
|
10
|
-
function transformTile(tile, extent) {
|
|
11
|
-
if (tile.transformed) {
|
|
12
|
-
return tile;
|
|
13
|
-
}
|
|
14
|
-
const z2 = 1 << tile.z;
|
|
15
|
-
const tx = tile.x;
|
|
16
|
-
const ty = tile.y;
|
|
17
|
-
for (const feature of tile.features) {
|
|
18
|
-
const geom = feature.geometry;
|
|
19
|
-
const type = feature.type;
|
|
20
|
-
feature.geometry = [];
|
|
21
|
-
if (type === 1) {
|
|
22
|
-
for (let j = 0; j < geom.length; j += 2) {
|
|
23
|
-
feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
for (let j = 0; j < geom.length; j++) {
|
|
28
|
-
const ring = [];
|
|
29
|
-
for (let k = 0; k < geom[j].length; k += 2) {
|
|
30
|
-
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
|
|
31
|
-
}
|
|
32
|
-
feature.geometry.push(ring);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
tile.transformed = true;
|
|
37
|
-
return tile;
|
|
38
|
-
}
|
|
39
|
-
exports.transformTile = transformTile;
|
|
40
|
-
// eslint-disable-next-line max-params
|
|
41
|
-
function transformPoint(x, y, extent, z2, tx, ty) {
|
|
42
|
-
return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
|
|
43
|
-
}
|