@loaders.gl/mvt 3.3.0-alpha.7 → 3.3.0-alpha.8
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 +766 -0
- package/dist/es5/index.js +7 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
- package/dist/es5/lib/geojson-tiler/clip.js +247 -0
- package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/convert.js +163 -0
- package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/feature.js +63 -0
- package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js +203 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/simplify.js +54 -0
- package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/tile.js +127 -0
- package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/transform.js +52 -0
- package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/wrap.js +127 -0
- package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/es5/mvt-loader.js +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
- package/dist/esm/lib/geojson-tiler/clip.js +184 -0
- package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/convert.js +120 -0
- package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/feature.js +37 -0
- package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js +189 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/simplify.js +49 -0
- package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/tile.js +108 -0
- package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/transform.js +35 -0
- package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/wrap.js +75 -0
- package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/esm/mvt-loader.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/lib/geojson-tiler/clip.d.ts +16 -0
- package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/clip.js +209 -0
- package/dist/lib/geojson-tiler/convert.d.ts +10 -0
- package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/convert.js +134 -0
- package/dist/lib/geojson-tiler/feature.d.ts +3 -0
- package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/feature.js +46 -0
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
- package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
- package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/simplify.js +68 -0
- package/dist/lib/geojson-tiler/tile.d.ts +38 -0
- package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/tile.js +125 -0
- package/dist/lib/geojson-tiler/transform.d.ts +7 -0
- package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/transform.js +43 -0
- package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
- package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
- package/dist/lib/geojson-tiler/wrap.js +86 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +3 -3
- package/dist/lib/types.d.ts +6 -6
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/mvt-worker.js +1 -1
- package/package.json +5 -5
- package/src/index.ts +7 -0
- package/src/lib/geojson-tiler/LICENSE +19 -0
- package/src/lib/geojson-tiler/clip.ts +248 -0
- package/src/lib/geojson-tiler/convert.ts +158 -0
- package/src/lib/geojson-tiler/feature.ts +45 -0
- package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
- package/src/lib/geojson-tiler/simplify.ts +77 -0
- package/src/lib/geojson-tiler/tile.ts +185 -0
- package/src/lib/geojson-tiler/transform.ts +55 -0
- package/src/lib/geojson-tiler/wrap.ts +108 -0
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GeoJSONTile } from './tile';
|
|
2
|
+
/**
|
|
3
|
+
* Transforms the coordinates of each feature in the given tile from
|
|
4
|
+
* mercator-projected space into (extent x extent) tile space.
|
|
5
|
+
*/
|
|
6
|
+
export declare function transformTile(tile: GeoJSONTile, extent: number): GeoJSONTile;
|
|
7
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/transform.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,QAAQ,CAAC;AAExC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAiC5E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GeoJSONTileFeature } from './tile';
|
|
2
|
+
/**
|
|
3
|
+
* Options for wrap()
|
|
4
|
+
*/
|
|
5
|
+
export type WrapOptions = {
|
|
6
|
+
buffer: number /** number of pixels of buffer for the tile */;
|
|
7
|
+
extent: number /** extent of each tile */;
|
|
8
|
+
lineMetrics: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Wrap across antemeridian, by clipping into two tiles, shifting the overflowing x coordinates
|
|
12
|
+
* @param features list of features to be wrapped
|
|
13
|
+
* @param options buffer and extent
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function wrap(features: GeoJSONTileFeature[], options: WrapOptions): GeoJSONTileFeature[];
|
|
17
|
+
//# sourceMappingURL=wrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../../src/lib/geojson-tiler/wrap.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,QAAQ,CAAC;AAI/C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC,8CAA8C,CAAC;IAC9D,MAAM,EAAE,MAAM,CAAC,0BAA0B,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,WAAW,wBAkBxE"}
|
|
@@ -0,0 +1,86 @@
|
|
|
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.wrap = void 0;
|
|
6
|
+
const clip_1 = require("./clip");
|
|
7
|
+
const feature_1 = require("./feature");
|
|
8
|
+
/**
|
|
9
|
+
* Wrap across antemeridian, by clipping into two tiles, shifting the overflowing x coordinates
|
|
10
|
+
* @param features list of features to be wrapped
|
|
11
|
+
* @param options buffer and extent
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
function wrap(features, options) {
|
|
15
|
+
const buffer = options.buffer / options.extent;
|
|
16
|
+
let merged = features;
|
|
17
|
+
const left = (0, clip_1.clip)(features, 1, -1 - buffer, buffer, 0, -1, 2, options); // left world copy
|
|
18
|
+
const right = (0, clip_1.clip)(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options); // right world copy
|
|
19
|
+
if (left || right) {
|
|
20
|
+
merged = (0, clip_1.clip)(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || []; // center world copy
|
|
21
|
+
if (left) {
|
|
22
|
+
merged = shiftFeatureCoords(left, 1).concat(merged); // merge left into center
|
|
23
|
+
}
|
|
24
|
+
if (right) {
|
|
25
|
+
merged = merged.concat(shiftFeatureCoords(right, -1)); // merge right into center
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return merged;
|
|
29
|
+
}
|
|
30
|
+
exports.wrap = wrap;
|
|
31
|
+
/**
|
|
32
|
+
* Shift the x coordinates of a list of features
|
|
33
|
+
* @param features list of features to shift x coordinates for
|
|
34
|
+
* @param offset
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
function shiftFeatureCoords(features, offset) {
|
|
38
|
+
const newFeatures = [];
|
|
39
|
+
for (let i = 0; i < features.length; i++) {
|
|
40
|
+
const feature = features[i];
|
|
41
|
+
const type = feature.type;
|
|
42
|
+
let newGeometry;
|
|
43
|
+
if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
|
|
44
|
+
newGeometry = shiftCoords(feature.geometry, offset);
|
|
45
|
+
}
|
|
46
|
+
else if (type === 'MultiLineString' || type === 'Polygon') {
|
|
47
|
+
newGeometry = [];
|
|
48
|
+
for (const line of feature.geometry) {
|
|
49
|
+
newGeometry.push(shiftCoords(line, offset));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (type === 'MultiPolygon') {
|
|
53
|
+
newGeometry = [];
|
|
54
|
+
for (const polygon of feature.geometry) {
|
|
55
|
+
const newPolygon = [];
|
|
56
|
+
for (const line of polygon) {
|
|
57
|
+
// @ts-expect-error TODO
|
|
58
|
+
newPolygon.push(shiftCoords(line, offset));
|
|
59
|
+
}
|
|
60
|
+
newGeometry.push(newPolygon);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
newFeatures.push((0, feature_1.createFeature)(feature.id, type, newGeometry, feature.tags));
|
|
64
|
+
}
|
|
65
|
+
return newFeatures;
|
|
66
|
+
}
|
|
67
|
+
class Points extends Array {
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Shift the x coordinate of every point
|
|
71
|
+
* @param points
|
|
72
|
+
* @param offset
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
function shiftCoords(points, offset) {
|
|
76
|
+
const newPoints = [];
|
|
77
|
+
newPoints.size = points.size;
|
|
78
|
+
if (points.start !== undefined) {
|
|
79
|
+
newPoints.start = points.start;
|
|
80
|
+
newPoints.end = points.end;
|
|
81
|
+
}
|
|
82
|
+
for (let i = 0; i < points.length; i += 3) {
|
|
83
|
+
newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
|
|
84
|
+
}
|
|
85
|
+
return newPoints;
|
|
86
|
+
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const mapbox_util_functions_1 = require("../../helpers/mapbox-util-functions");
|
|
4
4
|
class VectorTileFeature {
|
|
5
|
+
static get types() {
|
|
6
|
+
return ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
7
|
+
}
|
|
5
8
|
constructor(pbf, end, extent, keys, values) {
|
|
6
9
|
// Public
|
|
7
10
|
this.properties = {};
|
|
@@ -15,9 +18,6 @@ class VectorTileFeature {
|
|
|
15
18
|
this._values = values;
|
|
16
19
|
pbf.readFields(mapbox_util_functions_1.readFeature, this, end);
|
|
17
20
|
}
|
|
18
|
-
static get types() {
|
|
19
|
-
return ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
20
|
-
}
|
|
21
21
|
// eslint-disable-next-line complexity, max-statements
|
|
22
22
|
loadGeometry() {
|
|
23
23
|
const pbf = this._pbf;
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
/** For local coordinates, the tileIndex is not required */
|
|
3
|
-
|
|
3
|
+
type MVTLocalCoordinatesOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.
|
|
6
6
|
*/
|
|
@@ -8,7 +8,7 @@ declare type MVTLocalCoordinatesOptions = {
|
|
|
8
8
|
tileIndex: null;
|
|
9
9
|
};
|
|
10
10
|
/** In WGS84 coordinates, the tileIndex is required */
|
|
11
|
-
|
|
11
|
+
type MVTWgs84CoordinatesOptions = {
|
|
12
12
|
/**
|
|
13
13
|
* When set to `wgs84`, the parser will return a flat array of GeoJSON objects with coordinates in longitude, latitude decoded from the provided tile index.
|
|
14
14
|
*/
|
|
@@ -23,7 +23,7 @@ declare type MVTWgs84CoordinatesOptions = {
|
|
|
23
23
|
z: number;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
-
export
|
|
26
|
+
export type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {
|
|
27
27
|
/**
|
|
28
28
|
* When non-`null`, the layer name of each feature is added to
|
|
29
29
|
* `feature.properties[layerProperty]`. (A `feature.properties` object is created if the feature
|
|
@@ -37,13 +37,13 @@ export declare type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84Coordinat
|
|
|
37
37
|
layers?: string[];
|
|
38
38
|
shape?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
|
39
39
|
};
|
|
40
|
-
export
|
|
40
|
+
export type MVTMapboxGeometry = {
|
|
41
41
|
type?: string;
|
|
42
42
|
id?: number;
|
|
43
43
|
length: number;
|
|
44
44
|
coordinates?: any[];
|
|
45
45
|
};
|
|
46
|
-
export
|
|
46
|
+
export type MVTMapboxCoordinates = {
|
|
47
47
|
type: string;
|
|
48
48
|
geometry: {
|
|
49
49
|
type: string;
|
|
@@ -54,7 +54,7 @@ export declare type MVTMapboxCoordinates = {
|
|
|
54
54
|
};
|
|
55
55
|
id?: number;
|
|
56
56
|
};
|
|
57
|
-
export
|
|
57
|
+
export type MVTLoaderOptions = LoaderOptions & {
|
|
58
58
|
mvt?: MVTOptions;
|
|
59
59
|
gis?: {
|
|
60
60
|
/**
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE5D,2DAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE5D,2DAA2D;AAC3D,KAAK,0BAA0B,GAAG;IAChC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC;AAEF,sDAAsD;AACtD,KAAK,0BAA0B,GAAG;IAChC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,SAAS,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,0BAA0B,GAAG,0BAA0B,CAAC,GAAG;IACnF;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEhC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;CAC3F,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,iBAAiB,CAAC;KAChC,CAAC;IACF,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,GAAG,CAAC,EAAE;QACJ;;WAEG;QACH,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,yCAAyC;QACzC,MAAM,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;KAC5F,CAAC;CACH,CAAC"}
|
package/dist/mvt-worker.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/mvt",
|
|
3
3
|
"description": "Loader for Mapbox Vector Tiles",
|
|
4
|
-
"version": "3.3.0-alpha.
|
|
4
|
+
"version": "3.3.0-alpha.8",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@loaders.gl/gis": "3.3.0-alpha.
|
|
36
|
-
"@loaders.gl/loader-utils": "3.3.0-alpha.
|
|
37
|
-
"@loaders.gl/schema": "3.3.0-alpha.
|
|
35
|
+
"@loaders.gl/gis": "3.3.0-alpha.8",
|
|
36
|
+
"@loaders.gl/loader-utils": "3.3.0-alpha.8",
|
|
37
|
+
"@loaders.gl/schema": "3.3.0-alpha.8",
|
|
38
38
|
"@math.gl/polygon": "^3.5.1",
|
|
39
39
|
"pbf": "^3.2.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/pbf": "^3.0.2"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "69cfde0340328dd800c7c90151b56b406f47e9ae"
|
|
45
45
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
This directory is forked from Mapbox's https://github.com/mapbox/geojson-vt under ISC License.
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
ISC License
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2015, Mapbox
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
9
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
|
10
|
+
and this permission notice appear in all copies.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
14
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
16
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
17
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
18
|
+
THIS SOFTWARE.
|
|
19
|
+
```
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
3
|
+
|
|
4
|
+
import type {GeoJSONTileFeature} from './tile';
|
|
5
|
+
import {createFeature} from './feature';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable no-continue */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Clip features between two vertical or horizontal axis-parallel lines:
|
|
11
|
+
* | |
|
|
12
|
+
* ___|___ | /
|
|
13
|
+
* / | \____|____/
|
|
14
|
+
* | |
|
|
15
|
+
*
|
|
16
|
+
* @param k1 and k2 are the line coordinates
|
|
17
|
+
* @param axis: 0 for x, 1 for y
|
|
18
|
+
* @param minAll and maxAll: minimum and maximum coordinate value for all features
|
|
19
|
+
*/
|
|
20
|
+
// eslint-disable-next-line max-params, complexity, max-statements
|
|
21
|
+
export function clip(
|
|
22
|
+
features: GeoJSONTileFeature[],
|
|
23
|
+
scale: number,
|
|
24
|
+
k1: number,
|
|
25
|
+
k2: number,
|
|
26
|
+
axis,
|
|
27
|
+
minAll: number,
|
|
28
|
+
maxAll: number,
|
|
29
|
+
options: {lineMetrics: boolean}
|
|
30
|
+
): GeoJSONTileFeature[] | null {
|
|
31
|
+
k1 /= scale;
|
|
32
|
+
k2 /= scale;
|
|
33
|
+
|
|
34
|
+
if (minAll >= k1 && maxAll < k2) {
|
|
35
|
+
return features;
|
|
36
|
+
}
|
|
37
|
+
// trivial accept
|
|
38
|
+
else if (maxAll < k1 || minAll >= k2) {
|
|
39
|
+
return null; // trivial reject
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const clipped: GeoJSONTileFeature[] = [];
|
|
43
|
+
|
|
44
|
+
for (const feature of features) {
|
|
45
|
+
const geometry = feature.geometry;
|
|
46
|
+
let type = feature.type;
|
|
47
|
+
|
|
48
|
+
const min = axis === 0 ? feature.minX : feature.minY;
|
|
49
|
+
const max = axis === 0 ? feature.maxX : feature.maxY;
|
|
50
|
+
|
|
51
|
+
if (min >= k1 && max < k2) {
|
|
52
|
+
// trivial accept
|
|
53
|
+
clipped.push(feature);
|
|
54
|
+
continue;
|
|
55
|
+
} else if (max < k1 || min >= k2) {
|
|
56
|
+
// trivial reject
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let newGeometry: number[][][] | number[][] = [];
|
|
61
|
+
|
|
62
|
+
if (type === 'Point' || type === 'MultiPoint') {
|
|
63
|
+
clipPoints(geometry, newGeometry, k1, k2, axis);
|
|
64
|
+
} else if (type === 'LineString') {
|
|
65
|
+
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
|
|
66
|
+
} else if (type === 'MultiLineString') {
|
|
67
|
+
clipLines(geometry, newGeometry, k1, k2, axis, false);
|
|
68
|
+
} else if (type === 'Polygon') {
|
|
69
|
+
clipLines(geometry, newGeometry, k1, k2, axis, true);
|
|
70
|
+
} else if (type === 'MultiPolygon') {
|
|
71
|
+
for (const polygon of geometry) {
|
|
72
|
+
const newPolygon = [];
|
|
73
|
+
clipLines(polygon, newPolygon, k1, k2, axis, true);
|
|
74
|
+
if (newPolygon.length) {
|
|
75
|
+
newGeometry.push(newPolygon);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (newGeometry.length) {
|
|
81
|
+
if (options.lineMetrics && type === 'LineString') {
|
|
82
|
+
for (const line of newGeometry) {
|
|
83
|
+
clipped.push(createFeature(feature.id, type, line, feature.tags));
|
|
84
|
+
}
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (type === 'LineString' || type === 'MultiLineString') {
|
|
89
|
+
if (newGeometry.length === 1) {
|
|
90
|
+
type = 'LineString';
|
|
91
|
+
// @ts-expect-error TODO - use proper GeoJSON geometry types
|
|
92
|
+
newGeometry = newGeometry[0];
|
|
93
|
+
} else {
|
|
94
|
+
type = 'MultiLineString';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (type === 'Point' || type === 'MultiPoint') {
|
|
98
|
+
type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return clipped.length ? clipped : null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function clipPoints(geom, newGeom, k1: number, k2: number, axis): void {
|
|
109
|
+
for (let i = 0; i < geom.length; i += 3) {
|
|
110
|
+
const a = geom[i + axis];
|
|
111
|
+
|
|
112
|
+
if (a >= k1 && a <= k2) {
|
|
113
|
+
addPoint(newGeom, geom[i], geom[i + 1], geom[i + 2]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// eslint-disable-next-line max-params, complexity, max-statements
|
|
119
|
+
function clipLine(
|
|
120
|
+
geom,
|
|
121
|
+
newGeom,
|
|
122
|
+
k1: number,
|
|
123
|
+
k2: number,
|
|
124
|
+
axis,
|
|
125
|
+
isPolygon: boolean,
|
|
126
|
+
trackMetrics: boolean
|
|
127
|
+
): void {
|
|
128
|
+
let slice = newSlice(geom);
|
|
129
|
+
const intersect = axis === 0 ? intersectX : intersectY;
|
|
130
|
+
let len = geom.start;
|
|
131
|
+
let segLen;
|
|
132
|
+
let t;
|
|
133
|
+
|
|
134
|
+
for (let i = 0; i < geom.length - 3; i += 3) {
|
|
135
|
+
const ax = geom[i];
|
|
136
|
+
const ay = geom[i + 1];
|
|
137
|
+
const az = geom[i + 2];
|
|
138
|
+
const bx = geom[i + 3];
|
|
139
|
+
const by = geom[i + 4];
|
|
140
|
+
const a = axis === 0 ? ax : ay;
|
|
141
|
+
const b = axis === 0 ? bx : by;
|
|
142
|
+
let exited = false;
|
|
143
|
+
|
|
144
|
+
if (trackMetrics) {
|
|
145
|
+
segLen = Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (a < k1) {
|
|
149
|
+
// ---|--> | (line enters the clip region from the left)
|
|
150
|
+
if (b > k1) {
|
|
151
|
+
t = intersect(slice, ax, ay, bx, by, k1);
|
|
152
|
+
if (trackMetrics) {
|
|
153
|
+
slice.start = len + segLen * t;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} else if (a > k2) {
|
|
157
|
+
// | <--|--- (line enters the clip region from the right)
|
|
158
|
+
if (b < k2) {
|
|
159
|
+
t = intersect(slice, ax, ay, bx, by, k2);
|
|
160
|
+
if (trackMetrics) {
|
|
161
|
+
slice.start = len + segLen * t;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
addPoint(slice, ax, ay, az);
|
|
166
|
+
}
|
|
167
|
+
if (b < k1 && a >= k1) {
|
|
168
|
+
// <--|--- | or <--|-----|--- (line exits the clip region on the left)
|
|
169
|
+
t = intersect(slice, ax, ay, bx, by, k1);
|
|
170
|
+
exited = true;
|
|
171
|
+
}
|
|
172
|
+
if (b > k2 && a <= k2) {
|
|
173
|
+
// | ---|--> or ---|-----|--> (line exits the clip region on the right)
|
|
174
|
+
t = intersect(slice, ax, ay, bx, by, k2);
|
|
175
|
+
exited = true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!isPolygon && exited) {
|
|
179
|
+
if (trackMetrics) {
|
|
180
|
+
slice.end = len + segLen * t;
|
|
181
|
+
}
|
|
182
|
+
newGeom.push(slice);
|
|
183
|
+
slice = newSlice(geom);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (trackMetrics) {
|
|
187
|
+
len += segLen;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// add the last point
|
|
192
|
+
let last = geom.length - 3;
|
|
193
|
+
const ax = geom[last];
|
|
194
|
+
const ay = geom[last + 1];
|
|
195
|
+
const az = geom[last + 2];
|
|
196
|
+
const a = axis === 0 ? ax : ay;
|
|
197
|
+
if (a >= k1 && a <= k2) addPoint(slice, ax, ay, az);
|
|
198
|
+
|
|
199
|
+
// close the polygon if its endpoints are not the same after clipping
|
|
200
|
+
last = slice.length - 3;
|
|
201
|
+
if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
|
|
202
|
+
addPoint(slice, slice[0], slice[1], slice[2]);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// add the final slice
|
|
206
|
+
if (slice.length) {
|
|
207
|
+
newGeom.push(slice);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
class Slice extends Array<number> {
|
|
212
|
+
size?: number;
|
|
213
|
+
start?: number;
|
|
214
|
+
end?: number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function newSlice(line: {size: number; start: number; end: number}): Slice {
|
|
218
|
+
const slice: Slice = [];
|
|
219
|
+
slice.size = line.size;
|
|
220
|
+
slice.start = line.start;
|
|
221
|
+
slice.end = line.end;
|
|
222
|
+
return slice;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// eslint-disable-next-line max-params
|
|
226
|
+
function clipLines(geom, newGeom, k1: number, k2: number, axis, isPolygon: boolean): void {
|
|
227
|
+
for (const line of geom) {
|
|
228
|
+
clipLine(line, newGeom, k1, k2, axis, isPolygon, false);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function addPoint(out: number[], x: number, y: number, z: number): void {
|
|
233
|
+
out.push(x, y, z);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// eslint-disable-next-line max-params
|
|
237
|
+
function intersectX(out, ax: number, ay: number, bx: number, by: number, x: number): number {
|
|
238
|
+
const t = (x - ax) / (bx - ax);
|
|
239
|
+
addPoint(out, x, ay + (by - ay) * t, 1);
|
|
240
|
+
return t;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// eslint-disable-next-line max-params
|
|
244
|
+
function intersectY(out, ax: number, ay: number, bx: number, by: number, y): number {
|
|
245
|
+
const t = (y - ay) / (by - ay);
|
|
246
|
+
addPoint(out, ax + (bx - ax) * t, y, 1);
|
|
247
|
+
return t;
|
|
248
|
+
}
|