forked from City-of-Helsinki/servicemap-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into depedency/update-babel-core
Merge branch 'develop'.
- Loading branch information
Showing
22 changed files
with
570 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/components/MobilityPlatform/RailwayStations/RailwayStations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useMap } from 'react-leaflet'; | ||
import railwayIcon from 'servicemap-ui-turku/assets/icons/icons-icon_railway_station.svg'; | ||
import railwayIconBw from 'servicemap-ui-turku/assets/icons/contrast/icons-icon_railway_station-bw.svg'; | ||
import { useMobilityPlatformContext } from '../../../context/MobilityPlatformContext'; | ||
import { useAccessibleMap } from '../../../redux/selectors/settings'; | ||
import { fetchRailwaysData } from '../mobilityPlatformRequests/mobilityPlatformRequests'; | ||
import { createIcon, isDataValid } from '../utils/utils'; | ||
import RailwayStationsContent from './components/RailwayStationsContent'; | ||
|
||
const RailwayStations = () => { | ||
const [railwayStations, setRailwayStations] = useState([]); | ||
|
||
const { showRailwayStations } = useMobilityPlatformContext(); | ||
|
||
const map = useMap(); | ||
|
||
const { Marker, Popup } = global.rL; | ||
const { icon } = global.L; | ||
|
||
const useContrast = useSelector(useAccessibleMap); | ||
|
||
const customIcon = icon(createIcon(useContrast ? railwayIconBw : railwayIcon)); | ||
|
||
useEffect(() => { | ||
if (showRailwayStations && !railwayStations.length) { | ||
fetchRailwaysData('metadata/stations', setRailwayStations); | ||
} | ||
}, [showRailwayStations]); | ||
|
||
/** Separate railway stations of Turku, eg. Turku station and Kupittaa */ | ||
const turkuStationCodes = ['TKU', 'KUT', 'TUS']; | ||
const railwayStationsTku = railwayStations.filter(curr => turkuStationCodes.includes(curr.stationShortCode)); | ||
|
||
const renderData = isDataValid(showRailwayStations, railwayStationsTku); | ||
|
||
useEffect(() => { | ||
if (renderData) { | ||
const bounds = []; | ||
railwayStationsTku.forEach(item => { | ||
bounds.push([item.latitude, item.longitude]); | ||
}); | ||
map.fitBounds(bounds); | ||
} | ||
}, [showRailwayStations, railwayStationsTku]); | ||
|
||
return renderData | ||
? railwayStationsTku.map(item => ( | ||
<Marker key={item.stationName} icon={customIcon} position={[item.latitude, item.longitude]}> | ||
<Popup> | ||
<RailwayStationsContent item={item} stationsData={railwayStations} /> | ||
</Popup> | ||
</Marker> | ||
)) | ||
: null; | ||
}; | ||
|
||
export default RailwayStations; |
Oops, something went wrong.