From aff1383bebda35f8a153b6d3a30926c4f6177030 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Sun, 28 Apr 2024 02:09:11 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=9E=E3=83=83=E3=83=97=E3=81=AE=E8=B7=AF?= =?UTF-8?q?=E7=B7=9A=E5=88=A5=E9=A7=85=E9=81=B8=E6=8A=9E=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/trainMenu.js | 122 +++++++++++++++++++++++++++++----------- lib/getStationList2.js | 13 ++++- 2 files changed, 102 insertions(+), 33 deletions(-) diff --git a/components/trainMenu.js b/components/trainMenu.js index 13876a0..b075037 100644 --- a/components/trainMenu.js +++ b/components/trainMenu.js @@ -1,43 +1,40 @@ -import React, { useRef, useMemo } from "react"; +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"; export default function TrainMenu({ stationData, style }) { const { webview } = useCurrentTrain(); const mapRef = useRef(); const { navigate } = useNavigation(); - const stationPin = useMemo( - () => - Object.keys(stationData).map((d, indexBase) => - stationData[d].map((D, index) => { - if (!D.StationMap) return null; - const latlng = D.StationMap.replace( - "https://www.google.co.jp/maps/place/", - "" - ).split(","); - if (latlng.length == 0) return null; - return ( - { - webview.current?.injectJavaScript( - `MoveDisplayStation('${d}_${D.MyStation}_${D.Station_JP}'); - setStrings();` - ); - if (navigate) navigate("Apps"); - }} - > - ); - }) - ), - [stationData] - ); + const [stationPin, setStationPin] = useState([]); + useEffect(() => { + const stationPinData = []; + Object.keys(stationData).map((d, indexBase) => + stationData[d].map((D, index) => { + if (!D.StationMap) return null; + 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]); + useEffect(() => { + mapRef.current.fitToCoordinates( + stationPin.map(({ latlng }) => ({ + latitude: parseFloat(latlng[0]), + longitude: parseFloat(latlng[1]), + })), + { edgePadding: { top: 50, bottom: 50, left: 50, right: 50 } } // Add margin values here + ); + }, [stationPin]); return ( - {stationPin} + {stationPin.map(({ D, d, latlng, indexBase, index }) => ( + + ))} + + {Object.keys(stationData).map((d) => ( + { + setStationPin( + stationData[d].map((D, index) => { + if (!D.StationMap) return null; + const latlng = D.StationMap.replace( + "https://www.google.co.jp/maps/place/", + "" + ).split(","); + if (latlng.length == 0) return null; + return { D, d, latlng, indexBase: 0, index }; + }) + ); + }} + > + + {stationIDPair[d]} + + + ))} + {navigate && ( { ); }; + +const MapPin = ({ index, indexBase, latlng, D, d, navigate, webview }) => { + return ( + { + webview.current?.injectJavaScript( + `MoveDisplayStation('${d}_${D.MyStation}_${D.Station_JP}'); + setStrings();` + ); + if (navigate) navigate("Apps"); + }} + > + ); +}; diff --git a/lib/getStationList2.js b/lib/getStationList2.js index a8b392b..11397b8 100644 --- a/lib/getStationList2.js +++ b/lib/getStationList2.js @@ -1,4 +1,3 @@ -let status = undefined; import yosan from "../assets/originData/yosan"; import uwajima from "../assets/originData/uwajima"; import uwajima2 from "../assets/originData/uwajima2"; @@ -21,3 +20,15 @@ export const getStationList2 = async (props) => { seto, }; }; + +export const stationIDPair = { + yosan: "Y", + uwajima: "U", + uwajima2: "S", + dosan: "D", + dosan2: "K", + koutoku: "T", + tokushima: "B", + naruto: "N", + seto: "M", +};