diff --git a/src/components/rte/RteViewer.tsx b/src/components/rte/RteViewer.tsx index 7542b3a..3f17c29 100644 --- a/src/components/rte/RteViewer.tsx +++ b/src/components/rte/RteViewer.tsx @@ -8,7 +8,7 @@ import QuestionMarkIcon from '@suid/icons-material/QuestionMark'; import Tree from '../tree'; import { LineString } from 'ol/geom'; import { DisplayOrGetStartEndAddresses } from '../display-or-get-address'; -import { getFormatedLength } from '../../lib/ol'; +import { getFormattedLength } from '../../lib/ol'; import Alert from '../alert'; import dispatch from '../../workers/dispatcher-main'; @@ -73,7 +73,7 @@ const RteViewer: Component = ({ rteId }) => { content={ <>
- {getFormatedLength(lineString)} + {getFormattedLength(lineString)} rte().rtept} diff --git a/src/components/trkseg/TrksegViewer.tsx b/src/components/trkseg/TrksegViewer.tsx index 37827a2..8354099 100644 --- a/src/components/trkseg/TrksegViewer.tsx +++ b/src/components/trkseg/TrksegViewer.tsx @@ -3,9 +3,10 @@ import { peekCachedSignal } from '../../workers/cached-signals'; import Tree from '../tree'; import TrkIcon from '../../icons/human-footprints-svgrepo-com.svg?component-solid'; import { useI18n } from '@solid-primitives/i18n'; -import { getFormatedLength } from '../../lib/ol'; +import { getFormattedLength } from '../../lib/ol'; import { DisplayOrGetStartEndAddresses } from '../display-or-get-address'; import { LineString } from 'ol/geom'; +import { getFormattedHeightStats } from '../../lib/height'; interface Props { trksegId: string; @@ -40,12 +41,13 @@ const TrksegViewer: Component = ({ trksegId }) => { content={ <>
- {getFormatedLength(lineString)} {t('from')}{' '} + {getFormattedLength(lineString)}{' '} trkseg().trkpt} putAction='putTrkpt' - /> + />{', '} + {getFormattedHeightStats(trkseg().trkpt)}
} diff --git a/src/lib/height.ts b/src/lib/height.ts new file mode 100644 index 0000000..fd056af --- /dev/null +++ b/src/lib/height.ts @@ -0,0 +1,33 @@ +export const getHeightStats = (wpts: Wpt[]) => { + let previous: number | null = null, + min: number | null = null, + max: number | null = null, + positive: number = 0, + negative: number = 0; + + wpts.forEach((wpt) => { + if (wpt.ele) { + const ele = Math.round(wpt.ele); + if (!max || ele > max) { + max = ele; + } + if (!min || ele < min) { + min = ele; + } + if (previous) { + if (ele > previous) { + positive += ele - previous; + } else { + negative += previous - ele; + } + } + previous = ele; + } + }); + return { min, max, positive, negative }; +}; + +export const getFormattedHeightStats = (wpts: Wpt[]) => { + const { min, max, positive, negative } = getHeightStats(wpts); + return `d+ : ${positive}m, d- : ${negative}m`; +}; diff --git a/src/lib/ol.ts b/src/lib/ol.ts index 6155a06..db1dd2f 100644 --- a/src/lib/ol.ts +++ b/src/lib/ol.ts @@ -1,7 +1,7 @@ import { LineString } from 'ol/geom'; import { getLength } from 'ol/sphere'; -export const getFormatedLength = (lineString: LineString) => { +export const getFormattedLength = (lineString: LineString) => { const length = getLength(lineString, { projection: 'EPSG:4326' }); if (length > 1000) { const l = length / 1000;