マップのメモ化

This commit is contained in:
harukin-expo-dev-env 2024-03-26 05:21:16 +00:00
parent b45c2cf951
commit aa0daeb791

View File

@ -1,4 +1,4 @@
import React, { useRef } from "react"; import React, { useRef, useMemo } from "react";
import { View, Text, TouchableOpacity, Linking } from "react-native"; import { View, Text, TouchableOpacity, Linking } from "react-native";
import MapView, { Marker } from "react-native-maps"; import MapView, { Marker } from "react-native-maps";
import { MaterialCommunityIcons } from "@expo/vector-icons"; import { MaterialCommunityIcons } from "@expo/vector-icons";
@ -9,6 +9,35 @@ export default function TrainMenu({
style, style,
}) { }) {
const mapRef = useRef(); const mapRef = useRef();
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 (
<Marker
key={index + indexBase}
coordinate={{
latitude: parseFloat(latlng[0]),
longitude: parseFloat(latlng[1]),
}}
onPress={() => {
webview.current?.injectJavaScript(
`MoveDisplayStation('${d}_${D.MyStation}_${D.Station_JP}')`
);
if (navigate) navigate("Apps");
}}
></Marker>
);
})
),
[stationData]
);
return ( return (
<View style={{ height: "100%", backgroundColor: "#0099CC", ...style }}> <View style={{ height: "100%", backgroundColor: "#0099CC", ...style }}>
<MapView <MapView
@ -27,32 +56,7 @@ export default function TrainMenu({
longitudeDelta: 1.8, longitudeDelta: 1.8,
}} }}
> >
{stationData && {stationPin}
Object.keys(stationData).map((d) =>
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 (
<Marker
key={index}
coordinate={{
latitude: parseFloat(latlng[0]),
longitude: parseFloat(latlng[1]),
}}
onPress={() => {
webview.current?.injectJavaScript(
`MoveDisplayStation('${d}_${D.MyStation}_${D.Station_JP}')`
);
if (navigate) navigate("Apps");
}}
></Marker>
);
})
)}
</MapView> </MapView>
{navigate && ( {navigate && (
<View style={{ flexDirection: "row" }}> <View style={{ flexDirection: "row" }}>