@loaders.gl/mvt 4.0.0-alpha.1 → 4.0.0-alpha.11
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.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +3124 -0
- 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.d.ts +35 -0
- package/dist/helpers/binary-util-functions.d.ts.map +1 -0
- package/dist/helpers/binary-util-functions.js +111 -74
- package/dist/helpers/mapbox-util-functions.d.ts +29 -0
- package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
- package/dist/helpers/mapbox-util-functions.js +78 -45
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -2
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +41 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -142
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
- package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
- package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
- 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 +27 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
- package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
- package/dist/lib/parse-mvt.d.ts +14 -0
- package/dist/lib/parse-mvt.d.ts.map +1 -0
- package/dist/lib/parse-mvt.js +149 -98
- package/dist/lib/types.d.ts +69 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -2
- package/dist/mvt-loader.d.ts +10 -0
- package/dist/mvt-loader.d.ts.map +1 -0
- package/dist/mvt-loader.js +43 -22
- package/dist/mvt-worker.js +845 -766
- package/dist/workers/mvt-worker.d.ts +2 -0
- package/dist/workers/mvt-worker.d.ts.map +1 -0
- package/dist/workers/mvt-worker.js +5 -4
- package/package.json +10 -9
- package/src/helpers/binary-util-functions.ts +9 -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 +42 -45
- package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
- 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 +138 -93
- package/src/lib/types.ts +49 -72
- 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/features-to-binary.js +0 -327
- package/dist/lib/binary-vector-tile/features-to-binary.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/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
- /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
- /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mvt-worker.d.ts","sourceRoot":"","sources":["../../src/workers/mvt-worker.ts"],"names":[],"mappings":""}
|
|
@@ -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.11",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"MVT",
|
|
18
18
|
"Mapbox Vector Tiles"
|
|
19
19
|
],
|
|
20
|
-
"types": "
|
|
21
|
-
"main": "dist/index.js",
|
|
22
|
-
"module": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"main": "dist/es5/index.js",
|
|
22
|
+
"module": "dist/esm/index.js",
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"files": [
|
|
25
25
|
"src",
|
|
@@ -28,17 +28,18 @@
|
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
30
|
"pre-build": "npm run build-worker && npm run build-worker --env.dev && npm run build-bundle",
|
|
31
|
-
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/
|
|
32
|
-
"build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js"
|
|
31
|
+
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js",
|
|
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.
|
|
35
|
+
"@loaders.gl/gis": "4.0.0-alpha.11",
|
|
36
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.11",
|
|
37
|
+
"@loaders.gl/schema": "4.0.0-alpha.11",
|
|
37
38
|
"@math.gl/polygon": "^3.5.1",
|
|
38
39
|
"pbf": "^3.2.1"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@types/pbf": "^3.0.2"
|
|
42
43
|
},
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "bc680098cfea790c67b7fb95bab96e8d9288d34f"
|
|
44
45
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Protobuf from 'pbf';
|
|
2
2
|
import {getPolygonSignedArea} from '@math.gl/polygon';
|
|
3
|
-
import {
|
|
3
|
+
import {FlatIndexedGeometry, FlatPolygon} from '@loaders.gl/schema';
|
|
4
4
|
import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -13,14 +13,16 @@ import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
|
|
|
13
13
|
* @returns object
|
|
14
14
|
*/
|
|
15
15
|
// eslint-disable-next-line max-statements
|
|
16
|
-
export function classifyRings(geom:
|
|
17
|
-
const len = geom.
|
|
16
|
+
export function classifyRings(geom: FlatIndexedGeometry): FlatPolygon {
|
|
17
|
+
const len = geom.indices.length;
|
|
18
|
+
const type = 'Polygon';
|
|
18
19
|
|
|
19
20
|
if (len <= 1) {
|
|
20
21
|
return {
|
|
22
|
+
type,
|
|
21
23
|
data: geom.data,
|
|
22
24
|
areas: [[getPolygonSignedArea(geom.data)]],
|
|
23
|
-
|
|
25
|
+
indices: [geom.indices]
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -32,9 +34,9 @@ export function classifyRings(geom: MvtBinaryGeometry) {
|
|
|
32
34
|
let offset = 0;
|
|
33
35
|
|
|
34
36
|
for (let endIndex: number, i = 0, startIndex: number; i < len; i++) {
|
|
35
|
-
startIndex = geom.
|
|
37
|
+
startIndex = geom.indices[i] - offset;
|
|
36
38
|
|
|
37
|
-
endIndex = geom.
|
|
39
|
+
endIndex = geom.indices[i + 1] - offset || geom.data.length;
|
|
38
40
|
const shape = geom.data.slice(startIndex, endIndex);
|
|
39
41
|
const area = getPolygonSignedArea(shape);
|
|
40
42
|
|
|
@@ -70,7 +72,7 @@ export function classifyRings(geom: MvtBinaryGeometry) {
|
|
|
70
72
|
if (ringAreas) areas.push(ringAreas);
|
|
71
73
|
if (polygon.length) polygons.push(polygon);
|
|
72
74
|
|
|
73
|
-
return {areas,
|
|
75
|
+
return {type, areas, indices: polygons, data: geom.data};
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
/**
|
|
@@ -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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
|
|
2
2
|
|
|
3
3
|
import Protobuf from 'pbf';
|
|
4
|
-
import {
|
|
4
|
+
import {FlatFeature, FlatIndexedGeometry, GeojsonGeometryInfo} from '@loaders.gl/schema';
|
|
5
5
|
import {classifyRings, project, readFeature} from '../../helpers/binary-util-functions';
|
|
6
6
|
|
|
7
7
|
// Reduce GC by reusing variables
|
|
@@ -26,10 +26,7 @@ export default class VectorTileFeature {
|
|
|
26
26
|
_geometry: number;
|
|
27
27
|
_keys: string[];
|
|
28
28
|
_values: (string | number | boolean | null)[];
|
|
29
|
-
|
|
30
|
-
static get types() {
|
|
31
|
-
return ['Unknown', 'Point', 'LineString', 'Polygon'];
|
|
32
|
-
}
|
|
29
|
+
_geometryInfo: GeojsonGeometryInfo;
|
|
33
30
|
|
|
34
31
|
// eslint-disable-next-line max-params
|
|
35
32
|
constructor(
|
|
@@ -38,7 +35,7 @@ export default class VectorTileFeature {
|
|
|
38
35
|
extent: any,
|
|
39
36
|
keys: string[],
|
|
40
37
|
values: (string | number | boolean | null)[],
|
|
41
|
-
|
|
38
|
+
geometryInfo: GeojsonGeometryInfo
|
|
42
39
|
) {
|
|
43
40
|
// Public
|
|
44
41
|
this.properties = {};
|
|
@@ -51,13 +48,13 @@ export default class VectorTileFeature {
|
|
|
51
48
|
this._geometry = -1;
|
|
52
49
|
this._keys = keys;
|
|
53
50
|
this._values = values;
|
|
54
|
-
this.
|
|
51
|
+
this._geometryInfo = geometryInfo;
|
|
55
52
|
|
|
56
53
|
pbf.readFields(readFeature, this, end);
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
// eslint-disable-next-line complexity, max-statements
|
|
60
|
-
loadGeometry():
|
|
57
|
+
loadGeometry(): FlatIndexedGeometry {
|
|
61
58
|
const pbf = this._pbf;
|
|
62
59
|
pbf.pos = this._geometry;
|
|
63
60
|
|
|
@@ -73,7 +70,7 @@ export default class VectorTileFeature {
|
|
|
73
70
|
// `set()` and direct index access. Also, we cannot
|
|
74
71
|
// know how large the buffer should be, so it would
|
|
75
72
|
// increase memory usage
|
|
76
|
-
const
|
|
73
|
+
const indices: number[] = []; // Indices where geometries start
|
|
77
74
|
const data: number[] = []; // Flat array of coordinate data
|
|
78
75
|
|
|
79
76
|
while (pbf.pos < endPos) {
|
|
@@ -91,14 +88,14 @@ export default class VectorTileFeature {
|
|
|
91
88
|
|
|
92
89
|
if (cmd === 1) {
|
|
93
90
|
// New line
|
|
94
|
-
|
|
91
|
+
indices.push(i);
|
|
95
92
|
}
|
|
96
93
|
data.push(x, y);
|
|
97
94
|
i += 2;
|
|
98
95
|
} else if (cmd === 7) {
|
|
99
96
|
// Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90
|
|
100
97
|
if (i > 0) {
|
|
101
|
-
const start =
|
|
98
|
+
const start = indices[indices.length - 1]; // start index of polygon
|
|
102
99
|
data.push(data[start], data[start + 1]); // closePolygon
|
|
103
100
|
i += 2;
|
|
104
101
|
}
|
|
@@ -107,7 +104,7 @@ export default class VectorTileFeature {
|
|
|
107
104
|
}
|
|
108
105
|
}
|
|
109
106
|
|
|
110
|
-
return {data,
|
|
107
|
+
return {data, indices};
|
|
111
108
|
}
|
|
112
109
|
|
|
113
110
|
/**
|
|
@@ -116,27 +113,28 @@ export default class VectorTileFeature {
|
|
|
116
113
|
* @returns result
|
|
117
114
|
*/
|
|
118
115
|
_toBinaryCoordinates(transform) {
|
|
119
|
-
// Expands the protobuf data to an intermediate
|
|
116
|
+
// Expands the protobuf data to an intermediate Flat GeoJSON
|
|
120
117
|
// data format, which maps closely to the binary data buffers.
|
|
121
118
|
// It is similar to GeoJSON, but rather than storing the coordinates
|
|
122
119
|
// in multidimensional arrays, we have a 1D `data` with all the
|
|
123
|
-
// coordinates, and then index into this using the `
|
|
120
|
+
// coordinates, and then index into this using the `indices`
|
|
124
121
|
// parameter, e.g.
|
|
125
122
|
//
|
|
126
123
|
// geometry: {
|
|
127
|
-
// type: 'Point', data: [1,2],
|
|
124
|
+
// type: 'Point', data: [1,2], indices: [0]
|
|
128
125
|
// }
|
|
129
126
|
// geometry: {
|
|
130
|
-
// type: 'LineString', data: [1,2,3,4,...],
|
|
127
|
+
// type: 'LineString', data: [1,2,3,4,...], indices: [0]
|
|
131
128
|
// }
|
|
132
129
|
// geometry: {
|
|
133
|
-
// type: 'Polygon', data: [1,2,3,4,...],
|
|
130
|
+
// type: 'Polygon', data: [1,2,3,4,...], indices: [[0, 2]]
|
|
134
131
|
// }
|
|
135
|
-
// Thus the
|
|
132
|
+
// Thus the indices member lets us look up the relevant range
|
|
136
133
|
// from the data array.
|
|
137
134
|
// The Multi* versions of the above types share the same data
|
|
138
|
-
// structure, just with multiple elements in the
|
|
139
|
-
|
|
135
|
+
// structure, just with multiple elements in the indices array
|
|
136
|
+
const geom = this.loadGeometry();
|
|
137
|
+
let geometry;
|
|
140
138
|
|
|
141
139
|
// Apply the supplied transformation to data
|
|
142
140
|
transform(geom.data, this);
|
|
@@ -146,43 +144,37 @@ export default class VectorTileFeature {
|
|
|
146
144
|
// eslint-disable-next-line default-case
|
|
147
145
|
switch (this.type) {
|
|
148
146
|
case 1: // Point
|
|
149
|
-
this.
|
|
150
|
-
this.
|
|
147
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
148
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
149
|
+
geometry = {type: 'Point', ...geom};
|
|
151
150
|
break;
|
|
152
151
|
|
|
153
152
|
case 2: // LineString
|
|
154
|
-
this.
|
|
155
|
-
this.
|
|
156
|
-
this.
|
|
153
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
154
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
155
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
156
|
+
geometry = {type: 'LineString', ...geom};
|
|
157
157
|
break;
|
|
158
158
|
|
|
159
159
|
case 3: // Polygon
|
|
160
|
-
|
|
160
|
+
geometry = classifyRings(geom);
|
|
161
161
|
|
|
162
|
-
// Unlike Point & LineString geom.
|
|
162
|
+
// Unlike Point & LineString geom.indices is a 2D array, thanks
|
|
163
163
|
// to the classifyRings method
|
|
164
|
-
this.
|
|
165
|
-
this.
|
|
164
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
165
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
166
166
|
|
|
167
|
-
for (const
|
|
168
|
-
this.
|
|
167
|
+
for (const indices of geometry.indices) {
|
|
168
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
169
169
|
}
|
|
170
|
-
this.
|
|
170
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
171
171
|
|
|
172
|
-
geom = classified;
|
|
173
172
|
break;
|
|
173
|
+
default:
|
|
174
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
|
|
177
|
-
if (geom.lines.length > 1) {
|
|
178
|
-
geom.type = `Multi${geom.type}`;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const result: MvtBinaryCoordinates = {
|
|
182
|
-
type: 'Feature',
|
|
183
|
-
geometry: geom,
|
|
184
|
-
properties: this.properties
|
|
185
|
-
};
|
|
177
|
+
const result: FlatFeature = {type: 'Feature', geometry, properties: this.properties};
|
|
186
178
|
|
|
187
179
|
if (this.id !== null) {
|
|
188
180
|
result.id = this.id;
|
|
@@ -193,10 +185,15 @@ export default class VectorTileFeature {
|
|
|
193
185
|
|
|
194
186
|
toBinaryCoordinates(
|
|
195
187
|
options: {x: number; y: number; z: number} | ((data: number[], feature: {extent: any}) => void)
|
|
196
|
-
):
|
|
188
|
+
): FlatFeature {
|
|
197
189
|
if (typeof options === 'function') {
|
|
198
190
|
return this._toBinaryCoordinates(options);
|
|
199
191
|
}
|
|
200
|
-
|
|
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));
|
|
201
198
|
}
|
|
202
199
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import VectorTileFeature from './vector-tile-feature';
|
|
5
5
|
import Protobuf from 'pbf';
|
|
6
|
-
import {
|
|
6
|
+
import {GeojsonGeometryInfo} from '@loaders.gl/schema';
|
|
7
7
|
|
|
8
8
|
export default class VectorTileLayer {
|
|
9
9
|
version: number;
|
|
@@ -36,10 +36,10 @@ export default class VectorTileLayer {
|
|
|
36
36
|
* return feature `i` from this layer as a `VectorTileFeature`
|
|
37
37
|
*
|
|
38
38
|
* @param index
|
|
39
|
-
* @param
|
|
39
|
+
* @param geometryInfo
|
|
40
40
|
* @returns {VectorTileFeature}
|
|
41
41
|
*/
|
|
42
|
-
feature(i: number,
|
|
42
|
+
feature(i: number, geometryInfo: GeojsonGeometryInfo): VectorTileFeature {
|
|
43
43
|
if (i < 0 || i >= this._features.length) {
|
|
44
44
|
throw new Error('feature index out of bounds');
|
|
45
45
|
}
|
|
@@ -53,7 +53,7 @@ export default class VectorTileLayer {
|
|
|
53
53
|
this.extent,
|
|
54
54
|
this._keys,
|
|
55
55
|
this._values,
|
|
56
|
-
|
|
56
|
+
geometryInfo
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -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
|
+
}
|