Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: represent bearing as geographic terms #1009

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading