@deck.gl-community/layers 9.0.0-alpha.1 → 9.0.2
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/index.cjs +605 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -5
- package/dist/path-marker-layer/arrow-2d-geometry.d.ts +4 -0
- package/dist/path-marker-layer/arrow-2d-geometry.js +58 -0
- package/dist/path-marker-layer/create-path-markers.d.ts +18 -0
- package/dist/path-marker-layer/create-path-markers.js +78 -0
- package/dist/path-marker-layer/path-marker-layer.d.ts +40 -0
- package/dist/path-marker-layer/path-marker-layer.js +124 -0
- package/dist/path-marker-layer/polyline.d.ts +18 -0
- package/dist/path-marker-layer/polyline.js +40 -0
- package/dist/path-outline-layer/outline.d.ts +8 -0
- package/dist/path-outline-layer/outline.js +100 -0
- package/dist/path-outline-layer/path-outline-layer.d.ts +34 -0
- package/dist/path-outline-layer/path-outline-layer.js +116 -0
- package/dist/tile-source-layer/tile-source-layer.d.ts +43 -0
- package/dist/tile-source-layer/tile-source-layer.js +109 -0
- package/package.json +27 -13
- package/src/index.ts +7 -4
- package/src/path-marker-layer/arrow-2d-geometry.ts +65 -0
- package/src/path-marker-layer/create-path-markers.ts +122 -0
- package/src/path-marker-layer/path-marker-layer.ts +183 -0
- package/src/path-marker-layer/polyline.ts +44 -0
- package/src/path-outline-layer/outline.ts +107 -0
- package/src/path-outline-layer/path-outline-layer.ts +159 -0
- package/src/{tile-source-layer.ts → tile-source-layer/tile-source-layer.ts} +30 -22
- package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.js +0 -193
- package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.js.map +0 -1
- package/dist/data-driven-tile-3d-layer/utils/colorize-tile.js +0 -31
- package/dist/data-driven-tile-3d-layer/utils/colorize-tile.js.map +0 -1
- package/dist/data-driven-tile-3d-layer/utils/filter-tile.js +0 -146
- package/dist/data-driven-tile-3d-layer/utils/filter-tile.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/tile-source-layer.js +0 -112
- package/dist/tile-source-layer.js.map +0 -1
- package/src/data-driven-tile-3d-layer/data-driven-tile-3d-layer.ts +0 -261
- package/src/data-driven-tile-3d-layer/utils/colorize-tile.ts +0 -53
- package/src/data-driven-tile-3d-layer/utils/filter-tile.ts +0 -179
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CompositeLayer } from '@deck.gl/core';
|
|
2
|
+
import { TileLayer, TileLayerProps } from '@deck.gl/geo-layers';
|
|
3
|
+
import type { TileSource } from '@loaders.gl/loader-utils';
|
|
4
|
+
export type TileSourceLayerProps = TileLayerProps & {
|
|
5
|
+
tileSource: TileSource<any>;
|
|
6
|
+
showTileBorders?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A Deck.gl layer that renders a tile source
|
|
10
|
+
* Autodiscovers type of content (vector tile, bitmap, ...)
|
|
11
|
+
* Can render debug borders around tiles
|
|
12
|
+
* TODO - Change debug border color based on zoom level
|
|
13
|
+
*/
|
|
14
|
+
export declare class TileSourceLayer extends CompositeLayer<TileSourceLayerProps> {
|
|
15
|
+
static layerName: string;
|
|
16
|
+
static defaultProps: {
|
|
17
|
+
showTileBorders: boolean;
|
|
18
|
+
};
|
|
19
|
+
state: {
|
|
20
|
+
tileSource: TileSource<any> | null;
|
|
21
|
+
};
|
|
22
|
+
initializeState(): void;
|
|
23
|
+
updateState({ props, changeFlags }: {
|
|
24
|
+
props: any;
|
|
25
|
+
changeFlags: any;
|
|
26
|
+
}): void;
|
|
27
|
+
renderLayers(): TileLayer<any, {
|
|
28
|
+
id: string;
|
|
29
|
+
getTileData: any;
|
|
30
|
+
maxRequests: 20;
|
|
31
|
+
pickable: true;
|
|
32
|
+
onViewportLoad: any;
|
|
33
|
+
autoHighlight: any;
|
|
34
|
+
highlightColor: number[];
|
|
35
|
+
minZoom: any;
|
|
36
|
+
maxZoom: any;
|
|
37
|
+
tileSize: 256;
|
|
38
|
+
zoomOffset: 0 | -1;
|
|
39
|
+
renderSubLayers: any;
|
|
40
|
+
tileSource: any;
|
|
41
|
+
showTileBorders: any;
|
|
42
|
+
}>[];
|
|
43
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { CompositeLayer } from '@deck.gl/core';
|
|
5
|
+
import { TileLayer } from '@deck.gl/geo-layers';
|
|
6
|
+
import { BitmapLayer, GeoJsonLayer, PathLayer } from '@deck.gl/layers';
|
|
7
|
+
/* global window */
|
|
8
|
+
const devicePixelRatio = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
|
|
9
|
+
/**
|
|
10
|
+
* A Deck.gl layer that renders a tile source
|
|
11
|
+
* Autodiscovers type of content (vector tile, bitmap, ...)
|
|
12
|
+
* Can render debug borders around tiles
|
|
13
|
+
* TODO - Change debug border color based on zoom level
|
|
14
|
+
*/
|
|
15
|
+
export class TileSourceLayer extends CompositeLayer {
|
|
16
|
+
static layerName = 'TileSourceLayer';
|
|
17
|
+
static defaultProps = {
|
|
18
|
+
...TileLayer.defaultProps,
|
|
19
|
+
showTileBorders: true
|
|
20
|
+
};
|
|
21
|
+
state = undefined;
|
|
22
|
+
initializeState() {
|
|
23
|
+
this.setState({
|
|
24
|
+
tileSource: null
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
updateState({ props, changeFlags }) {
|
|
28
|
+
this.setState({
|
|
29
|
+
tileSource: props.tileSource
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
renderLayers() {
|
|
33
|
+
const { tileSource, showTileBorders, metadata, onTilesLoad } = this.props;
|
|
34
|
+
const minZoom = metadata?.minZoom || 0;
|
|
35
|
+
const maxZoom = metadata?.maxZoom || 30;
|
|
36
|
+
return [
|
|
37
|
+
new TileLayer({
|
|
38
|
+
// HACK: Trigger new layer via id prop to force clear tile cache
|
|
39
|
+
id: String(tileSource.url),
|
|
40
|
+
getTileData: tileSource.getTileData,
|
|
41
|
+
// Assume the pmtiles file support HTTP/2, so we aren't limited by the browser to a certain number per domain.
|
|
42
|
+
maxRequests: 20,
|
|
43
|
+
pickable: true,
|
|
44
|
+
onViewportLoad: onTilesLoad,
|
|
45
|
+
autoHighlight: showTileBorders,
|
|
46
|
+
highlightColor: [60, 60, 60, 40],
|
|
47
|
+
minZoom,
|
|
48
|
+
maxZoom,
|
|
49
|
+
tileSize: 256,
|
|
50
|
+
// TOOD - why is this needed?
|
|
51
|
+
zoomOffset: devicePixelRatio === 1 ? -1 : 0,
|
|
52
|
+
renderSubLayers: renderSubLayers,
|
|
53
|
+
// Custom prop
|
|
54
|
+
tileSource,
|
|
55
|
+
showTileBorders
|
|
56
|
+
})
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function renderSubLayers(props) {
|
|
61
|
+
const { tileSource, showTileBorders, minZoom, maxZoom, tile: { index: { z: zoom }, bbox: { west, south, east, north } } } = props;
|
|
62
|
+
const layers = [];
|
|
63
|
+
const borderColor = zoom <= minZoom || zoom >= maxZoom ? [255, 0, 0, 255] : [0, 0, 255, 255];
|
|
64
|
+
switch (tileSource.mimeType) {
|
|
65
|
+
case 'application/vnd.mapbox-vector-tile':
|
|
66
|
+
layers.push(new GeoJsonLayer({
|
|
67
|
+
id: `${props.id}-geojson`,
|
|
68
|
+
data: props.data,
|
|
69
|
+
pickable: true,
|
|
70
|
+
getFillColor: [0, 190, 80, 255],
|
|
71
|
+
lineWidthScale: 500,
|
|
72
|
+
lineWidthMinPixels: 0.5
|
|
73
|
+
}));
|
|
74
|
+
break;
|
|
75
|
+
case 'image/png':
|
|
76
|
+
case 'image/jpeg':
|
|
77
|
+
case 'image/webp':
|
|
78
|
+
case 'image/avif':
|
|
79
|
+
layers.push(new BitmapLayer(props, {
|
|
80
|
+
data: null,
|
|
81
|
+
image: props.data,
|
|
82
|
+
bounds: [west, south, east, north],
|
|
83
|
+
pickable: true
|
|
84
|
+
}));
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
// eslint-disable-next-line no-console
|
|
88
|
+
console.error('Unknown tile mimeType', tileSource?.mimeType);
|
|
89
|
+
}
|
|
90
|
+
// Debug tile borders
|
|
91
|
+
if (showTileBorders) {
|
|
92
|
+
layers.push(new PathLayer({
|
|
93
|
+
id: `${props.id}-border`,
|
|
94
|
+
data: [
|
|
95
|
+
[
|
|
96
|
+
[west, north],
|
|
97
|
+
[west, south],
|
|
98
|
+
[east, south],
|
|
99
|
+
[east, north],
|
|
100
|
+
[west, north]
|
|
101
|
+
]
|
|
102
|
+
],
|
|
103
|
+
getPath: (d) => d,
|
|
104
|
+
getColor: borderColor,
|
|
105
|
+
widthMinPixels: 4
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
return layers;
|
|
109
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deck.gl-community/layers",
|
|
3
|
-
"version": "9.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "9.0.2",
|
|
4
|
+
"description": "Addon layers for deck.gl",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"layers",
|
|
@@ -11,26 +11,40 @@
|
|
|
11
11
|
],
|
|
12
12
|
"type": "module",
|
|
13
13
|
"sideEffects": false,
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
14
15
|
"main": "./dist/index.cjs",
|
|
15
16
|
"module": "./dist/index.js",
|
|
16
17
|
"exports": {
|
|
17
18
|
".": {
|
|
18
|
-
"
|
|
19
|
-
"
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"require": "./dist/index.cjs",
|
|
21
|
+
"import": "./dist/index.js"
|
|
20
22
|
}
|
|
21
23
|
},
|
|
22
24
|
"files": [
|
|
23
25
|
"dist",
|
|
24
26
|
"src"
|
|
25
27
|
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test-watch": "vitest"
|
|
31
|
+
},
|
|
26
32
|
"dependencies": {
|
|
27
|
-
"@deck.gl/core": "^9.0.
|
|
28
|
-
"@deck.gl/extensions": "9.0.
|
|
29
|
-
"@deck.gl/geo-layers": "^9.0.
|
|
30
|
-
"@deck.gl/layers": "^9.0.
|
|
31
|
-
"@deck.gl/mesh-layers": "^9.0.
|
|
32
|
-
"@deck.gl/react": "^9.0.
|
|
33
|
-
"@loaders.gl/core": "^4.
|
|
34
|
-
"@loaders.gl/
|
|
35
|
-
|
|
33
|
+
"@deck.gl/core": "^9.0.12",
|
|
34
|
+
"@deck.gl/extensions": "^9.0.12",
|
|
35
|
+
"@deck.gl/geo-layers": "^9.0.12",
|
|
36
|
+
"@deck.gl/layers": "^9.0.12",
|
|
37
|
+
"@deck.gl/mesh-layers": "^9.0.12",
|
|
38
|
+
"@deck.gl/react": "^9.0.12",
|
|
39
|
+
"@loaders.gl/core": "^4.2.0",
|
|
40
|
+
"@loaders.gl/i3s": "^4.2.0",
|
|
41
|
+
"@loaders.gl/loader-utils": "^4.2.0",
|
|
42
|
+
"@loaders.gl/schema": "^4.2.0",
|
|
43
|
+
"@loaders.gl/tiles": "^4.2.0",
|
|
44
|
+
"@luma.gl/constants": "^9.0.11",
|
|
45
|
+
"@luma.gl/core": "^9.0.11",
|
|
46
|
+
"@luma.gl/engine": "^9.0.11",
|
|
47
|
+
"@math.gl/core": "^4.0.0"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "646f8328d27d67d596f05c9154072051ec5cf4f0"
|
|
36
50
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
5
|
+
export type {TileSourceLayerProps} from './tile-source-layer/tile-source-layer';
|
|
6
|
+
export {TileSourceLayer} from './tile-source-layer/tile-source-layer';
|
|
7
7
|
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
8
|
+
export type {PathOutlineLayerProps} from './path-outline-layer/path-outline-layer';
|
|
9
|
+
export {PathOutlineLayer} from './path-outline-layer/path-outline-layer';
|
|
10
|
+
|
|
11
|
+
export type {PathMarkerLayerProps} from './path-marker-layer/path-marker-layer';
|
|
12
|
+
export {PathMarkerLayer} from './path-marker-layer/path-marker-layer';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Geometry} from '@luma.gl/engine';
|
|
6
|
+
|
|
7
|
+
export class Arrow2DGeometry extends Geometry {
|
|
8
|
+
constructor(opts = {}) {
|
|
9
|
+
super(
|
|
10
|
+
Object.assign({}, opts, {
|
|
11
|
+
attributes: getArrowAttributes(opts),
|
|
12
|
+
topology: 'triangle-list' as const
|
|
13
|
+
})
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getArrowAttributes({length = 1, headSize = 0.2, tailWidth = 0.05, tailStart = 0.05}) {
|
|
19
|
+
const texCoords = [
|
|
20
|
+
// HEAD
|
|
21
|
+
0.5,
|
|
22
|
+
1.0,
|
|
23
|
+
0,
|
|
24
|
+
0.5 - headSize / 2,
|
|
25
|
+
1.0 - headSize,
|
|
26
|
+
0,
|
|
27
|
+
0.5 + headSize / 2,
|
|
28
|
+
1.0 - headSize,
|
|
29
|
+
0,
|
|
30
|
+
0.5 - tailWidth / 2,
|
|
31
|
+
tailStart,
|
|
32
|
+
0,
|
|
33
|
+
0.5 + tailWidth / 2,
|
|
34
|
+
1.0 - headSize,
|
|
35
|
+
0,
|
|
36
|
+
0.5 + tailWidth / 2,
|
|
37
|
+
tailStart,
|
|
38
|
+
0,
|
|
39
|
+
0.5 - tailWidth / 2,
|
|
40
|
+
tailStart,
|
|
41
|
+
0,
|
|
42
|
+
0.5 - tailWidth / 2,
|
|
43
|
+
1.0 - headSize,
|
|
44
|
+
0,
|
|
45
|
+
0.5 + tailWidth / 2,
|
|
46
|
+
1.0 - headSize,
|
|
47
|
+
0
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const normals = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1];
|
|
51
|
+
|
|
52
|
+
// Center and scale
|
|
53
|
+
const positions = new Array(texCoords.length);
|
|
54
|
+
for (let i = 0; i < texCoords.length / 3; i++) {
|
|
55
|
+
const i3 = i * 3;
|
|
56
|
+
positions[i3 + 0] = (texCoords[i3 + 0] - 0.5) * length;
|
|
57
|
+
positions[i3 + 1] = (texCoords[i3 + 1] - 0.5) * length;
|
|
58
|
+
positions[i3 + 2] = 0;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
positions: {size: 3, value: new Float32Array(positions)},
|
|
62
|
+
normals: {size: 3, value: new Float32Array(normals)},
|
|
63
|
+
texCoords: {size: 2, value: new Float32Array(texCoords)}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Vector2} from '@math.gl/core';
|
|
6
|
+
|
|
7
|
+
/** GeoJSON style position coordinate vector */
|
|
8
|
+
export type Position = [number, number] | [number, number, number];
|
|
9
|
+
|
|
10
|
+
/** [red, green, blue, alpha] in premultiplied alpha format */
|
|
11
|
+
export type Color = [number, number, number, number];
|
|
12
|
+
|
|
13
|
+
export interface PathMarker {
|
|
14
|
+
position: Position;
|
|
15
|
+
angle: number;
|
|
16
|
+
color: Color;
|
|
17
|
+
object: unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getLineLength(vPoints) {
|
|
21
|
+
// calculate total length
|
|
22
|
+
let lineLength = 0;
|
|
23
|
+
for (let i = 0; i < vPoints.length - 1; i++) {
|
|
24
|
+
lineLength += vPoints[i].distance(vPoints[i + 1]);
|
|
25
|
+
}
|
|
26
|
+
return lineLength;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const DEFAULT_COLOR = [0, 0, 0, 255];
|
|
30
|
+
const DEFAULT_DIRECTION = {forward: true, backward: false};
|
|
31
|
+
|
|
32
|
+
export function createPathMarkers({
|
|
33
|
+
data,
|
|
34
|
+
getPath = (x, context) => x.path,
|
|
35
|
+
getDirection = (x) => x.direction,
|
|
36
|
+
getColor = (x) => DEFAULT_COLOR,
|
|
37
|
+
getMarkerPercentages = (x, info) => [0.5],
|
|
38
|
+
projectFlat
|
|
39
|
+
}): PathMarker[] {
|
|
40
|
+
const markers: PathMarker[] = [];
|
|
41
|
+
|
|
42
|
+
for (const object of data) {
|
|
43
|
+
const path = getPath(object, null);
|
|
44
|
+
const direction = getDirection(object) || DEFAULT_DIRECTION;
|
|
45
|
+
const color = getColor(object);
|
|
46
|
+
|
|
47
|
+
const vPoints = path.map((p) => new Vector2(p));
|
|
48
|
+
const vPointsReverse = vPoints.slice(0).reverse();
|
|
49
|
+
|
|
50
|
+
// calculate total length
|
|
51
|
+
const lineLength = getLineLength(vPoints);
|
|
52
|
+
|
|
53
|
+
// Ask for where to put markers
|
|
54
|
+
const percentages = getMarkerPercentages(object, {lineLength});
|
|
55
|
+
|
|
56
|
+
// Create the markers
|
|
57
|
+
for (const percentage of percentages) {
|
|
58
|
+
if (direction.forward) {
|
|
59
|
+
const marker = createMarkerAlongPath({
|
|
60
|
+
path: vPoints,
|
|
61
|
+
percentage,
|
|
62
|
+
lineLength,
|
|
63
|
+
color,
|
|
64
|
+
object,
|
|
65
|
+
projectFlat
|
|
66
|
+
});
|
|
67
|
+
markers.push(marker);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (direction.backward) {
|
|
71
|
+
const marker = createMarkerAlongPath({
|
|
72
|
+
path: vPointsReverse,
|
|
73
|
+
percentage,
|
|
74
|
+
lineLength,
|
|
75
|
+
color,
|
|
76
|
+
object,
|
|
77
|
+
projectFlat
|
|
78
|
+
});
|
|
79
|
+
markers.push(marker);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return markers;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function createMarkerAlongPath({
|
|
88
|
+
path,
|
|
89
|
+
percentage,
|
|
90
|
+
lineLength,
|
|
91
|
+
color,
|
|
92
|
+
object,
|
|
93
|
+
projectFlat
|
|
94
|
+
}): PathMarker {
|
|
95
|
+
const distanceAlong = lineLength * percentage;
|
|
96
|
+
let currentDistance = 0;
|
|
97
|
+
let previousDistance = 0;
|
|
98
|
+
let i = 0;
|
|
99
|
+
for (i = 0; i < path.length - 1; i++) {
|
|
100
|
+
currentDistance += path[i].distance(path[i + 1]);
|
|
101
|
+
if (currentDistance > distanceAlong) {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
previousDistance = currentDistance;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// If reached the end of the loop without exiting early,
|
|
108
|
+
// undo the final increment to avoid a null-pointer exception
|
|
109
|
+
if (i === path.length - 1) {
|
|
110
|
+
i -= 1;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const vDirection = path[i + 1].clone().subtract(path[i]).normalize();
|
|
114
|
+
const along = distanceAlong - previousDistance;
|
|
115
|
+
const vCenter = vDirection.clone().multiply(new Vector2(along, along)).add(path[i]);
|
|
116
|
+
|
|
117
|
+
const vDirection2 = new Vector2(projectFlat(path[i + 1])).subtract(projectFlat(path[i]));
|
|
118
|
+
|
|
119
|
+
const angle = (vDirection2.verticalAngle() * 180) / Math.PI;
|
|
120
|
+
|
|
121
|
+
return {position: [vCenter.x, vCenter.y, 0], angle, color, object};
|
|
122
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {CompositeLayer, COORDINATE_SYSTEM, DefaultProps} from '@deck.gl/core';
|
|
6
|
+
import {ScatterplotLayer} from '@deck.gl/layers';
|
|
7
|
+
import {SimpleMeshLayer} from '@deck.gl/mesh-layers';
|
|
8
|
+
import {PathOutlineLayer, PathOutlineLayerProps} from '../path-outline-layer/path-outline-layer';
|
|
9
|
+
import {Arrow2DGeometry} from './arrow-2d-geometry';
|
|
10
|
+
|
|
11
|
+
import {createPathMarkers} from './create-path-markers';
|
|
12
|
+
import {getClosestPointOnPolyline} from './polyline';
|
|
13
|
+
import {Vector3} from '@math.gl/core';
|
|
14
|
+
|
|
15
|
+
const DISTANCE_FOR_MULTI_ARROWS = 0.1;
|
|
16
|
+
const ARROW_HEAD_SIZE = 0.2;
|
|
17
|
+
const ARROW_TAIL_WIDTH = 0.05;
|
|
18
|
+
// const ARROW_CENTER_ADJUST = -0.8;
|
|
19
|
+
|
|
20
|
+
const DEFAULT_MARKER_LAYER = SimpleMeshLayer;
|
|
21
|
+
|
|
22
|
+
export type PathMarkerLayerProps<DataT> = PathOutlineLayerProps<DataT> & {
|
|
23
|
+
getDirection?: (x) => any;
|
|
24
|
+
getMarkerColor?: (x) => number[];
|
|
25
|
+
getMarkerPercentages?: (x: any, info: any) => number[];
|
|
26
|
+
highlightPoint?: any;
|
|
27
|
+
highlightIndex?: number;
|
|
28
|
+
MarkerLayer?: any;
|
|
29
|
+
markerLayerProps?: any;
|
|
30
|
+
sizeScale?: number;
|
|
31
|
+
fp64?: boolean;
|
|
32
|
+
nebulaLayer?: any;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const DEFAULT_MARKER_LAYER_PROPS = {
|
|
36
|
+
mesh: new Arrow2DGeometry({headSize: ARROW_HEAD_SIZE, tailWidth: ARROW_TAIL_WIDTH})
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const defaultProps: DefaultProps<PathMarkerLayerProps<any>> = Object.assign(
|
|
40
|
+
{},
|
|
41
|
+
PathOutlineLayer.defaultProps,
|
|
42
|
+
{
|
|
43
|
+
MarkerLayer: DEFAULT_MARKER_LAYER,
|
|
44
|
+
markerLayerProps: DEFAULT_MARKER_LAYER_PROPS,
|
|
45
|
+
|
|
46
|
+
sizeScale: 100,
|
|
47
|
+
fp64: false,
|
|
48
|
+
|
|
49
|
+
highlightIndex: -1,
|
|
50
|
+
highlightPoint: null,
|
|
51
|
+
|
|
52
|
+
getPath: (x) => x.path,
|
|
53
|
+
getColor: (x) => x.color,
|
|
54
|
+
getMarkerColor: (x) => [0, 0, 0, 255],
|
|
55
|
+
getDirection: (x) => x.direction,
|
|
56
|
+
getMarkerPercentages: (object, {lineLength}) =>
|
|
57
|
+
lineLength > DISTANCE_FOR_MULTI_ARROWS ? [0.25, 0.5, 0.75] : [0.5]
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export class PathMarkerLayer<
|
|
62
|
+
DataT = any,
|
|
63
|
+
ExtraPropsT = Record<string, unknown>
|
|
64
|
+
> extends CompositeLayer<ExtraPropsT & Required<PathMarkerLayerProps<DataT>>> {
|
|
65
|
+
static layerName = 'PathMarkerLayer';
|
|
66
|
+
static defaultProps = defaultProps;
|
|
67
|
+
|
|
68
|
+
state: {
|
|
69
|
+
closestPoint: Vector3 | null;
|
|
70
|
+
closestPoints?: {position: Vector3}[];
|
|
71
|
+
markers: any[];
|
|
72
|
+
mesh: Arrow2DGeometry;
|
|
73
|
+
} = undefined!;
|
|
74
|
+
|
|
75
|
+
initializeState() {
|
|
76
|
+
this.state = {
|
|
77
|
+
markers: [],
|
|
78
|
+
mesh: new Arrow2DGeometry({headSize: ARROW_HEAD_SIZE, tailWidth: ARROW_TAIL_WIDTH}),
|
|
79
|
+
closestPoint: null,
|
|
80
|
+
closestPoints: []
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
projectFlat(xyz, viewport, coordinateSystem, coordinateOrigin) {
|
|
85
|
+
if (coordinateSystem === COORDINATE_SYSTEM.METER_OFFSETS) {
|
|
86
|
+
const [dx, dy] = viewport.metersToLngLatDelta(xyz);
|
|
87
|
+
const [x, y] = coordinateOrigin;
|
|
88
|
+
return viewport.projectFlat([x + dx, dy + y]);
|
|
89
|
+
} else if (coordinateSystem === COORDINATE_SYSTEM.LNGLAT_OFFSETS) {
|
|
90
|
+
const [dx, dy] = xyz;
|
|
91
|
+
const [x, y] = coordinateOrigin;
|
|
92
|
+
return viewport.projectFlat([x + dx, dy + y]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return viewport.projectFlat(xyz);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
updateState({props, oldProps, changeFlags}) {
|
|
99
|
+
if (changeFlags.dataChanged || changeFlags.updateTriggersChanged) {
|
|
100
|
+
const {
|
|
101
|
+
data,
|
|
102
|
+
getPath,
|
|
103
|
+
getDirection,
|
|
104
|
+
getMarkerColor,
|
|
105
|
+
getMarkerPercentages,
|
|
106
|
+
coordinateSystem,
|
|
107
|
+
coordinateOrigin
|
|
108
|
+
} = this.props;
|
|
109
|
+
|
|
110
|
+
const {viewport} = this.context;
|
|
111
|
+
const projectFlat = (o) => this.projectFlat(o, viewport, coordinateSystem, coordinateOrigin);
|
|
112
|
+
this.state.markers = createPathMarkers({
|
|
113
|
+
data,
|
|
114
|
+
getPath,
|
|
115
|
+
getDirection,
|
|
116
|
+
getColor: getMarkerColor,
|
|
117
|
+
getMarkerPercentages,
|
|
118
|
+
projectFlat
|
|
119
|
+
});
|
|
120
|
+
this._recalculateClosestPoint();
|
|
121
|
+
}
|
|
122
|
+
if (changeFlags.propsChanged) {
|
|
123
|
+
if (props.point !== oldProps.point) {
|
|
124
|
+
this._recalculateClosestPoint();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
_recalculateClosestPoint() {
|
|
130
|
+
const {highlightPoint, highlightIndex} = this.props;
|
|
131
|
+
if (highlightPoint && highlightIndex >= 0) {
|
|
132
|
+
const object = this.props.data[highlightIndex];
|
|
133
|
+
const points = this.props.getPath(object, null as any);
|
|
134
|
+
const {point} = getClosestPointOnPolyline({points, p: highlightPoint});
|
|
135
|
+
this.state.closestPoints = [{position: point}];
|
|
136
|
+
} else {
|
|
137
|
+
this.state.closestPoints = [];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
getPickingInfo({info}) {
|
|
142
|
+
return Object.assign(info, {
|
|
143
|
+
// override object with picked feature
|
|
144
|
+
object: (info.object && info.object.path) || info.object
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
renderLayers() {
|
|
149
|
+
return [
|
|
150
|
+
new PathOutlineLayer(
|
|
151
|
+
this.props,
|
|
152
|
+
this.getSubLayerProps({
|
|
153
|
+
id: 'paths',
|
|
154
|
+
// Note: data has to be passed explicitly like this to avoid being empty
|
|
155
|
+
data: this.props.data
|
|
156
|
+
})
|
|
157
|
+
),
|
|
158
|
+
new this.props.MarkerLayer(
|
|
159
|
+
this.getSubLayerProps(
|
|
160
|
+
Object.assign({}, this.props.markerLayerProps, {
|
|
161
|
+
id: 'markers',
|
|
162
|
+
data: this.state.markers,
|
|
163
|
+
getOrientation: (x) => [0, -x.angle, 0],
|
|
164
|
+
getColor: (x) => x.color,
|
|
165
|
+
sizeScale: this.props.sizeScale,
|
|
166
|
+
fp64: this.props.fp64,
|
|
167
|
+
pickable: false,
|
|
168
|
+
parameters: {
|
|
169
|
+
blend: false,
|
|
170
|
+
depthTest: false
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
)
|
|
174
|
+
),
|
|
175
|
+
this.state.closestPoints &&
|
|
176
|
+
new ScatterplotLayer({
|
|
177
|
+
id: `${this.props.id}-highlight`,
|
|
178
|
+
data: this.state.closestPoints,
|
|
179
|
+
fp64: this.props.fp64
|
|
180
|
+
})
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Vector3, clamp} from '@math.gl/core';
|
|
6
|
+
|
|
7
|
+
// Return the closest point on a line segment
|
|
8
|
+
export function getClosestPointOnLine({p, p1, p2, clampToLine = true}) {
|
|
9
|
+
const lineVector = new Vector3(p2).subtract(p1);
|
|
10
|
+
const pointVector = new Vector3(p).subtract(p1);
|
|
11
|
+
let dotProduct = lineVector.dot(pointVector);
|
|
12
|
+
if (clampToLine) {
|
|
13
|
+
dotProduct = clamp(dotProduct, 0, 1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return lineVector.lerp(p1, p2, dotProduct);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Return the closest point on a line segment
|
|
20
|
+
export function getClosestPointOnPolyline({p, points}) {
|
|
21
|
+
p = new Vector3(p);
|
|
22
|
+
let pClosest: Vector3 | null = null;
|
|
23
|
+
let distanceSquared = Infinity;
|
|
24
|
+
let index = -1;
|
|
25
|
+
for (let i = 0; i < points.length - 1; ++i) {
|
|
26
|
+
const p1 = points[i];
|
|
27
|
+
const p2 = points[i + 1];
|
|
28
|
+
const pClosestOnLine = getClosestPointOnLine({p, p1, p2});
|
|
29
|
+
const distanceToLineSquared = p.distanceSquared(pClosestOnLine);
|
|
30
|
+
if (distanceToLineSquared < distanceSquared) {
|
|
31
|
+
distanceSquared = distanceToLineSquared;
|
|
32
|
+
pClosest = pClosestOnLine;
|
|
33
|
+
index = i;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
point: pClosest,
|
|
38
|
+
index,
|
|
39
|
+
p1: points[index],
|
|
40
|
+
p2: points[index + 1],
|
|
41
|
+
distanceSquared,
|
|
42
|
+
distance: Math.sqrt(distanceSquared)
|
|
43
|
+
};
|
|
44
|
+
}
|