1
1
import { t } from 'i18next'
2
- import { useRef } from 'react'
2
+ import { useRef , useEffect , useState } from 'react'
3
+ import { useTranslation } from 'react-i18next'
3
4
import { Marker , Polyline , Popup , TileLayer , useMap } from 'react-leaflet'
4
5
import { Icon , IconOptions , Marker as LeafletMarker } from 'leaflet'
5
6
import { busIcon , busIconPath } from '../utils/BusIcon'
@@ -29,7 +30,6 @@ export function MapContent({ positions, plannedRouteStops, showNavigationButtons
29
30
const plannedRouteLineColor = 'black'
30
31
const actualRouteStopMarker = getIcon ( actualRouteStopMarkerPath , 20 , 20 )
31
32
const plannedRouteStopMarker = getIcon ( plannedRouteStopMarkerPath , 20 , 25 )
32
-
33
33
const navigateMarkers = ( positionId : number ) => {
34
34
const loc = positions [ positionId ] ?. loc
35
35
if ( ! map || ! loc ) return
@@ -39,12 +39,28 @@ export function MapContent({ positions, plannedRouteStops, showNavigationButtons
39
39
marker . openPopup ( )
40
40
}
41
41
}
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
+ } , [ ] )
42
58
43
59
return (
44
60
< >
45
61
< TileLayer
46
62
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 }
48
64
/>
49
65
< div className = "map-index" >
50
66
< MapIndex
0 commit comments