Skip to content

Commit c74509a

Browse files
GuyKe5Guy5ke
andauthored
feat: represent bearing as geographic terms (#1009)
Co-authored-by: Guyke5 <[email protected]>
1 parent 69660b7 commit c74509a

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/locale/he.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@
154154
"at_time": "בשעה",
155155
"vehicle_ref": "לוחית רישוי",
156156
"drive_direction": "כיוון נסיעה",
157+
"directions":{
158+
"North": "צפון",
159+
"Northeast": "צפון-מזרח",
160+
"East": "מזרח",
161+
"Southeast": "דרום-מזרח",
162+
"South": "דרום",
163+
"Southwest": "דרום-מערב",
164+
"West": "מערב",
165+
"Northwest": "צפון-מערב"
166+
},
157167
"bearing": "מעלות",
158168
"coords": "נ.צ.",
159169
"hide_document": "הסתר מידע לגיקים",

src/pages/components/map-related/MapLayers/BusToolTip.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ export function BusToolTip({ position, icon, children }: BusToolTipProps) {
3333
.finally(() => setIsLoading(false))
3434
}, [position])
3535

36+
function getDirectionFromAngle(angle: number): string {
37+
// Normalize the angle to the range 0-360
38+
angle = ((angle % 360) + 360) % 360
39+
// Define the cardinal directions in clockwise order
40+
const directions: string[] = [
41+
t('directions.North', { defaultValue: 'North' }),
42+
t('directions.Northeast', { defaultValue: 'Northeast' }),
43+
t('directions.East', { defaultValue: 'East' }),
44+
t('directions.Southeast', { defaultValue: 'Southeast' }),
45+
t('directions.South', { defaultValue: 'South' }),
46+
t('directions.Southwest', { defaultValue: 'Southwest' }),
47+
t('directions.West', { defaultValue: 'West' }),
48+
t('directions.Northwest', { defaultValue: 'Northwest' }),
49+
]
50+
// Divide the angle into 8 equal sections (45 degrees each)
51+
const index: number = Math.round(angle / 45) % 8
52+
53+
return directions[index]
54+
}
55+
3656
return (
3757
<div className={cn('bus-tooltip', { hebrew: i18n.language === 'he' })}>
3858
{isLoading || !siriRide ? (
@@ -56,6 +76,7 @@ export function BusToolTip({ position, icon, children }: BusToolTipProps) {
5676
<div className="content">
5777
<ul>
5878
<li>
79+
{' '}
5980
{`${t('from')}: `}
6081
<span>{siriRide.gtfsRouteRouteLongName?.split('<->')[0]}</span>
6182
</li>
@@ -83,7 +104,12 @@ export function BusToolTip({ position, icon, children }: BusToolTipProps) {
83104
<li>
84105
{`${t('drive_direction')}: `}
85106
<span>
86-
({position.point?.bearing} {t('bearing')})
107+
{/* ({position.point?.bearing} {t('bearing')}) */}
108+
{position.point?.bearing} {t('bearing')} (
109+
{position.point?.bearing !== undefined
110+
? getDirectionFromAngle(position.point.bearing)
111+
: t('unknown', { defaultValue: 'unknown' })}
112+
)
87113
</span>
88114
</li>
89115
<li>

0 commit comments

Comments
 (0)