@loaders.gl/mvt 4.0.0-alpha.5 → 4.0.0-alpha.7
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/bundle.js +2 -2
- package/dist/dist.min.js +1748 -913
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/helpers/binary-util-functions.js +82 -0
- package/dist/es5/helpers/binary-util-functions.js.map +1 -0
- package/dist/es5/helpers/mapbox-util-functions.js +50 -0
- package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/es5/index.js +26 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +168 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +62 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +28 -0
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
- package/dist/es5/lib/geojson-tiler/clip.js +237 -0
- package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/convert.js +161 -0
- package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/feature.js +62 -0
- package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js +186 -0
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/simplify.js +52 -0
- package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/tile.js +121 -0
- package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/transform.js +50 -0
- package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/es5/lib/geojson-tiler/wrap.js +122 -0
- package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +184 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +62 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +28 -0
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/es5/lib/parse-mvt.js +143 -0
- package/dist/es5/lib/parse-mvt.js.map +1 -0
- package/dist/es5/lib/types.js +2 -0
- package/dist/es5/lib/types.js.map +1 -0
- package/dist/es5/mvt-loader.js +58 -0
- package/dist/es5/mvt-loader.js.map +1 -0
- package/dist/es5/workers/mvt-worker.js +6 -0
- package/dist/es5/workers/mvt-worker.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/helpers/binary-util-functions.js +73 -0
- package/dist/esm/helpers/binary-util-functions.js.map +1 -0
- package/dist/esm/helpers/mapbox-util-functions.js +41 -0
- package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +136 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +47 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile.js +19 -0
- package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
- package/dist/esm/lib/geojson-tiler/clip.js +173 -0
- package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/convert.js +116 -0
- package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/feature.js +35 -0
- package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js +171 -0
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/simplify.js +46 -0
- package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/tile.js +103 -0
- package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/transform.js +32 -0
- package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/esm/lib/geojson-tiler/wrap.js +67 -0
- package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +163 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +47 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +19 -0
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/esm/lib/parse-mvt.js +138 -0
- package/dist/esm/lib/parse-mvt.js.map +1 -0
- package/dist/esm/lib/types.js +2 -0
- package/dist/esm/lib/types.js.map +1 -0
- package/dist/esm/mvt-loader.js +29 -0
- package/dist/esm/mvt-loader.js.map +1 -0
- package/dist/esm/workers/mvt-worker.js +4 -0
- package/dist/esm/workers/mvt-worker.js.map +1 -0
- package/dist/helpers/binary-util-functions.js +111 -77
- package/dist/helpers/mapbox-util-functions.d.ts +2 -2
- package/dist/helpers/mapbox-util-functions.js +78 -45
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -143
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
- package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
- 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.d.ts +4 -4
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
- package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
- package/dist/lib/parse-mvt.d.ts +6 -9
- package/dist/lib/parse-mvt.d.ts.map +1 -1
- package/dist/lib/parse-mvt.js +148 -98
- package/dist/lib/types.d.ts +48 -7
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +2 -2
- package/dist/mvt-loader.d.ts.map +1 -1
- package/dist/mvt-loader.js +43 -22
- package/dist/mvt-worker.js +903 -829
- package/dist/workers/mvt-worker.js +5 -4
- package/package.json +7 -7
- package/src/helpers/mapbox-util-functions.ts +2 -2
- package/src/index.ts +7 -0
- package/src/lib/binary-vector-tile/vector-tile-feature.ts +6 -1
- 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
- package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +4 -4
- package/src/lib/parse-mvt.ts +136 -93
- package/src/lib/types.ts +53 -7
- package/src/mvt-loader.ts +13 -9
- package/dist/bundle.js.map +0 -1
- package/dist/helpers/binary-util-functions.js.map +0 -1
- package/dist/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/lib/parse-mvt.js.map +0 -1
- package/dist/lib/types.js.map +0 -1
- package/dist/mvt-loader.js.map +0 -1
- package/dist/workers/mvt-worker.js.map +0 -1
- /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
- /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mvt_loader_1 = require("../mvt-loader");
|
|
4
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
+
(0, loader_utils_1.createLoaderWorker)(mvt_loader_1.MVTLoader);
|
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": "4.0.0-alpha.
|
|
4
|
+
"version": "4.0.0-alpha.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"Mapbox Vector Tiles"
|
|
19
19
|
],
|
|
20
20
|
"types": "dist/index.d.ts",
|
|
21
|
-
"main": "dist/index.js",
|
|
22
|
-
"module": "dist/index.js",
|
|
21
|
+
"main": "dist/es5/index.js",
|
|
22
|
+
"module": "dist/esm/index.js",
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"files": [
|
|
25
25
|
"src",
|
|
@@ -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": "4.0.0-alpha.
|
|
36
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
37
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
35
|
+
"@loaders.gl/gis": "4.0.0-alpha.7",
|
|
36
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.7",
|
|
37
|
+
"@loaders.gl/schema": "4.0.0-alpha.7",
|
|
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": "afb59c4d8e5d8ebb9c28f111cb0c96c5527d0ffd"
|
|
45
45
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Protobuf from 'pbf';
|
|
2
|
-
import {
|
|
2
|
+
import {MVTMapboxGeometry} from '../lib/types';
|
|
3
3
|
import VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@ import VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';
|
|
|
7
7
|
* @param rings
|
|
8
8
|
* @returns polygons
|
|
9
9
|
*/
|
|
10
|
-
export function classifyRings(rings:
|
|
10
|
+
export function classifyRings(rings: MVTMapboxGeometry) {
|
|
11
11
|
const len = rings.length;
|
|
12
12
|
|
|
13
13
|
if (len <= 1) return [rings];
|
package/src/index.ts
CHANGED
|
@@ -189,6 +189,11 @@ export default class VectorTileFeature {
|
|
|
189
189
|
if (typeof options === 'function') {
|
|
190
190
|
return this._toBinaryCoordinates(options);
|
|
191
191
|
}
|
|
192
|
-
|
|
192
|
+
const {x, y, z} = options;
|
|
193
|
+
const size = this.extent * Math.pow(2, z);
|
|
194
|
+
const x0 = this.extent * x;
|
|
195
|
+
const y0 = this.extent * y;
|
|
196
|
+
|
|
197
|
+
return this._toBinaryCoordinates((data: number[]) => project(data, x0, y0, size));
|
|
193
198
|
}
|
|
194
199
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
3
|
+
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
// @ts-nocheck
|
|
6
|
+
|
|
7
|
+
import type {Feature} from '@loaders.gl/schema';
|
|
8
|
+
import type {GeoJSONTileFeature} from './tile';
|
|
9
|
+
|
|
10
|
+
import {simplify} from './simplify';
|
|
11
|
+
import {createFeature} from './feature';
|
|
12
|
+
|
|
13
|
+
// converts GeoJSON feature into an intermediate projected JSON vector format with simplification data
|
|
14
|
+
|
|
15
|
+
export function convert(data: Feature, options): GeoJSONTileFeature[] {
|
|
16
|
+
const features = [];
|
|
17
|
+
if (data.type === 'FeatureCollection') {
|
|
18
|
+
for (let i = 0; i < data.features.length; i++) {
|
|
19
|
+
convertFeature(features, data.features[i], options, i);
|
|
20
|
+
}
|
|
21
|
+
} else if (data.type === 'Feature') {
|
|
22
|
+
convertFeature(features, data, options);
|
|
23
|
+
} else {
|
|
24
|
+
// single geometry or a geometry collection
|
|
25
|
+
convertFeature(features, {geometry: data}, options);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return features;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ConvertFeatureOptions = {
|
|
32
|
+
maxZoom?: number;
|
|
33
|
+
tolerance: number;
|
|
34
|
+
extent: number;
|
|
35
|
+
lineMetrics: boolean;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function convertFeature(
|
|
39
|
+
features: GeoJSONTileFeature[],
|
|
40
|
+
geojson: Feature,
|
|
41
|
+
options: ConvertFeatureOptions,
|
|
42
|
+
index: number
|
|
43
|
+
): void {
|
|
44
|
+
if (!geojson.geometry) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const coords = geojson.geometry.coordinates;
|
|
49
|
+
const type = geojson.geometry.type;
|
|
50
|
+
const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
|
|
51
|
+
let geometry = [];
|
|
52
|
+
let id = geojson.id;
|
|
53
|
+
if (options.promoteId) {
|
|
54
|
+
id = geojson.properties[options.promoteId];
|
|
55
|
+
} else if (options.generateId) {
|
|
56
|
+
id = index || 0;
|
|
57
|
+
}
|
|
58
|
+
if (type === 'Point') {
|
|
59
|
+
convertPoint(coords, geometry);
|
|
60
|
+
} else if (type === 'MultiPoint') {
|
|
61
|
+
for (const p of coords) {
|
|
62
|
+
convertPoint(p, geometry);
|
|
63
|
+
}
|
|
64
|
+
} else if (type === 'LineString') {
|
|
65
|
+
convertLine(coords, geometry, tolerance, false);
|
|
66
|
+
} else if (type === 'MultiLineString') {
|
|
67
|
+
if (options.lineMetrics) {
|
|
68
|
+
// explode into linestrings to be able to track metrics
|
|
69
|
+
for (const line of coords) {
|
|
70
|
+
geometry = [];
|
|
71
|
+
convertLine(line, geometry, tolerance, false);
|
|
72
|
+
features.push(createFeature(id, 'LineString', geometry, geojson.properties));
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
} else {
|
|
76
|
+
convertLines(coords, geometry, tolerance, false);
|
|
77
|
+
}
|
|
78
|
+
} else if (type === 'Polygon') {
|
|
79
|
+
convertLines(coords, geometry, tolerance, true);
|
|
80
|
+
} else if (type === 'MultiPolygon') {
|
|
81
|
+
for (const polygon of coords) {
|
|
82
|
+
const newPolygon = [];
|
|
83
|
+
convertLines(polygon, newPolygon, tolerance, true);
|
|
84
|
+
geometry.push(newPolygon);
|
|
85
|
+
}
|
|
86
|
+
} else if (type === 'GeometryCollection') {
|
|
87
|
+
for (const singleGeometry of geojson.geometry.geometries) {
|
|
88
|
+
convertFeature(
|
|
89
|
+
features,
|
|
90
|
+
{
|
|
91
|
+
id,
|
|
92
|
+
geometry: singleGeometry,
|
|
93
|
+
properties: geojson.properties
|
|
94
|
+
},
|
|
95
|
+
options,
|
|
96
|
+
index
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
} else {
|
|
101
|
+
throw new Error('Input data is not a valid GeoJSON object.');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
features.push(createFeature(id, type, geometry, geojson.properties));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function convertPoint(coords, out): void {
|
|
108
|
+
out.push(projectX(coords[0]), projectY(coords[1]), 0);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function convertLine(ring: number[], out, tolerance: number, isPolygon: boolean): void {
|
|
112
|
+
let x0, y0;
|
|
113
|
+
let size = 0;
|
|
114
|
+
|
|
115
|
+
for (let j = 0; j < ring.length; j++) {
|
|
116
|
+
const x = projectX(ring[j][0]);
|
|
117
|
+
const y = projectY(ring[j][1]);
|
|
118
|
+
|
|
119
|
+
out.push(x, y, 0);
|
|
120
|
+
|
|
121
|
+
if (j > 0) {
|
|
122
|
+
if (isPolygon) {
|
|
123
|
+
size += (x0 * y - x * y0) / 2; // area
|
|
124
|
+
} else {
|
|
125
|
+
size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
x0 = x;
|
|
129
|
+
y0 = y;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const last = out.length - 3;
|
|
133
|
+
out[2] = 1;
|
|
134
|
+
simplify(out, 0, last, tolerance);
|
|
135
|
+
out[last + 2] = 1;
|
|
136
|
+
|
|
137
|
+
out.size = Math.abs(size);
|
|
138
|
+
out.start = 0;
|
|
139
|
+
out.end = out.size;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function convertLines(rings: number[][], out, tolerance: number, isPolygon: boolean): void {
|
|
143
|
+
for (let i = 0; i < rings.length; i++) {
|
|
144
|
+
const geom = [];
|
|
145
|
+
convertLine(rings[i], geom, tolerance, isPolygon);
|
|
146
|
+
out.push(geom);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function projectX(x: number): number {
|
|
151
|
+
return x / 360 + 0.5;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function projectY(y: number): number {
|
|
155
|
+
const sin = Math.sin((y * Math.PI) / 180);
|
|
156
|
+
const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
|
|
157
|
+
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
|
|
158
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
// Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
|
|
3
|
+
|
|
4
|
+
import {GeoJSONTileFeature} from './tile';
|
|
5
|
+
|
|
6
|
+
export function createFeature(id, type, geom, tags): GeoJSONTileFeature {
|
|
7
|
+
const feature: GeoJSONTileFeature = {
|
|
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
|
+
|
|
19
|
+
if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
|
|
20
|
+
calcLineBBox(feature, geom);
|
|
21
|
+
} else if (type === 'Polygon') {
|
|
22
|
+
// the outer ring (ie [0]) contains all inner rings
|
|
23
|
+
calcLineBBox(feature, geom[0]);
|
|
24
|
+
} else if (type === 'MultiLineString') {
|
|
25
|
+
for (const line of geom) {
|
|
26
|
+
calcLineBBox(feature, line);
|
|
27
|
+
}
|
|
28
|
+
} else if (type === 'MultiPolygon') {
|
|
29
|
+
for (const polygon of geom) {
|
|
30
|
+
// the outer ring (ie [0]) contains all inner rings
|
|
31
|
+
calcLineBBox(feature, polygon[0]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return feature;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function calcLineBBox(feature, geom) {
|
|
39
|
+
for (let i = 0; i < geom.length; i += 3) {
|
|
40
|
+
feature.minX = Math.min(feature.minX, geom[i]);
|
|
41
|
+
feature.minY = Math.min(feature.minY, geom[i + 1]);
|
|
42
|
+
feature.maxX = Math.max(feature.maxX, geom[i]);
|
|
43
|
+
feature.maxY = Math.max(feature.maxY, geom[i + 1]);
|
|
44
|
+
}
|
|
45
|
+
}
|