203 lines
6.6 KiB
JavaScript
203 lines
6.6 KiB
JavaScript
import 予讃線 from "../assets/四国旅客鉄道予讃線.json";
|
||
import 土讃線 from "../assets/四国旅客鉄道土讃線.json";
|
||
import 高徳線 from "../assets/四国旅客鉄道高徳線.json";
|
||
import 内子線 from "../assets/四国旅客鉄道内子線.json";
|
||
import 徳島線 from "../assets/四国旅客鉄道徳島線.json";
|
||
import 鳴門線 from "../assets/四国旅客鉄道鳴門線.json";
|
||
import yosan from "../assets/originData/yosan";
|
||
import uwajima from "../assets/originData/uwajima";
|
||
import uwajima2 from "../assets/originData/uwajima2";
|
||
import dosan from "../assets/originData/dosan";
|
||
import dosan2 from "../assets/originData/dosan2";
|
||
import koutoku from "../assets/originData/koutoku";
|
||
import tokushima from "../assets/originData/tokushima";
|
||
import naruto from "../assets/originData/naruto";
|
||
|
||
let status = undefined;
|
||
|
||
export const getStationList = async (props) => {
|
||
if (status) return status;
|
||
//駅リストイニシャライズ
|
||
const HeaderConfig = {
|
||
headers: {
|
||
referer: "https://train.jr-shikoku.co.jp/sp.html",
|
||
},
|
||
};
|
||
return await Promise.all([
|
||
yosan,
|
||
uwajima,
|
||
uwajima2,
|
||
dosan,
|
||
dosan2,
|
||
koutoku,
|
||
tokushima,
|
||
naruto,
|
||
fetch(
|
||
"https://train.jr-shikoku.co.jp/g?arg1=station&arg2=seto",
|
||
HeaderConfig
|
||
).then((response) => response.json()),
|
||
fetch(
|
||
"https://train.jr-shikoku.co.jp/g?arg1=station&arg2=between",
|
||
HeaderConfig
|
||
).then((response) => response.json()),
|
||
fetch(
|
||
"https://train.jr-shikoku.co.jp/g?arg1=line&arg2=train_lang",
|
||
HeaderConfig
|
||
).then((response) => response.json()),
|
||
]).then((values) => {
|
||
let stationList = {};
|
||
[
|
||
stationList.予讃線,
|
||
stationList.松宇線,
|
||
stationList.伊予灘線,
|
||
stationList.土讃線,
|
||
stationList.窪川線,
|
||
stationList.高徳線,
|
||
stationList.徳島線,
|
||
stationList.鳴門線,
|
||
stationList.瀬戸大橋線,
|
||
stationList.駅間リスト,
|
||
stationList.日英対応表,
|
||
] = values;
|
||
const concatBetweenStations = (eachRouteData) => {
|
||
let additional = [];
|
||
eachRouteData.forEach((routeData, routeIndex) => {
|
||
try {
|
||
const currentStationID = parseInt(
|
||
routeData.StationNumber.replace(/[A-Z]/g, "")
|
||
);
|
||
const nextStationID = parseInt(
|
||
eachRouteData[routeIndex + 1].StationNumber.replace(/[A-Z]/g, "")
|
||
);
|
||
if (nextStationID - currentStationID != 1) {
|
||
stationList.駅間リスト.forEach((betweenList) => {
|
||
if (
|
||
betweenList.BetweenStation ==
|
||
routeData.Station_JP +
|
||
"~" +
|
||
eachRouteData[routeIndex + 1].Station_JP
|
||
) {
|
||
additional = additional.concat(betweenList.Datas);
|
||
}
|
||
});
|
||
}
|
||
} catch (e) {}
|
||
});
|
||
return eachRouteData
|
||
.concat(additional)
|
||
.sort((a, b) => (a.StationNumber > b.StationNumber ? 1 : -1));
|
||
};
|
||
const addStationPosition = (setDataBase, geoJson, EnJpList) => {
|
||
return setDataBase.map((data) => {
|
||
let stationName;
|
||
if (data.hasOwnProperty("Station_JP")) stationName = data.Station_JP;
|
||
else if (data.hasOwnProperty("StationName")) {
|
||
stationName = data.StationName;
|
||
data.Station_JP = data.StationName;
|
||
data.Station_EN = EnJpList.find(
|
||
(d) => d.Station_JP == data.Station_JP
|
||
).Station_EN;
|
||
}
|
||
geoJson.features
|
||
.filter((d) => d.geometry.type == "Point")
|
||
.forEach((element) => {
|
||
if (element.properties.name == stationName) {
|
||
data.lat = element.geometry.coordinates[1];
|
||
data.lng = element.geometry.coordinates[0];
|
||
}
|
||
});
|
||
return data;
|
||
});
|
||
};
|
||
stationList.予讃線 = addStationPosition(
|
||
concatBetweenStations(stationList.予讃線),
|
||
予讃線,
|
||
stationList.日英対応表
|
||
);
|
||
stationList.松宇線 = addStationPosition(
|
||
concatBetweenStations(stationList.松宇線),
|
||
予讃線,
|
||
stationList.日英対応表
|
||
);
|
||
stationList.伊予灘線 = addStationPosition(
|
||
concatBetweenStations(stationList.伊予灘線),
|
||
予讃線,
|
||
stationList.日英対応表
|
||
);
|
||
stationList.土讃線 = addStationPosition(
|
||
concatBetweenStations(stationList.土讃線),
|
||
土讃線,
|
||
stationList.日英対応表
|
||
);
|
||
stationList.窪川線 = addStationPosition(
|
||
concatBetweenStations(stationList.窪川線),
|
||
土讃線,
|
||
stationList.日英対応表
|
||
);
|
||
stationList.高徳線 = addStationPosition(
|
||
concatBetweenStations(stationList.高徳線),
|
||
高徳線,
|
||
stationList.日英対応表
|
||
);
|
||
stationList.鳴門線 = addStationPosition(
|
||
concatBetweenStations(stationList.鳴門線),
|
||
鳴門線,
|
||
stationList.日英対応表
|
||
);
|
||
const tokushimaCurrent = addStationPosition(
|
||
concatBetweenStations(stationList.徳島線),
|
||
徳島線,
|
||
stationList.日英対応表
|
||
);
|
||
stationList.徳島線 = [
|
||
tokushimaCurrent[tokushimaCurrent.length - 1],
|
||
...tokushimaCurrent,
|
||
];
|
||
stationList.徳島線.pop();
|
||
stationList.瀬戸大橋線 = [
|
||
{
|
||
Station_JP: "坂出",
|
||
Station_EN: "Sakaide",
|
||
MyStation: "3",
|
||
StationNumber: null,
|
||
DispNum: "3",
|
||
StationTimeTable:
|
||
"http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/sakaide.pdf",
|
||
StationMap: "https://www.google.co.jp/maps/place/34.313222,133.856325",
|
||
JrHpUrl: "http://www.jr-shikoku.co.jp/01_trainbus/kakueki/sakaide/",
|
||
lat: 34.313222,
|
||
lng: 133.856325,
|
||
},
|
||
|
||
{
|
||
Station_JP: "児島",
|
||
Station_EN: "Kojima",
|
||
MyStation: "0",
|
||
StationNumber: "M12",
|
||
DispNum: "3",
|
||
StationTimeTable:
|
||
"http://www.jr-odekake.net/eki/timetable.php?id=0651304",
|
||
StationMap: "https://www.google.co.jp/maps/place/34.462562,133.807809",
|
||
JrHpUrl: "http://www.jr-odekake.net/eki/top.php?id=0651304",
|
||
lat: 34.462562,
|
||
lng: 133.807809,
|
||
},
|
||
{
|
||
Station_JP: "宇多津",
|
||
Station_EN: "Utazu",
|
||
MyStation: "0",
|
||
StationNumber: null,
|
||
DispNum: "3",
|
||
StationTimeTable:
|
||
"http://www.jr-shikoku.co.jp/01_trainbus/jikoku/pdf/utazu.pdf",
|
||
StationMap: "https://www.google.co.jp/maps/place/34.306379,133.813784",
|
||
JrHpUrl: "http://www.jr-shikoku.co.jp/01_trainbus/kakueki/utazu/",
|
||
lat: 34.306379,
|
||
lng: 133.813784,
|
||
},
|
||
];
|
||
status = stationList;
|
||
return stationList;
|
||
});
|
||
};
|