diff --git a/src/components/overview/index.jsx b/src/components/overview/index.jsx index 5ea927f..f66c000 100644 --- a/src/components/overview/index.jsx +++ b/src/components/overview/index.jsx @@ -3,7 +3,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Button, Grid, Stack, TextField } from '@mui/material'; import { useEffect, useState } from 'react'; -import { downloadGpx, getITRADistance } from '../../utils'; +import { downloadGpx } from '../../utils'; const Overview = ({ gpx, meta, setMeta }) => { const [distance, setDistance] = useState(0); @@ -12,15 +12,12 @@ const Overview = ({ gpx, meta, setMeta }) => { const [itraDistance, setItraDistance] = useState(0); useEffect(() => { - setDistance(Math.floor(gpx.tracks[0].distance.total / 1000)); + setDistance(Math.round(gpx.tracks[0].distance.total / 1000)); + setItraDistance(Math.round(gpx.tracks[0].distance.totalItra / 1000)) setDuration(Math.ceil(distance / meta.kmPerDay)); setElevation(gpx.calcElevation(gpx.tracks[0].points)); }, [distance, gpx, meta]); - useEffect(() => { - setItraDistance(getITRADistance({ distance, elevation: elevation.pos })); - }, [distance, elevation]) - return ( diff --git a/src/pages/trail.jsx b/src/pages/trail.jsx index 6bde98d..5399f20 100644 --- a/src/pages/trail.jsx +++ b/src/pages/trail.jsx @@ -62,6 +62,29 @@ const Trail = () => { .then((xml) => { const newGpx = new gpxParser(); newGpx.parse(xml); + // Compute cumulative positiv elevation and ITRA distance at each point of the Route/Track + const cumulItra = []; + const cumulElevation = []; + let itraValue = 0; + let elevationValue = 0; + const points = newGpx.tracks[0].points; + for (let i = 0; i < points.length - 1; i++) { + const pointFrom = points[i]; + const pointTo = points[i + 1]; + let distance = newGpx.calcDistanceBetween(pointFrom, pointTo); + const elevation = pointTo.ele - pointFrom.ele; + if (elevation > 0) { + distance += elevation * 10; + elevationValue += elevation; + } + itraValue += distance; + cumulItra.push(itraValue); + cumulElevation.push(elevationValue); + }; + newGpx.tracks[0].distance.cumulItra = cumulItra; + newGpx.tracks[0].distance.totalItra = itraValue; + newGpx.tracks[0].distance.cumulElevation = cumulElevation; + newGpx.tracks[0].distance.totalElevation = elevationValue; setGpx(newGpx); }) .catch((e) => console.error(e));