現在地基準の当該駅を複数表示できるように修正
This commit is contained in:
parent
7232c40af1
commit
015e4e54ed
37
menu.js
37
menu.js
@ -55,9 +55,9 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
|||||||
}
|
}
|
||||||
}, 10);
|
}, 10);
|
||||||
}, []);
|
}, []);
|
||||||
//位置情報
|
|
||||||
const { position, locationStatus } = useUserPosition();
|
|
||||||
|
|
||||||
|
//現在地基準の駅名標リストアップ機能
|
||||||
|
const { position, locationStatus } = useUserPosition();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!position) return () => {};
|
if (!position) return () => {};
|
||||||
makeCurrentStation(position);
|
makeCurrentStation(position);
|
||||||
@ -65,7 +65,7 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
|||||||
const makeCurrentStation = (location) => {
|
const makeCurrentStation = (location) => {
|
||||||
if (!originalStationList) return () => {};
|
if (!originalStationList) return () => {};
|
||||||
const findStationEachLine = (selectLine) => {
|
const findStationEachLine = (selectLine) => {
|
||||||
const searchArea = stationListMode == "position" ? 0.07 : 0.002;
|
const searchArea = 0.12;
|
||||||
const _calcDistance = (from, to) => {
|
const _calcDistance = (from, to) => {
|
||||||
let lat = Math.abs(from.lat - to.lat);
|
let lat = Math.abs(from.lat - to.lat);
|
||||||
let lng = Math.abs(from.lng - to.lng);
|
let lng = Math.abs(from.lng - to.lng);
|
||||||
@ -78,11 +78,26 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
|||||||
lng: location.coords.longitude,
|
lng: location.coords.longitude,
|
||||||
}) < searchArea
|
}) < searchArea
|
||||||
);
|
);
|
||||||
|
//NearStationを距離の近い順にソート
|
||||||
|
NearStation.sort((a, b) => {
|
||||||
|
return (
|
||||||
|
_calcDistance(a, {
|
||||||
|
lat: location.coords.latitude,
|
||||||
|
lng: location.coords.longitude,
|
||||||
|
}) -
|
||||||
|
_calcDistance(b, {
|
||||||
|
lat: location.coords.latitude,
|
||||||
|
lng: location.coords.longitude,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
return NearStation;
|
return NearStation;
|
||||||
};
|
};
|
||||||
|
|
||||||
let returnDataBase = lineList
|
let returnDataBase = lineList
|
||||||
.map((d) => findStationEachLine(originalStationList[d]))
|
.map((d) => {
|
||||||
|
return findStationEachLine(originalStationList[d]);
|
||||||
|
})
|
||||||
.filter((d) => {
|
.filter((d) => {
|
||||||
return d.length > 0;
|
return d.length > 0;
|
||||||
})
|
})
|
||||||
@ -90,17 +105,16 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
|||||||
pre.push(...current);
|
pre.push(...current);
|
||||||
return pre;
|
return pre;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (returnDataBase.length) {
|
if (returnDataBase.length) {
|
||||||
let currentStation = currentStation == undefined ? [] : currentStation;
|
const returnData = returnDataBase.map((d) => [d]);
|
||||||
if (currentStation.toString() != returnDataBase.toString()) {
|
setNearPositionStation(returnData);
|
||||||
setNearPositionStation(returnDataBase);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setNearPositionStation(undefined);
|
setNearPositionStation([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [nearPositionStation, setNearPositionStation] = useState(undefined); //第三要素
|
const [nearPositionStation, setNearPositionStation] = useState([]); //第三要素
|
||||||
|
|
||||||
const carouselRef = useRef();
|
const carouselRef = useRef();
|
||||||
const [listIndex, setListIndex] = useState(0);
|
const [listIndex, setListIndex] = useState(0);
|
||||||
@ -108,8 +122,7 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
|
|||||||
const [listUpStation, setListUpStation] = useState([]);
|
const [listUpStation, setListUpStation] = useState([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (stationListMode == "position") {
|
if (stationListMode == "position") {
|
||||||
console.log(nearPositionStation);
|
setListUpStation(nearPositionStation.filter((d) => d != undefined));
|
||||||
setListUpStation([nearPositionStation].filter((d) => d != undefined));
|
|
||||||
} else {
|
} else {
|
||||||
setListUpStation(favoriteStation.filter((d) => d != undefined));
|
setListUpStation(favoriteStation.filter((d) => d != undefined));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user