Skip to content

Commit df8a2e3

Browse files
authored
fix: changing map language (#981)
1 parent 9f5c1c2 commit df8a2e3

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/pages/components/map-related/MapContent.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { t } from 'i18next'
2-
import { useRef } from 'react'
2+
import { useRef, useEffect, useState } from 'react'
3+
import { useTranslation } from 'react-i18next'
34
import { Marker, Polyline, Popup, TileLayer, useMap } from 'react-leaflet'
45
import { Icon, IconOptions, Marker as LeafletMarker } from 'leaflet'
56
import { busIcon, busIconPath } from '../utils/BusIcon'
@@ -29,7 +30,6 @@ export function MapContent({ positions, plannedRouteStops, showNavigationButtons
2930
const plannedRouteLineColor = 'black'
3031
const actualRouteStopMarker = getIcon(actualRouteStopMarkerPath, 20, 20)
3132
const plannedRouteStopMarker = getIcon(plannedRouteStopMarkerPath, 20, 25)
32-
3333
const navigateMarkers = (positionId: number) => {
3434
const loc = positions[positionId]?.loc
3535
if (!map || !loc) return
@@ -39,12 +39,28 @@ export function MapContent({ positions, plannedRouteStops, showNavigationButtons
3939
marker.openPopup()
4040
}
4141
}
42+
const { i18n } = useTranslation()
43+
const [tileUrl, setTileUrl] = useState('https://tile-a.openstreetmap.fr/hot/{z}/{x}/{y}.png')
44+
useEffect(() => {
45+
const handleLanguageChange = (lng: string) => {
46+
console.log('Language changed to:', lng)
47+
const newUrl =
48+
lng === 'he'
49+
? 'https://tile-a.openstreetmap.fr/hot/{z}/{x}/{y}.png'
50+
: 'https://tile-a.openstreetmap.fr/osmfr/{z}/{x}/{y}.png?lang=en'
51+
setTileUrl(newUrl)
52+
}
53+
i18n.on('languageChanged', handleLanguageChange)
54+
return () => {
55+
i18n.off('languageChanged', handleLanguageChange)
56+
}
57+
}, [])
4258

4359
return (
4460
<>
4561
<TileLayer
4662
attribution='&copy <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
47-
url="https://tile-a.openstreetmap.fr/hot/{z}/{x}/{y}.png"
63+
url={tileUrl}
4864
/>
4965
<div className="map-index">
5066
<MapIndex

0 commit comments

Comments
 (0)