-
Notifications
You must be signed in to change notification settings - Fork 3
/
Vehicle.tsx
59 lines (56 loc) · 1.12 KB
/
Vehicle.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
56
57
58
59
import { Rect, Text } from "react-konva";
import React from "react";
import type { VehicleProps } from "./VehiclePath.types";
/**
* Component used to mark an x,y position with a vehicle (rectangle) on a 'Konva React' canvas.
*/
const Vehicle = (
{
height = 5,
width = 2,
x,
y,
yaw = 0,
color = "#FFAF2C",
label = ""
}: VehicleProps,
key: React.Key
) => {
const rotation = ((yaw * 180) / Math.PI - 90) * -1;
return (
<>
<Rect
x={x}
y={y}
offsetX={width / 2}
offsetY={height}
width={width}
height={height}
rotation={rotation}
key={key}
fill={color}
/>
{/* Only render text if label given */}
{label && (
<Text
text={label}
width={5}
height={3}
wrap="char"
ellipsis={true}
x={x}
y={y}
offset={{
x: 2.5,
y: 0
}}
rotation={rotation}
verticalAlign="top"
align="center"
fontSize={1.5}
/>
)}
</>
);
};
export default Vehicle;