Skip to content

Commit 2a3a34a

Browse files
Fix: Improve getDirectionFromOrientation function
1 parent 0d64bc9 commit 2a3a34a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/lib/MapHelpers/generateVehicleIcon.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ const DIRECTIONS = [
1212
];
1313

1414
function getDirectionFromOrientation(orientation) {
15-
const nearestDirection = DIRECTIONS.reduce((prev, curr) =>
16-
Math.abs(curr.angle - orientation) < Math.abs(prev.angle - orientation) ? curr : prev
15+
if (DIRECTIONS.length === 0) {
16+
return null;
17+
}
18+
19+
const nearestDirection = DIRECTIONS.reduce(
20+
(prev, curr) =>
21+
Math.abs(curr.angle - orientation) < Math.abs(prev.angle - orientation) ? curr : prev,
22+
DIRECTIONS[0]
1723
);
1824
return nearestDirection.icon;
1925
}

0 commit comments

Comments
 (0)