({ filter }: Props)
| 109 | }; |
| 110 | |
| 111 | export default function Map({ filter }: Props) { |
| 112 | const showCornerNumbers = useSettingsStore((state) => state.showCornerNumbers); |
| 113 | const favoriteDrivers = useSettingsStore((state) => state.favoriteDrivers); |
| 114 | |
| 115 | // const positions = useDataStore((state) => state.positions); |
| 116 | const drivers = useDataStore((state) => state?.state?.DriverList); |
| 117 | const trackStatus = useDataStore((state) => state?.state?.TrackStatus); |
| 118 | const timingDrivers = useDataStore((state) => state?.state?.TimingData); |
| 119 | const raceControlMessages = useDataStore((state) => state?.state?.RaceControlMessages?.Messages ?? undefined); |
| 120 | const circuitKey = useDataStore((state) => state?.state?.SessionInfo?.Meeting.Circuit.Key); |
| 121 | |
| 122 | const [[minX, minY, widthX, widthY], setBounds] = useState<(null | number)[]>([null, null, null, null]); |
| 123 | const [[centerX, centerY], setCenter] = useState<(null | number)[]>([null, null]); |
| 124 | |
| 125 | const [points, setPoints] = useState<null | { x: number; y: number }[]>(null); |
| 126 | const [sectors, setSectors] = useState<MapSector[]>([]); |
| 127 | const [corners, setCorners] = useState<Corner[]>([]); |
| 128 | const [rotation, setRotation] = useState<number>(0); |
| 129 | const [finishLine, setFinishLine] = useState<null | { x: number; y: number; startAngle: number }>(null); |
| 130 | const [originalTrackPoints, setOriginalTrackPoints] = useState<null | { x: number; y: number }[]>(null); |
| 131 | |
| 132 | useEffect(() => { |
| 133 | (async () => { |
| 134 | if (!circuitKey) return; |
| 135 | const mapJson = await fetchMap(circuitKey); |
| 136 | |
| 137 | if (!mapJson) return; |
| 138 | |
| 139 | const centerX = (Math.max(...mapJson.x) - Math.min(...mapJson.x)) / 2; |
| 140 | const centerY = (Math.max(...mapJson.y) - Math.min(...mapJson.y)) / 2; |
| 141 | |
| 142 | const fixedRotation = mapJson.rotation + ROTATION_FIX; |
| 143 | |
| 144 | const sectors = createSectors(mapJson).map((s) => ({ |
| 145 | ...s, |
| 146 | start: rotate(s.start.x, s.start.y, fixedRotation, centerX, centerY), |
| 147 | end: rotate(s.end.x, s.end.y, fixedRotation, centerX, centerY), |
| 148 | points: s.points.map((p) => rotate(p.x, p.y, fixedRotation, centerX, centerY)), |
| 149 | })); |
| 150 | |
| 151 | const cornerPositions: Corner[] = mapJson.corners.map((corner) => ({ |
| 152 | number: corner.number, |
| 153 | pos: rotate(corner.trackPosition.x, corner.trackPosition.y, fixedRotation, centerX, centerY), |
| 154 | labelPos: rotate( |
| 155 | corner.trackPosition.x + 540 * Math.cos(rad(corner.angle)), |
| 156 | corner.trackPosition.y + 540 * Math.sin(rad(corner.angle)), |
| 157 | fixedRotation, |
| 158 | centerX, |
| 159 | centerY, |
| 160 | ), |
| 161 | })); |
| 162 | |
| 163 | const rotatedPoints = mapJson.x.map((x, index) => rotate(x, mapJson.y[index], fixedRotation, centerX, centerY)); |
| 164 | |
| 165 | const pointsX = rotatedPoints.map((item) => item.x); |
| 166 | const pointsY = rotatedPoints.map((item) => item.y); |
| 167 | |
| 168 | const cMinX = Math.min(...pointsX) - SPACE; |
nothing calls this directly
no test coverage detected