Skip to content

Commit

Permalink
feat: represent bearing as geographic terms (#1009)
Browse files Browse the repository at this point in the history
Co-authored-by: Guyke5 <[email protected]>
  • Loading branch information
GuyKe5 and Guy5ke authored Feb 2, 2025
1 parent 69660b7 commit c74509a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/locale/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@
"at_time": "בשעה",
"vehicle_ref": "לוחית רישוי",
"drive_direction": "כיוון נסיעה",
"directions":{
"North": "צפון",
"Northeast": "צפון-מזרח",
"East": "מזרח",
"Southeast": "דרום-מזרח",
"South": "דרום",
"Southwest": "דרום-מערב",
"West": "מערב",
"Northwest": "צפון-מערב"
},
"bearing": "מעלות",
"coords": "נ.צ.",
"hide_document": "הסתר מידע לגיקים",
Expand Down
28 changes: 27 additions & 1 deletion src/pages/components/map-related/MapLayers/BusToolTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ export function BusToolTip({ position, icon, children }: BusToolTipProps) {
.finally(() => setIsLoading(false))
}, [position])

function getDirectionFromAngle(angle: number): string {
// Normalize the angle to the range 0-360
angle = ((angle % 360) + 360) % 360
// Define the cardinal directions in clockwise order
const directions: string[] = [
t('directions.North', { defaultValue: 'North' }),
t('directions.Northeast', { defaultValue: 'Northeast' }),
t('directions.East', { defaultValue: 'East' }),
t('directions.Southeast', { defaultValue: 'Southeast' }),
t('directions.South', { defaultValue: 'South' }),
t('directions.Southwest', { defaultValue: 'Southwest' }),
t('directions.West', { defaultValue: 'West' }),
t('directions.Northwest', { defaultValue: 'Northwest' }),
]
// Divide the angle into 8 equal sections (45 degrees each)
const index: number = Math.round(angle / 45) % 8

return directions[index]
}

return (
<div className={cn('bus-tooltip', { hebrew: i18n.language === 'he' })}>
{isLoading || !siriRide ? (
Expand All @@ -56,6 +76,7 @@ export function BusToolTip({ position, icon, children }: BusToolTipProps) {
<div className="content">
<ul>
<li>
{' '}
{`${t('from')}: `}
<span>{siriRide.gtfsRouteRouteLongName?.split('<->')[0]}</span>
</li>
Expand Down Expand Up @@ -83,7 +104,12 @@ export function BusToolTip({ position, icon, children }: BusToolTipProps) {
<li>
{`${t('drive_direction')}: `}
<span>
({position.point?.bearing} {t('bearing')})
{/* ({position.point?.bearing} {t('bearing')}) */}
{position.point?.bearing} {t('bearing')} (
{position.point?.bearing !== undefined
? getDirectionFromAngle(position.point.bearing)
: t('unknown', { defaultValue: 'unknown' })}
)
</span>
</li>
<li>
Expand Down

0 comments on commit c74509a

Please sign in to comment.