Skip to content

Commit 1a884d2

Browse files
committed
fix: do not compute walk route at every stop page render
1 parent d4199d8 commit 1a884d2

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

app/action/PositionActions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function watchPosition(actionContext) {
112112
}, quietTimeoutSeconds * 1000);
113113
try {
114114
if (MOCKPOS) {
115-
setInterval(mockPositionChange, 2000, actionContext);
115+
setInterval(mockPositionChange, 5000, actionContext);
116116
}
117117
geoWatchId = navigator.geolocation.watchPosition(
118118
position => {

app/component/map/StopPageMap.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ function StopPageMap(
5757
const maxShowRouteDistance = breakpoint === 'large' ? 900 : 470;
5858
const { environment } = useContext(ReactRelayContext);
5959
const [walk, setWalk] = useState(null);
60+
const [bounds, setBounds] = useState(null);
6061
const isRouting = useRef(false);
6162

6263
useEffect(() => {
6364
const fetchWalk = async targetStop => {
64-
if (locationState.hasLocation && locationState.address) {
65+
if (locationState.hasLocation) {
6566
if (distance(locationState, stop) < maxShowRouteDistance) {
6667
const settings = getSettings(config);
6768
const variables = {
@@ -98,7 +99,20 @@ function StopPageMap(
9899
isRouting.current = true;
99100
fetchWalk(stop);
100101
}
101-
}, [locationState.status]);
102+
if (
103+
locationState.lat &&
104+
locationState.lon &&
105+
distance(locationState, stop) < maxShowRouteDistance
106+
) {
107+
setBounds([
108+
[locationState.lat, locationState.lon],
109+
[
110+
stop.lat + (stop.lat - locationState.lat),
111+
stop.lon + (stop.lon - locationState.lon),
112+
],
113+
]);
114+
}
115+
}, [stop, locationState.status]);
102116

103117
if (locationState.loadingPosition) {
104118
return <Loading />;
@@ -142,26 +156,12 @@ function StopPageMap(
142156
}
143157
const id = match.params.stopId || match.params.terminalId || match.params.id;
144158

145-
const mwtProps = {};
146-
if (
147-
locationState &&
148-
locationState.lat &&
149-
locationState.lon &&
150-
stop.lat &&
151-
stop.lon &&
152-
distance(locationState, stop) < maxShowRouteDistance
153-
) {
154-
mwtProps.bounds = [
155-
[locationState.lat, locationState.lon],
156-
[
157-
stop.lat + (stop.lat - locationState.lat),
158-
stop.lon + (stop.lon - locationState.lon),
159-
],
160-
];
159+
const mwtProps = { zoom: 18 };
160+
if (bounds) {
161+
mwtProps.bounds = bounds;
161162
} else {
162163
mwtProps.lat = stop.lat;
163164
mwtProps.lon = stop.lon;
164-
mwtProps.zoom = !match.params.stopId || stop.platformCode ? 18 : 16;
165165
}
166166

167167
return (

0 commit comments

Comments
 (0)