import React, { useRef, useState, useEffect } from "react"; import { View, Text, TouchableOpacity, Linking } from "react-native"; import MapView, { Marker } from "react-native-maps"; import { MaterialCommunityIcons } from "@expo/vector-icons"; import { useCurrentTrain } from "../stateBox/useCurrentTrain"; import { useNavigation } from "@react-navigation/native"; import lineColorList from "../assets/originData/lineColorList"; import { stationIDPair } from "../lib/getStationList2"; import { lineListPair } from "../lib/getStationList"; export default function TrainMenu({ stationData, style }) { const { webview } = useCurrentTrain(); const mapRef = useRef(); const { navigate } = useNavigation(); const [stationPin, setStationPin] = useState([]); const [selectedLine, setSelectedLine] = useState(undefined); useEffect(() => { const stationPinData = []; Object.keys(stationData).map((d, indexBase) => stationData[d].map((D, index) => { if (!D.StationMap) return null; if (selectedLine && selectedLine != d) return; const latlng = D.StationMap.replace( "https://www.google.co.jp/maps/place/", "" ).split(","); if (latlng.length == 0) return null; stationPinData.push({ D, d, latlng, indexBase: 0, index }); }) ); setStationPin(stationPinData); }, [stationData, selectedLine]); useEffect(() => { mapRef.current.fitToCoordinates( stationPin.map(({ latlng }) => ({ latitude: parseFloat(latlng[0]), longitude: parseFloat(latlng[1]), })), { edgePadding: { top: 100, bottom: 50, left: 50, right: 50 } } // Add margin values here ); }, [stationPin]); return ( {selectedLine && ( {selectedLine ? lineListPair[stationIDPair[selectedLine]] : "全線"} )} {stationPin.map(({ D, d, latlng, indexBase, index }) => ( ))} 路線記号からフィルタリング {Object.keys(stationData).map((d) => ( setSelectedLine(selectedLine == d ? undefined : d)} > {stationIDPair[d]} ))} {navigate && ( navigate("howto", { info: "https://train.jr-shikoku.co.jp/usage.htm", }) } > 使い方 navigate("favoriteList")} > お気に入り Linking.openURL( "https://nexcloud.haruk.in/apps/forms/ZRHjWFF7znr5Xjr2" ) } > フィードバック )} {navigate && ( navigate("Apps")} > 閉じる )} ); } const UsefulBox = (props) => { const { icon, backgroundColor, flex, onPressButton, children } = props; return ( {children} ); }; const MapPin = ({ index, indexBase, latlng, D, d, navigate, webview }) => { return ( { webview.current?.injectJavaScript( `MoveDisplayStation('${d}_${D.MyStation}_${D.Station_JP}'); document.getElementById("disp").insertAdjacentHTML("afterbegin", "
");` ); if (navigate) navigate("Apps"); }} > ); };