@loaders.gl/mvt 4.3.0-alpha.2 → 4.3.0-alpha.4
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 +821 -680
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +795 -656
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/lib/get-schemas-from-tilejson.d.ts +4 -0
- package/dist/lib/get-schemas-from-tilejson.d.ts.map +1 -0
- package/dist/lib/get-schemas-from-tilejson.js +55 -0
- package/dist/lib/parse-tilejson.d.ts +9 -4
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.js +6 -6
- package/dist/lib/types.d.ts +39 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +1 -1
- package/dist/lib/utils/geometry-utils.js +1 -1
- package/dist/lib/vector-tiler/{clip.d.ts → features/clip-features.d.ts} +4 -4
- package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{clip.js → features/clip-features.js} +4 -4
- package/dist/lib/vector-tiler/{convert.d.ts → features/convert-feature.d.ts} +7 -7
- package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
- package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
- package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
- package/dist/lib/vector-tiler/{simplify.d.ts → features/simplify-path.d.ts} +2 -2
- package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{simplify.js → features/simplify-path.js} +3 -3
- package/dist/lib/vector-tiler/{wrap.d.ts → features/wrap-features.d.ts} +5 -5
- package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
- package/dist/lib/vector-tiler/{wrap.js → features/wrap-features.js} +33 -26
- package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
- package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/proto-tile.js +138 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
- package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
- package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
- package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
- package/dist/lib/vector-tiler/transform-tile.js +41 -0
- package/dist/mvt-loader.d.ts +2 -0
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-source.d.ts +31 -14
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +26 -6
- package/dist/mvt-worker.js +4 -4
- package/dist/table-tile-source.d.ts +66 -36
- package/dist/table-tile-source.d.ts.map +1 -1
- package/dist/table-tile-source.js +167 -117
- package/dist/tilejson-loader.js +1 -1
- package/package.json +9 -6
- package/src/index.ts +13 -6
- package/src/lib/get-schemas-from-tilejson.ts +64 -0
- package/src/lib/parse-tilejson.ts +19 -12
- package/src/lib/types.ts +40 -2
- package/src/lib/utils/geometry-utils.ts +1 -1
- package/src/lib/vector-tiler/{clip.ts → features/clip-features.ts} +8 -8
- package/src/lib/vector-tiler/{convert.ts → features/convert-feature.ts} +91 -70
- package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
- package/src/lib/vector-tiler/{simplify.ts → features/simplify-path.ts} +8 -3
- package/src/lib/vector-tiler/{wrap.ts → features/wrap-features.ts} +44 -29
- package/src/lib/vector-tiler/proto-tile.ts +217 -0
- package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
- package/src/lib/vector-tiler/transform-tile.ts +57 -0
- package/src/mvt-loader.ts +2 -0
- package/src/mvt-source.ts +42 -18
- package/src/table-tile-source.ts +130 -85
- package/src/tilejson-loader.ts +2 -2
- package/dist/lib/vector-tiler/clip.d.ts.map +0 -1
- package/dist/lib/vector-tiler/convert.d.ts.map +0 -1
- package/dist/lib/vector-tiler/convert.js +0 -139
- package/dist/lib/vector-tiler/feature.d.ts +0 -3
- package/dist/lib/vector-tiler/feature.d.ts.map +0 -1
- package/dist/lib/vector-tiler/feature.js +0 -44
- package/dist/lib/vector-tiler/simplify.d.ts.map +0 -1
- package/dist/lib/vector-tiler/tile.d.ts +0 -38
- package/dist/lib/vector-tiler/tile.d.ts.map +0 -1
- package/dist/lib/vector-tiler/tile.js +0 -123
- package/dist/lib/vector-tiler/transform.d.ts +0 -7
- package/dist/lib/vector-tiler/transform.d.ts.map +0 -1
- package/dist/lib/vector-tiler/transform.js +0 -41
- package/dist/lib/vector-tiler/wrap.d.ts.map +0 -1
- package/src/lib/vector-tiler/feature.ts +0 -47
- package/src/lib/vector-tiler/tile.ts +0 -187
- package/src/lib/vector-tiler/transform.ts +0 -57
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
/**
|
|
6
|
-
* Create a tile from features and tile index
|
|
7
|
-
*/
|
|
8
|
-
export function createTile(features, z, tx, ty, options) {
|
|
9
|
-
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
10
|
-
const tile = {
|
|
11
|
-
features: [],
|
|
12
|
-
numPoints: 0,
|
|
13
|
-
numSimplified: 0,
|
|
14
|
-
numFeatures: features.length,
|
|
15
|
-
source: null,
|
|
16
|
-
x: tx,
|
|
17
|
-
y: ty,
|
|
18
|
-
z,
|
|
19
|
-
transformed: false,
|
|
20
|
-
minX: 2,
|
|
21
|
-
minY: 1,
|
|
22
|
-
maxX: -1,
|
|
23
|
-
maxY: 0
|
|
24
|
-
};
|
|
25
|
-
for (const feature of features) {
|
|
26
|
-
addFeature(tile, feature, tolerance, options);
|
|
27
|
-
}
|
|
28
|
-
return tile;
|
|
29
|
-
}
|
|
30
|
-
// eslint-disable-next-line complexity, max-statements
|
|
31
|
-
function addFeature(tile, feature, tolerance, options) {
|
|
32
|
-
const geom = feature.geometry;
|
|
33
|
-
const type = feature.type;
|
|
34
|
-
const simplified = [];
|
|
35
|
-
tile.minX = Math.min(tile.minX, feature.minX);
|
|
36
|
-
tile.minY = Math.min(tile.minY, feature.minY);
|
|
37
|
-
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
38
|
-
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
39
|
-
if (type === 'Point' || type === 'MultiPoint') {
|
|
40
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
41
|
-
simplified.push(geom[i], geom[i + 1]);
|
|
42
|
-
tile.numPoints++;
|
|
43
|
-
tile.numSimplified++;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else if (type === 'LineString') {
|
|
47
|
-
addLine(simplified, geom, tile, tolerance, false, false);
|
|
48
|
-
}
|
|
49
|
-
else if (type === 'MultiLineString' || type === 'Polygon') {
|
|
50
|
-
for (let i = 0; i < geom.length; i++) {
|
|
51
|
-
addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else if (type === 'MultiPolygon') {
|
|
55
|
-
for (let k = 0; k < geom.length; k++) {
|
|
56
|
-
const polygon = geom[k];
|
|
57
|
-
for (let i = 0; i < polygon.length; i++) {
|
|
58
|
-
addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (simplified.length) {
|
|
63
|
-
let tags = feature.tags || null;
|
|
64
|
-
if (type === 'LineString' && options.lineMetrics) {
|
|
65
|
-
tags = {};
|
|
66
|
-
for (const key in feature.tags)
|
|
67
|
-
tags[key] = feature.tags[key];
|
|
68
|
-
// eslint-disable-next-line camelcase
|
|
69
|
-
tags.mapbox_clip_start = geom.start / geom.size;
|
|
70
|
-
// eslint-disable-next-line camelcase
|
|
71
|
-
tags.mapbox_clip_end = geom.end / geom.size;
|
|
72
|
-
}
|
|
73
|
-
// @ts-expect-error TODO - create sub type?
|
|
74
|
-
const tileFeature = {
|
|
75
|
-
geometry: simplified,
|
|
76
|
-
type: type === 'Polygon' || type === 'MultiPolygon'
|
|
77
|
-
? 3
|
|
78
|
-
: type === 'LineString' || type === 'MultiLineString'
|
|
79
|
-
? 2
|
|
80
|
-
: 1,
|
|
81
|
-
tags
|
|
82
|
-
};
|
|
83
|
-
if (feature.id !== null) {
|
|
84
|
-
tileFeature.id = feature.id;
|
|
85
|
-
}
|
|
86
|
-
tile.features.push(tileFeature);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// eslint-disable-next-line max-params, max-statements
|
|
90
|
-
function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
|
|
91
|
-
const sqTolerance = tolerance * tolerance;
|
|
92
|
-
if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
93
|
-
tile.numPoints += geom.length / 3;
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const ring = [];
|
|
97
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
98
|
-
if (tolerance === 0 || geom[i + 2] > sqTolerance) {
|
|
99
|
-
tile.numSimplified++;
|
|
100
|
-
ring.push(geom[i], geom[i + 1]);
|
|
101
|
-
}
|
|
102
|
-
tile.numPoints++;
|
|
103
|
-
}
|
|
104
|
-
if (isPolygon)
|
|
105
|
-
rewind(ring, isOuter);
|
|
106
|
-
result.push(ring);
|
|
107
|
-
}
|
|
108
|
-
function rewind(ring, clockwise) {
|
|
109
|
-
let area = 0;
|
|
110
|
-
for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
|
|
111
|
-
area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
|
|
112
|
-
}
|
|
113
|
-
if (area > 0 === clockwise) {
|
|
114
|
-
for (let i = 0, len = ring.length; i < len / 2; i += 2) {
|
|
115
|
-
const x = ring[i];
|
|
116
|
-
const y = ring[i + 1];
|
|
117
|
-
ring[i] = ring[len - 2 - i];
|
|
118
|
-
ring[i + 1] = ring[len - 1 - i];
|
|
119
|
-
ring[len - 2 - i] = x;
|
|
120
|
-
ring[len - 1 - i] = y;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { TableTile } from "./tile.js";
|
|
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: TableTile, extent: number): TableTile;
|
|
7
|
-
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/transform.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,SAAS,EAAC,kBAAe;AAEtC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAiCxE"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
/**
|
|
6
|
-
* Transforms the coordinates of each feature in the given tile from
|
|
7
|
-
* mercator-projected space into (extent x extent) tile space.
|
|
8
|
-
*/
|
|
9
|
-
export function transformTile(tile, extent) {
|
|
10
|
-
if (tile.transformed) {
|
|
11
|
-
return tile;
|
|
12
|
-
}
|
|
13
|
-
const z2 = 1 << tile.z;
|
|
14
|
-
const tx = tile.x;
|
|
15
|
-
const ty = tile.y;
|
|
16
|
-
for (const feature of tile.features) {
|
|
17
|
-
const geom = feature.geometry;
|
|
18
|
-
const type = feature.type;
|
|
19
|
-
feature.geometry = [];
|
|
20
|
-
if (type === 1) {
|
|
21
|
-
for (let j = 0; j < geom.length; j += 2) {
|
|
22
|
-
feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
for (let j = 0; j < geom.length; j++) {
|
|
27
|
-
const ring = [];
|
|
28
|
-
for (let k = 0; k < geom[j].length; k += 2) {
|
|
29
|
-
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
|
|
30
|
-
}
|
|
31
|
-
feature.geometry.push(ring);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
tile.transformed = true;
|
|
36
|
-
return tile;
|
|
37
|
-
}
|
|
38
|
-
// eslint-disable-next-line max-params
|
|
39
|
-
function transformPoint(x, y, extent, z2, tx, ty) {
|
|
40
|
-
return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
|
|
41
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/wrap.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,gBAAgB,EAAC,kBAAe;AAI7C;;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,gBAAgB,EAAE,EAAE,OAAO,EAAE,WAAW,sBAkBtE"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
|
|
6
|
-
import {TableTileFeature} from './tile';
|
|
7
|
-
|
|
8
|
-
export function createFeature(id, type, geom, tags): TableTileFeature {
|
|
9
|
-
const feature: TableTileFeature = {
|
|
10
|
-
// eslint-disable-next-line
|
|
11
|
-
id: id == null ? null : id,
|
|
12
|
-
type,
|
|
13
|
-
geometry: geom,
|
|
14
|
-
tags,
|
|
15
|
-
minX: Infinity,
|
|
16
|
-
minY: Infinity,
|
|
17
|
-
maxX: -Infinity,
|
|
18
|
-
maxY: -Infinity
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
|
|
22
|
-
calcLineBBox(feature, geom);
|
|
23
|
-
} else if (type === 'Polygon') {
|
|
24
|
-
// the outer ring (ie [0]) contains all inner rings
|
|
25
|
-
calcLineBBox(feature, geom[0]);
|
|
26
|
-
} else if (type === 'MultiLineString') {
|
|
27
|
-
for (const line of geom) {
|
|
28
|
-
calcLineBBox(feature, line);
|
|
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
|
-
|
|
37
|
-
return feature;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function calcLineBBox(feature, geom) {
|
|
41
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
42
|
-
feature.minX = Math.min(feature.minX, geom[i]);
|
|
43
|
-
feature.minY = Math.min(feature.minY, geom[i + 1]);
|
|
44
|
-
feature.maxX = Math.max(feature.maxX, geom[i]);
|
|
45
|
-
feature.maxY = Math.max(feature.maxY, geom[i + 1]);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
|
|
6
|
-
// import type {Feature} from '@loaders.gl/schema';
|
|
7
|
-
|
|
8
|
-
export type TableTileFeature = {
|
|
9
|
-
type: any;
|
|
10
|
-
geometry: any;
|
|
11
|
-
|
|
12
|
-
// book keeping
|
|
13
|
-
id?: string;
|
|
14
|
-
tags?: string[];
|
|
15
|
-
|
|
16
|
-
// spatial extents
|
|
17
|
-
minX: number;
|
|
18
|
-
maxX: number;
|
|
19
|
-
minY: number;
|
|
20
|
-
maxY: number;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type TableTile = {
|
|
24
|
-
features: TableTileFeature[]; // Feature[]; Doesn't seem JSON compatible??
|
|
25
|
-
type?: number;
|
|
26
|
-
tags?: Record<string, string>;
|
|
27
|
-
|
|
28
|
-
// tile coordinates
|
|
29
|
-
x: number;
|
|
30
|
-
y: number;
|
|
31
|
-
z: number;
|
|
32
|
-
|
|
33
|
-
// spatial extents
|
|
34
|
-
minX: number;
|
|
35
|
-
maxX: number;
|
|
36
|
-
minY: number;
|
|
37
|
-
maxY: number;
|
|
38
|
-
|
|
39
|
-
transformed: boolean;
|
|
40
|
-
numPoints: number;
|
|
41
|
-
numSimplified: number;
|
|
42
|
-
numFeatures: number;
|
|
43
|
-
source: any | null;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type CreateTileOptions = {
|
|
47
|
-
maxZoom?: number;
|
|
48
|
-
tolerance: number;
|
|
49
|
-
extent: number;
|
|
50
|
-
lineMetrics: boolean;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Create a tile from features and tile index
|
|
55
|
-
*/
|
|
56
|
-
export function createTile(features: any[], z, tx, ty, options: CreateTileOptions): TableTile {
|
|
57
|
-
const tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
|
|
58
|
-
const tile: TableTile = {
|
|
59
|
-
features: [],
|
|
60
|
-
numPoints: 0,
|
|
61
|
-
numSimplified: 0,
|
|
62
|
-
numFeatures: features.length,
|
|
63
|
-
source: null,
|
|
64
|
-
x: tx,
|
|
65
|
-
y: ty,
|
|
66
|
-
z,
|
|
67
|
-
transformed: false,
|
|
68
|
-
minX: 2,
|
|
69
|
-
minY: 1,
|
|
70
|
-
maxX: -1,
|
|
71
|
-
maxY: 0
|
|
72
|
-
};
|
|
73
|
-
for (const feature of features) {
|
|
74
|
-
addFeature(tile, feature, tolerance, options);
|
|
75
|
-
}
|
|
76
|
-
return tile;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// eslint-disable-next-line complexity, max-statements
|
|
80
|
-
function addFeature(tile: TableTile, feature, tolerance: number, options: CreateTileOptions) {
|
|
81
|
-
const geom = feature.geometry;
|
|
82
|
-
const type = feature.type;
|
|
83
|
-
const simplified: number[] = [];
|
|
84
|
-
|
|
85
|
-
tile.minX = Math.min(tile.minX, feature.minX);
|
|
86
|
-
tile.minY = Math.min(tile.minY, feature.minY);
|
|
87
|
-
tile.maxX = Math.max(tile.maxX, feature.maxX);
|
|
88
|
-
tile.maxY = Math.max(tile.maxY, feature.maxY);
|
|
89
|
-
|
|
90
|
-
if (type === 'Point' || type === 'MultiPoint') {
|
|
91
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
92
|
-
simplified.push(geom[i], geom[i + 1]);
|
|
93
|
-
tile.numPoints++;
|
|
94
|
-
tile.numSimplified++;
|
|
95
|
-
}
|
|
96
|
-
} else if (type === 'LineString') {
|
|
97
|
-
addLine(simplified, geom, tile, tolerance, false, false);
|
|
98
|
-
} else if (type === 'MultiLineString' || type === 'Polygon') {
|
|
99
|
-
for (let i = 0; i < geom.length; i++) {
|
|
100
|
-
addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
|
|
101
|
-
}
|
|
102
|
-
} else if (type === 'MultiPolygon') {
|
|
103
|
-
for (let k = 0; k < geom.length; k++) {
|
|
104
|
-
const polygon = geom[k];
|
|
105
|
-
for (let i = 0; i < polygon.length; i++) {
|
|
106
|
-
addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (simplified.length) {
|
|
112
|
-
let tags = feature.tags || null;
|
|
113
|
-
|
|
114
|
-
if (type === 'LineString' && options.lineMetrics) {
|
|
115
|
-
tags = {};
|
|
116
|
-
for (const key in feature.tags) tags[key] = feature.tags[key];
|
|
117
|
-
// eslint-disable-next-line camelcase
|
|
118
|
-
tags.mapbox_clip_start = geom.start / geom.size;
|
|
119
|
-
// eslint-disable-next-line camelcase
|
|
120
|
-
tags.mapbox_clip_end = geom.end / geom.size;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// @ts-expect-error TODO - create sub type?
|
|
124
|
-
const tileFeature: TableTileFeature = {
|
|
125
|
-
geometry: simplified,
|
|
126
|
-
type:
|
|
127
|
-
type === 'Polygon' || type === 'MultiPolygon'
|
|
128
|
-
? 3
|
|
129
|
-
: type === 'LineString' || type === 'MultiLineString'
|
|
130
|
-
? 2
|
|
131
|
-
: 1,
|
|
132
|
-
tags
|
|
133
|
-
};
|
|
134
|
-
if (feature.id !== null) {
|
|
135
|
-
tileFeature.id = feature.id;
|
|
136
|
-
}
|
|
137
|
-
tile.features.push(tileFeature);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// eslint-disable-next-line max-params, max-statements
|
|
142
|
-
function addLine(
|
|
143
|
-
result,
|
|
144
|
-
geom,
|
|
145
|
-
tile: TableTile,
|
|
146
|
-
tolerance: number,
|
|
147
|
-
isPolygon: boolean,
|
|
148
|
-
isOuter: boolean
|
|
149
|
-
): void {
|
|
150
|
-
const sqTolerance = tolerance * tolerance;
|
|
151
|
-
|
|
152
|
-
if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
|
|
153
|
-
tile.numPoints += geom.length / 3;
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const ring: number[] = [];
|
|
158
|
-
|
|
159
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
160
|
-
if (tolerance === 0 || geom[i + 2] > sqTolerance) {
|
|
161
|
-
tile.numSimplified++;
|
|
162
|
-
ring.push(geom[i], geom[i + 1]);
|
|
163
|
-
}
|
|
164
|
-
tile.numPoints++;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (isPolygon) rewind(ring, isOuter);
|
|
168
|
-
|
|
169
|
-
result.push(ring);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function rewind(ring: number[], clockwise?: boolean): void {
|
|
173
|
-
let area = 0;
|
|
174
|
-
for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
|
|
175
|
-
area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
|
|
176
|
-
}
|
|
177
|
-
if (area > 0 === clockwise) {
|
|
178
|
-
for (let i = 0, len = ring.length; i < len / 2; i += 2) {
|
|
179
|
-
const x = ring[i];
|
|
180
|
-
const y = ring[i + 1];
|
|
181
|
-
ring[i] = ring[len - 2 - i];
|
|
182
|
-
ring[i + 1] = ring[len - 1 - i];
|
|
183
|
-
ring[len - 2 - i] = x;
|
|
184
|
-
ring[len - 1 - i] = y;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
5
|
-
|
|
6
|
-
import type {TableTile} from './tile';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Transforms the coordinates of each feature in the given tile from
|
|
10
|
-
* mercator-projected space into (extent x extent) tile space.
|
|
11
|
-
*/
|
|
12
|
-
export function transformTile(tile: TableTile, extent: number): TableTile {
|
|
13
|
-
if (tile.transformed) {
|
|
14
|
-
return tile;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const z2 = 1 << tile.z;
|
|
18
|
-
const tx = tile.x;
|
|
19
|
-
const ty = tile.y;
|
|
20
|
-
|
|
21
|
-
for (const feature of tile.features) {
|
|
22
|
-
const geom = feature.geometry;
|
|
23
|
-
const type = feature.type;
|
|
24
|
-
|
|
25
|
-
feature.geometry = [];
|
|
26
|
-
|
|
27
|
-
if (type === 1) {
|
|
28
|
-
for (let j = 0; j < geom.length; j += 2) {
|
|
29
|
-
feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
for (let j = 0; j < geom.length; j++) {
|
|
33
|
-
const ring: number[][] = [];
|
|
34
|
-
for (let k = 0; k < geom[j].length; k += 2) {
|
|
35
|
-
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
|
|
36
|
-
}
|
|
37
|
-
feature.geometry.push(ring);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
tile.transformed = true;
|
|
43
|
-
|
|
44
|
-
return tile;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// eslint-disable-next-line max-params
|
|
48
|
-
function transformPoint(
|
|
49
|
-
x: number,
|
|
50
|
-
y: number,
|
|
51
|
-
extent: number,
|
|
52
|
-
z2: number,
|
|
53
|
-
tx: number,
|
|
54
|
-
ty: number
|
|
55
|
-
): number[] {
|
|
56
|
-
return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
|
|
57
|
-
}
|