近くの駅の情報がとりあえず出るようになった

This commit is contained in:
harukin-expo-dev-env 2025-04-13 16:17:15 +00:00
parent 6d51db98fa
commit 2c505c4b17
2 changed files with 22 additions and 12 deletions

33
menu.js
View File

@ -35,7 +35,9 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
const { bottom, left, right, top } = useSafeAreaInsets(); const { bottom, left, right, top } = useSafeAreaInsets();
const tabBarHeight = useBottomTabBarHeight(); const tabBarHeight = useBottomTabBarHeight();
const [mapsOpacity, setMapsOpacity] = useState(false); const [mapsOpacity, setMapsOpacity] = useState(false);
const [stationListMode, setStationListMode] = useState/*<"position"|"favorite">*/("position"); const [stationListMode, setStationListMode] = useState(
/*<"position"|"favorite">*/ "position"
);
const mapsRef = useRef(null); const mapsRef = useRef(null);
const MapHeight = const MapHeight =
height - height -
@ -59,11 +61,11 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
useEffect(() => { useEffect(() => {
if (!position) return () => {}; if (!position) return () => {};
makeCurrentStation(position); makeCurrentStation(position);
}, [position]); }, [position, stationListMode]);
const makeCurrentStation = (location) => { const makeCurrentStation = (location) => {
if (!originalStationList) return () => {}; if (!originalStationList) return () => {};
const findStationEachLine = (selectLine) => { const findStationEachLine = (selectLine) => {
const searchArea = stationListMode == "position" ? 0.1 : 0.002; const searchArea = stationListMode == "position" ? 0.07 : 0.002;
const _calcDistance = (from, to) => { const _calcDistance = (from, to) => {
let lat = Math.abs(from.lat - to.lat); let lat = Math.abs(from.lat - to.lat);
let lng = Math.abs(from.lng - to.lng); let lng = Math.abs(from.lng - to.lng);
@ -104,17 +106,17 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
const [allStationData, setAllStationData] = useState([]); const [allStationData, setAllStationData] = useState([]);
useEffect(() => { useEffect(() => {
if(stationListMode == "position"){ if (stationListMode == "position") {
console.log(currentStation);
setAllStationData( setAllStationData(
[currentStation].filter((d) => d != undefined) [currentStation].filter((d) => d != undefined)
); );
}else{ } else {
setAllStationData( setAllStationData(
[currentStation, ...favoriteStation].filter((d) => d != undefined) [currentStation, ...favoriteStation].filter((d) => d != undefined)
); );
} }
}, [currentStation, favoriteStation,stationListMode]); }, [currentStation, favoriteStation, stationListMode]);
useEffect(() => { useEffect(() => {
if (allStationData.length == 0) { if (allStationData.length == 0) {
setSelectedCurrentStation(0); setSelectedCurrentStation(0);
@ -186,7 +188,16 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
}} }}
onPress={() => alert("地図をタップ")} onPress={() => alert("地図をタップ")}
/> />
<CarouselTypeChanger {...{ locationStatus, position, mapsRef,stationListMode, setStationListMode,setSelectedCurrentStation }} /> <CarouselTypeChanger
{...{
locationStatus,
position,
mapsRef,
stationListMode,
setStationListMode,
setSelectedCurrentStation,
}}
/>
{allStationData.length != 0 && originalStationList.length != 0 && ( {allStationData.length != 0 && originalStationList.length != 0 && (
<> <>
<CarouselBox <CarouselBox

View File

@ -36,7 +36,6 @@ export const StationListProvider: FC<Props> = ({ children }) => {
getStationList().then(setOriginalStationList); getStationList().then(setOriginalStationList);
}, []); }, []);
const getStationDataFromId: (id: string) => any[] = (id) => { const getStationDataFromId: (id: string) => any[] = (id) => {
console.log("id", id);
let returnArray = []; let returnArray = [];
Object.keys(originalStationList).forEach((key) => { Object.keys(originalStationList).forEach((key) => {
originalStationList[key].forEach((station) => { originalStationList[key].forEach((station) => {