-
Notifications
You must be signed in to change notification settings - Fork 3
/
VehiclePath.tsx
55 lines (52 loc) · 1.48 KB
/
VehiclePath.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Line } from "react-konva";
import Marker from "./Marker";
import React from "react";
import Vehicle from "./Vehicle";
import { VehiclePathProps } from "./VehiclePath.types";
const VehiclePath = (
{ path, index = 0, vehicle, showPath = true }: VehiclePathProps,
key: React.Key
) => {
// compute current x,y and yaw values
const x = path.x[index];
const y = path.y[index];
const yaw = path.yaw ? (path.yaw[index] ?? 0) : 0;
return (
<>
{/* Only show path/trajectory if showPath flag is 'true' */}
{showPath ? (
<Line
key={key}
strokeWidth={path.strokeWidth ?? 0.1}
stroke={path.color ?? "#FFAF2C"}
// zip the x and y points --> [x0, y0, x1, y1...]
points={path.x.flatMap((e, i) => [e, path.y[i]])}
/>
) : null}
{/* Render vehicle if vehicle exists and is type 'Vehicle' */}
{vehicle && "height" in vehicle ? (
<Vehicle
key={`vehicle_${key}`}
x={x}
y={y}
yaw={yaw}
height={vehicle.height}
width={vehicle.width}
color={vehicle.color}
label={vehicle.label}
/>
) : null}
{/* Render marker if vehicle defined and is type 'Marker' */}
{vehicle && "radius" in vehicle ? (
<Marker
key={`marker_${key}`}
x={x}
y={y}
radius={vehicle.radius}
color={vehicle.color}
/>
) : null}
</>
);
};
export default VehiclePath;