Display delta heigth stats for trkseg

This commit is contained in:
Eric van der Vlist 2023-05-09 09:40:42 +02:00
parent 73172812f5
commit 99daeefa98
4 changed files with 41 additions and 6 deletions

View File

@ -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<Props> = ({ rteId }) => {
content={
<>
<div>
{getFormatedLength(lineString)}
{getFormattedLength(lineString)}
<DisplayOrGetStartEndAddresses
id={rteId}
wpts={() => rte().rtept}

View File

@ -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<Props> = ({ trksegId }) => {
content={
<>
<div>
{getFormatedLength(lineString)} {t('from')}{' '}
{getFormattedLength(lineString)}{' '}
<DisplayOrGetStartEndAddresses
id={trksegId}
wpts={() => trkseg().trkpt}
putAction='putTrkpt'
/>
/>{', '}
{getFormattedHeightStats(trkseg().trkpt)}
</div>
</>
}

33
src/lib/height.ts Normal file
View File

@ -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`;
};

View File

@ -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;