各駅停車と駅に止まっている列車の現在地を表示可能に
This commit is contained in:
parent
92b9a4a044
commit
4446019ab2
@ -81,11 +81,89 @@ export const EachTrainInfo = ({
|
|||||||
return StationNumbers[0];
|
return StationNumbers[0];
|
||||||
});
|
});
|
||||||
function findReversalPoints(array) {
|
function findReversalPoints(array) {
|
||||||
return null;
|
// arrayは現在位置の駅ID(駅在宅の場合は1つの配列、駅間の場合は2つの配列)
|
||||||
|
// stopStationIDListは停車駅の駅IDの配列
|
||||||
|
const arrayNumber = array.map((d) => ({
|
||||||
|
line: d
|
||||||
|
.split("")
|
||||||
|
.filter((s) => "A" < s && s < "Z")
|
||||||
|
.join(""),
|
||||||
|
ID: d
|
||||||
|
.split("")
|
||||||
|
.filter((s) => "0" <= s && s <= "9")
|
||||||
|
.join(""),
|
||||||
|
}));
|
||||||
|
const stopStationIDListNumber = stopStationIDList.map((d) => {
|
||||||
|
if (!d) return { line: [], ID: [] };
|
||||||
|
return {
|
||||||
|
line: d
|
||||||
|
.split("")
|
||||||
|
.filter((s) => "A" < s && s < "Z")
|
||||||
|
.join(""),
|
||||||
|
ID: d
|
||||||
|
.split("")
|
||||||
|
.filter((s) => "0" <= s && s <= "9")
|
||||||
|
.join(""),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// 完全一致
|
||||||
|
if (array.length == 1) {
|
||||||
|
const index = stopStationIDList.indexOf(array[0]);
|
||||||
|
if (index != -1) return [index];
|
||||||
|
// 通過駅の場合
|
||||||
|
for (let i = 0; i < stopStationIDListNumber.length - 1; i++) {
|
||||||
|
if (stopStationIDListNumber[i].ID < arrayNumber[0].ID) {
|
||||||
|
if (stopStationIDListNumber[i + 1].ID > arrayNumber[0].ID) {
|
||||||
|
return [i + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stopStationIDListNumber[i].ID > arrayNumber[0].ID) {
|
||||||
|
if (stopStationIDListNumber[i + 1].ID < arrayNumber[0].ID) {
|
||||||
|
return [i + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 駅間の場合
|
||||||
|
if (array.length == 2) {
|
||||||
|
const index1 = stopStationIDList.indexOf(array[0]);
|
||||||
|
const index2 = stopStationIDList.indexOf(array[1]);
|
||||||
|
console.log(index1, index2);
|
||||||
|
if (index1 != -1 && index2 != -1) {
|
||||||
|
// 駅間で通過駅も無い場合
|
||||||
|
if (index1 < index2) {
|
||||||
|
if (index1 + 1 == index2) {
|
||||||
|
return [index2];
|
||||||
|
} else {
|
||||||
|
const returnArray = [];
|
||||||
|
for (let i = index1 + 1; i <= index2; i++) {
|
||||||
|
returnArray.push(i);
|
||||||
|
}
|
||||||
|
return returnArray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index1 > index2) {
|
||||||
|
if (index2 + 1 == index1) return [index1];
|
||||||
|
else {
|
||||||
|
const returnArray = [];
|
||||||
|
for (let i = index2 + 1; i <= index1; i++) {
|
||||||
|
returnArray.push(i);
|
||||||
|
}
|
||||||
|
return returnArray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
|
// 通過駅の場合
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用例
|
// 使用例
|
||||||
const points = findReversalPoints(currentPosition);
|
const points = findReversalPoints(currentPosition);
|
||||||
|
console.log(points);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
@ -435,7 +513,7 @@ export const EachTrainInfo = ({
|
|||||||
>
|
>
|
||||||
見込
|
見込
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={{ fontSize: 20, width: 50 }}>着発</Text>
|
<Text style={{ fontSize: 20, width: 50 }}></Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
@ -537,6 +615,9 @@ export const EachTrainInfo = ({
|
|||||||
>
|
>
|
||||||
<Text style={{ fontSize: 20 }}>{station}</Text>
|
<Text style={{ fontSize: 20 }}>{station}</Text>
|
||||||
<View style={{ flex: 1 }} />
|
<View style={{ flex: 1 }} />
|
||||||
|
{points.findIndex((d) => d == index) >= 0 ? (
|
||||||
|
<Text>ほげ</Text>
|
||||||
|
) : null}
|
||||||
{!isNaN(data.trainData?.delay) &&
|
{!isNaN(data.trainData?.delay) &&
|
||||||
data.trainData?.delay != 0 && (
|
data.trainData?.delay != 0 && (
|
||||||
<Text
|
<Text
|
||||||
@ -566,7 +647,9 @@ export const EachTrainInfo = ({
|
|||||||
>
|
>
|
||||||
{timeString[0]}:{timeString[1]}
|
{timeString[0]}:{timeString[1]}
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={{ fontSize: 18, width: 50 }}>({se})</Text>
|
<Text style={{ fontSize: 18, width: 50 }}>
|
||||||
|
{se?.replace("発", "出発").replace("着", "到着")}
|
||||||
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</TouchableWithoutFeedback>
|
</TouchableWithoutFeedback>
|
||||||
|
Loading…
Reference in New Issue
Block a user