看板処理系と位置情報取得系を一斉更新

This commit is contained in:
harukin-DeskMini 2022-04-20 09:27:13 +09:00
parent e557f7433c
commit ba35ae10d3

362
menu.js
View File

@ -24,27 +24,6 @@ import 内子線 from './assets/四国旅客鉄道内子線.json';
import 徳島線 from './assets/四国旅客鉄道徳島線.json';
import 鳴門線 from './assets/四国旅客鉄道鳴門線.json'
import LED_vision from './components/発車時刻表/LED_vidion';
const makeLineStationListValiable = (base,lineName)=>{
let returnData =[];
base.features.forEach(element =>{
if(element.geometry.type=="Point"){
returnData.push({
lat:element.geometry.coordinates[1],
lng:element.geometry.coordinates[0],
name:element.properties.name,
lineName:lineName
})
}
});
return returnData;
}
const yosanLineStation = makeLineStationListValiable(予讃線,"予讃線");
const DosanLineStation = makeLineStationListValiable(土讃線,"土讃線");
const KotokuLineStation = makeLineStationListValiable(高徳線,"高徳線");
const UchikoLineStation = makeLineStationListValiable(内子線,"(予讃)内子線");
const TokushimaLineStation = makeLineStationListValiable(徳島線,"徳島線");
const NarutoLineStation = makeLineStationListValiable(鳴門線,"鳴門線");
const stationList = {};
@ -84,135 +63,46 @@ export default function Menu(props) {
const StationBoardAcSR = useRef(null);
const navigation = useNavigation();
const [stationName,setStationName] = useState(undefined);
const getCurrentStation = (location) =>{
const findStationEachLine = (selectLine,selectLineName) => {
const searchArea = 0.005;
for( let selectLineData of selectLine){
let latBool = false;
let lngBool = false;
if(location.latitude < selectLineData.lat){
if((selectLineData.lat - location.latitude) < searchArea)latBool = true;
}
else{
if((location.latitude - selectLineData.lat) < searchArea)latBool = true;
}
if(location.longitude < selectLineData.lng){
if((selectLineData.lng - location.longitude) < searchArea)lngBool = true;
}
else{
if((location.longitude - selectLineData.lng) < searchArea)lngBool = true;
}
if(latBool && lngBool){
for(let data of stationList.日英対応表){
if(data.Station_JP == selectLineData.name){
let pre = undefined;
let nex = undefined;
let now = undefined;
let index =0;
for(let da of stationList[selectLineName]){
if((data.Station_JP == da.Station_JP) || (data.Station_JP == da.StationName)){
try{
let preEn = undefined;
stationList.日英対応表.forEach((j,l)=>{
if(j.Station_JP == (stationList[selectLineName][index-1].Station_JP ? stationList[selectLineName][index-1].Station_JP : stationList[selectLineName][index-1].StationName)){
preEn = j.Station_EN;
}
})
pre = {
name:stationList[selectLineName][index-1].Station_JP ? stationList[selectLineName][index-1].Station_JP : stationList[selectLineName][index-1].StationName,
en:preEn,
StationNumber:stationList[selectLineName][index-1].StationNumber,
StationTimeTable:stationList[selectLineName][index-1].StationTimeTable,
StationMap:stationList[selectLineName][index-1].StationMap
}
}catch(e){
pre = {
name:null,
en:null,
StationNumber:null
}
}
now = {
LineName:selectLineData.lineName,
name:selectLineData.name,
en:data.Station_EN,
StationNumber:da.StationNumber,
JrHpUrl:da.JrHpUrl,
StationTimeTable:da.StationTimeTable,
StationMap:da.StationMap
}
try{
let nexEn = undefined;
stationList.日英対応表.forEach((j,l)=>{
if(j.Station_JP == (stationList[selectLineName][index+1].Station_JP ? stationList[selectLineName][index+1].Station_JP : stationList[selectLineName][index+1].StationName)){
nexEn = j.Station_EN;
}
})
nex = {
name:stationList[selectLineName][index+1].Station_JP ? stationList[selectLineName][index+1].Station_JP : stationList[selectLineName][index+1].StationName,
en:nexEn,
StationNumber:stationList[selectLineName][index+1].StationNumber,
StationTimeTable:stationList[selectLineName][index+1].StationTimeTable,
StationMap:stationList[selectLineName][index+1].StationMap
}
}catch(e){
nex = {
name:null,
en:null,
StationNumber:null,
StationTimeTable:null
}
}
}
index++;
}
if(now){
setStationName({
"前":pre,
"今":now,
"次":nex
});
return true;
}
}
}
}
//位置情報
const [location, setLocation] = useState(null);
const [errorMsg, setErrorMsg] = useState(null);
useEffect(() => {
Location.requestForegroundPermissionsAsync().then(data=>{
if (data.status !== 'granted') {
setErrorMsg('Permission to access location was denied');
return ()=>{};
}
return false;
}
findStationEachLine(yosanLineStation,"予讃線") ? null :
findStationEachLine(yosanLineStation,"松宇線") ? null :
findStationEachLine(UchikoLineStation,"松宇線") ? null :
findStationEachLine(DosanLineStation,"土讃線") ? null :
findStationEachLine(DosanLineStation,"窪川線") ? null :
findStationEachLine(KotokuLineStation,"高徳線") ? null :
findStationEachLine(TokushimaLineStation,"徳島線") ? null :
findStationEachLine(NarutoLineStation,"鳴門線") ? null : console.log("not found");
}
async function loadOfficialStationList(){
Location.getCurrentPositionAsync({}).then(location=>setLocation(location))
})
setInterval(() => {
Location.getCurrentPositionAsync({}).then(location=>setLocation(location))
}, 10000);
},[])
const [originalStationList , setOriginalStationList] = useState();
useEffect(()=>{ //駅リストイニシャライズ
const HeaderConfig = {
headers:{
'referer':'https://train.jr-shikoku.co.jp/sp.html'
}
}
Promise.all([
await fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=yosan', HeaderConfig).then(response => response.json()),
await fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima',HeaderConfig).then(response => response.json()),
await fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima2',HeaderConfig).then(response => response.json()),
await fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan',HeaderConfig).then(response => response.json()),
await fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan2',HeaderConfig).then(response => response.json()),
await fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=koutoku',HeaderConfig).then(response => response.json()),
await fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=tokushima',HeaderConfig).then(response => response.json()),
await fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=naruto',HeaderConfig).then(response => response.json()),
await fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=between',HeaderConfig).then(response => response.json()),
await fetch('https://train.jr-shikoku.co.jp/g?arg1=line&arg2=train_lang',HeaderConfig).then(response => response.json())
]).then((values)=>{
fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=yosan', HeaderConfig).then(response => response.json()),
fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima',HeaderConfig).then(response => response.json()),
fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima2',HeaderConfig).then(response => response.json()),
fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan',HeaderConfig).then(response => response.json()),
fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan2',HeaderConfig).then(response => response.json()),
fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=koutoku',HeaderConfig).then(response => response.json()),
fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=tokushima',HeaderConfig).then(response => response.json()),
fetch('https://train.jr-shikoku.co.jp/g?arg1=station&arg2=naruto',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.日英対応表] = values;
const concatBetweenStations = (eachRouteData) => {
let additional = [];
eachRouteData.forEach((routeData,routeIndex) => {
@ -226,42 +116,74 @@ export default function Menu(props) {
}
})
}
}catch(e){
}
}catch(e){}
});
return(eachRouteData.concat(additional).sort((a,b)=> (a.StationNumber > b.StationNumber) ? 1 : -1 ))
}
stationList.予讃線 = concatBetweenStations(stationList.予讃線);
stationList.松宇線 = concatBetweenStations(stationList.松宇線);
stationList.伊予灘線 = concatBetweenStations(stationList.伊予灘線);
stationList.土讃線 = concatBetweenStations(stationList.土讃線);
stationList.窪川線 = concatBetweenStations(stationList.窪川線);
stationList.高徳線 = concatBetweenStations(stationList.高徳線);
stationList.徳島線 = concatBetweenStations(stationList.徳島線);
stationList.鳴門線 = concatBetweenStations(stationList.鳴門線);
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.日英対応表);
stationList.鳴門線 = addStationPosition(concatBetweenStations(stationList.鳴門線), 鳴門線, stationList.日英対応表);
setOriginalStationList(stationList);
});
}
},[])
const [location, setLocation] = useState(null);
const [errorMsg, setErrorMsg] = useState(null);
useEffect(async() => {
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
setErrorMsg('Permission to access location was denied');
return;
const [stationName,setStationName] = useState(undefined);
const [currentStation, setCurrentStation] = useState(undefined);
useEffect(()=>{
if(!location) return ()=>{};
if(!originalStationList) return ()=>{};
const findStationEachLine = (selectLine) => {
const searchArea = 0.0015;
const _calcDistance = (from, to) =>{
let lat = Math.abs(from.lat - to.lat);
let lng = Math.abs(from.lng - to.lng);
return Math.sqrt((lat*lat)+(lng*lng))
}
let NearStation = selectLine.filter(d=>_calcDistance(d,{lat:location.coords.latitude,lng:location.coords.longitude}) < searchArea);
return NearStation;
}
Location.getCurrentPositionAsync({}).then(location=>{
console.log(location);
setLocation(location);
loadOfficialStationList().then(()=>getCurrentStation(location.coords));
})
}, []);
const lineList = ["予讃線", "松宇線", "伊予灘線", "土讃線", "窪川線", "高徳線", "徳島線", "鳴門線"];
console.log(lineList.map(d=>findStationEachLine(originalStationList[d])).find(d=>d.length > 0))
let returnDataBase = lineList.map(d=>findStationEachLine(originalStationList[d])).find(d=>d.length > 0)
if(returnDataBase.length){
setCurrentStation(returnDataBase);
}
else{
setCurrentStation(undefined);
}
},[location,originalStationList])
const LottieRef = useRef(null);
@ -287,6 +209,18 @@ export default function Menu(props) {
}catch(e){}
})
const getPreNextStation = (now) =>{
const lineList = ["予讃線", "松宇線", "伊予灘線", "土讃線", "窪川線", "高徳線", "徳島線", "鳴門線"];
let returnData;
lineList.forEach(d=>{
let cache = originalStationList[d].findIndex( data => data.StationNumber == now.StationNumber);
if(cache != -1){
returnData = [originalStationList[d][cache-1],originalStationList[d][cache+1]]
}
})
return returnData;
}
return (
<View style={{height:"100%",paddingTop: Constants.statusBarHeight,backgroundColor:"white"}}>
{Status}
@ -305,57 +239,73 @@ export default function Menu(props) {
<Text style={{color:"white",fontWeight:"bold",fontSize:20}}>新型コロナウイルスに関するお知らせ</Text>
<Text style={{color:"white",fontSize:18}}>列車の運行計画混雑状況感染症対策への取り組み</Text>
</TextBox>
{stationName ? stationName. ?
{currentStation ?
<TouchableOpacity style={{ width: wp("80%"), height: wp("80%")/20*9,borderColor:"#2E94BB",borderWidth:1,margin:10,marginHorizontal:wp("10%")}} /* onPress={()=> !stationName.今.JrHpUrl || Linking.openURL(stationName.今.JrHpUrl)} */onPress={() => {StationBoardAcSR.current?.setModalVisible()}}>
<View style={{position:"absolute",bottom:"0%",left:"0%",width:"100%",height:'30%',backgroundColor:"#2E94BB"}} />
<Text style={{position:"absolute",top:"2%",left:"2%",fontWeight:"bold",fontSize:parseInt("30%"),color:"#2E94BB"}}>JR</Text>
<View style={{position:"absolute",alignContent:"center",alignItems:"center",top:"20%",right:'10%',width:wp("10%"),height:wp("10%"),borderColor:"#2E94BB",borderWidth:parseInt("2%"),borderRadius:parseInt("100%")}} >
<View style={{flex:1}} />
<Text style={{fontSize:parseInt("20%")}}>{stationName..StationNumber}</Text>
<View style={{flex:1}} />
</View>
{currentStation.map((d,index,array)=>
<View style={{position:"absolute",alignContent:"center",alignItems:"center",top:(()=>{
if(array.length == 1) return 20;
else if(index == 0) return 5;
else if(index == 1) return 35;
else return 20;
})()+"%",right:'10%',width:wp("10%"),height:wp("10%"),borderColor:"#2E94BB",borderWidth:parseInt("2%"),borderRadius:parseInt("100%")}} >
<View style={{flex:1}} />
<Text style={{fontSize:parseInt("20%")}}>{d.StationNumber}</Text>
<View style={{flex:1}} />
</View>
)}
<View style={{position:"absolute",top:"10%",alignContent:"center",flexDirection:"row"}}>
<View style={{flex:1}}/>
<View style={{alignItems:"center"}}>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"#005170"}}>{stationName..LineName}</Text>
<Text style={{fontWeight:"bold",fontSize:parseInt("40%"),color:"#005170"}}>{stationName..name}</Text>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"#005170"}}>{stationName..en}</Text>
{/* <Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"#005170"}}>{stationName.今.LineName}</Text> */}
<Text style={{fontWeight:"bold",fontSize:parseInt("40%"),color:"#005170"}}>{currentStation[0].Station_JP}</Text>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"#005170"}}>{currentStation[0].Station_EN}</Text>
</View>
<View style={{flex:1}}/>
</View>
<View style={{position:"absolute",bottom:"0%",height:"30%",width:"100%",alignItems:"center",flexDirection:"row"}}>
{stationName. ? <Text style={{fontWeight:"bold",fontSize:parseInt("20%"),color:"white",paddingHorizontal:10}}></Text> : null}
{stationName. ?
<View style={{alignContent:"center",alignItems:"center",width:wp("8%"),height:wp("8%"),margin:wp("1%"),borderColor:"white",borderWidth:parseInt("2%"),borderRadius:parseInt("100%")}} >
<View style={{flex:1}} />
<Text style={{fontSize:parseInt("10%"),color:"white"}}>{stationName..StationNumber}</Text>
<View style={{flex:1}} />
</View> : null}
<View style={{flex:1,alignItems:"flex-start"}}>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"white"}}>{stationName..name}</Text>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"white"}}>{stationName..en}</Text>
</View>
{/* <TouchableOpacity style={{alignItems:"center"}} onPress={()=>Linking.openURL(stationName..StationTimeTable)}>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),backgroundColor:"white",color:"#005170",padding:5}}>時刻表</Text>
</TouchableOpacity> */}
<View style={{flex:1,alignItems:"flex-end"}}>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"white"}}>{stationName..name}</Text>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"white"}}>{stationName..en}</Text>
</View>
{stationName..name != null ?
<View style={{alignContent:"center",alignItems:"center",width:wp("8%"),height:wp("8%"),margin:wp("1%"),borderColor:"white",borderWidth:parseInt("2%"),borderRadius:parseInt("100%")}} >
<View style={{flex:1}} />
<Text style={{fontSize:parseInt("10%"),color:"white"}}>{stationName..StationNumber}</Text>
<View style={{flex:1}} />
</View> : null}
{stationName..name != null ? <Text style={{fontWeight:"bold",fontSize:parseInt("20%"),color:"white",paddingHorizontal:10}}></Text>: null}
{(()=>{
let [preStation, nexStation] = getPreNextStation(currentStation[0])
return(
[<View style={{flex:1,flexDirection:"row",alignContent:"center"}}>
{preStation &&
[<Text style={{fontWeight:"bold",fontSize:parseInt("20%"),color:"white",paddingHorizontal:10,textAlignVertical:"center"}}></Text>,
<View style={{alignContent:"center",alignItems:"center",width:wp("8%"),height:wp("8%"),margin:wp("1%"),borderColor:"white",borderWidth:parseInt("2%"),borderRadius:parseInt("100%")}} >
<View style={{flex:1}} />
<Text style={{fontSize:parseInt("10%"),color:"white"}}>{preStation.StationNumber}</Text>
<View style={{flex:1}} />
</View>,
<View style={{flex:1,alignItems:"flex-start"}}>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"white",flex:1,textAlignVertical:"center"}}>{preStation.Station_JP}</Text>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"white",flex:1,textAlignVertical:"center"}}>{preStation.Station_EN}</Text>
</View>]}
</View>,
<View style={{flex:1,flexDirection:"row",alignContent:"center"}}>
{nexStation &&
[<View style={{flex:1,alignItems:"flex-end"}}>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"white",flex:1,textAlignVertical:"center"}}>{nexStation.Station_JP}</Text>
<Text style={{fontWeight:"bold",fontSize:parseInt("15%"),color:"white",flex:1,textAlignVertical:"center"}}>{nexStation.Station_EN}</Text>
</View>,
<View style={{alignContent:"center",alignItems:"center",width:wp("8%"),height:wp("8%"),margin:wp("1%"),borderColor:"white",borderWidth:parseInt("2%"),borderRadius:parseInt("100%")}} >
<View style={{flex:1}} />
<Text style={{fontSize:parseInt("10%"),color:"white"}}>{nexStation.StationNumber}</Text>
<View style={{flex:1}} />
</View>,
<Text style={{fontWeight:"bold",fontSize:parseInt("20%"),color:"white",paddingHorizontal:10,textAlignVertical:"center"}}></Text>]}
</View>]
)
})()}
</View>
</TouchableOpacity>: null : null}
{stationName ? stationName. ?
<LED_vision stationName={stationName} />
: null : null}
</TouchableOpacity>: null }
{currentStation ?
<LED_vision station={currentStation[0]} />
: null}
<TouchableOpacity onPress={() => {JRSTraInfoEXAcSR.current?.setModalVisible()}}>
<View style={{backgroundColor:"#0099CC",borderRadius:5,margin:10,borderColor:"black",borderWidth:2,overflow:"hidden"}}>
<ScrollView scrollEnabled={false} style={{backgroundColor:"#0099CC",borderRadius:5,maxHeight:300,}}>