Skip to content

Commit

Permalink
Merge pull request #5215 from HSLdevcom/DT-6476_patch-4
Browse files Browse the repository at this point in the history
DT-6476 Memoized planar leg calculation
  • Loading branch information
vesameskanen authored Dec 27, 2024
2 parents 2387c56 + 78e959d commit 00f5859
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions app/component/itinerary/navigator/hooks/useRealtimeLegs.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ const useRealtimeLegs = (relayEnvironment, initialLegs = []) => {
[initialLegs[0]],
);

const planarLegs = useMemo(() => {
return initialLegs.map(leg => {
const geometry = polyUtil.decode(leg.legGeometry.points);
return {
...leg,
geometry: geometry.map(p => GeodeticToEnu(p[0], p[1], origin)),
};
});
}, [initialLegs]);

const queryAndMapRealtimeLegs = useCallback(
async legs => {
if (!legs.length) {
Expand Down Expand Up @@ -188,14 +198,6 @@ const useRealtimeLegs = (relayEnvironment, initialLegs = []) => {
return;
}

const planarLegs = initialLegs.map(leg => {
const geometry = polyUtil.decode(leg.legGeometry.points);
return {
...leg,
geometry: geometry.map(p => GeodeticToEnu(p[0], p[1], origin)),
};
});

const rtLegMap = await queryAndMapRealtimeLegs(planarLegs).catch(err =>
// eslint-disable-next-line no-console
console.error('Failed to query and map real time legs', err),
Expand All @@ -219,7 +221,7 @@ const useRealtimeLegs = (relayEnvironment, initialLegs = []) => {
// shift non-transit-legs to match possibly changed transit legs
matchLegEnds(rtLegs);
setRealTimeLegs(rtLegs);
}, [initialLegs, queryAndMapRealtimeLegs]);
}, [planarLegs, queryAndMapRealtimeLegs]);

useEffect(() => {
fetchAndSetRealtimeLegs();
Expand Down

0 comments on commit 00f5859

Please sign in to comment.