Display delta heigth stats for trkseg
This commit is contained in:
parent
73172812f5
commit
99daeefa98
|
@ -8,7 +8,7 @@ import QuestionMarkIcon from '@suid/icons-material/QuestionMark';
|
||||||
import Tree from '../tree';
|
import Tree from '../tree';
|
||||||
import { LineString } from 'ol/geom';
|
import { LineString } from 'ol/geom';
|
||||||
import { DisplayOrGetStartEndAddresses } from '../display-or-get-address';
|
import { DisplayOrGetStartEndAddresses } from '../display-or-get-address';
|
||||||
import { getFormatedLength } from '../../lib/ol';
|
import { getFormattedLength } from '../../lib/ol';
|
||||||
import Alert from '../alert';
|
import Alert from '../alert';
|
||||||
import dispatch from '../../workers/dispatcher-main';
|
import dispatch from '../../workers/dispatcher-main';
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ const RteViewer: Component<Props> = ({ rteId }) => {
|
||||||
content={
|
content={
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
{getFormatedLength(lineString)}
|
{getFormattedLength(lineString)}
|
||||||
<DisplayOrGetStartEndAddresses
|
<DisplayOrGetStartEndAddresses
|
||||||
id={rteId}
|
id={rteId}
|
||||||
wpts={() => rte().rtept}
|
wpts={() => rte().rtept}
|
||||||
|
|
|
@ -3,9 +3,10 @@ import { peekCachedSignal } from '../../workers/cached-signals';
|
||||||
import Tree from '../tree';
|
import Tree from '../tree';
|
||||||
import TrkIcon from '../../icons/human-footprints-svgrepo-com.svg?component-solid';
|
import TrkIcon from '../../icons/human-footprints-svgrepo-com.svg?component-solid';
|
||||||
import { useI18n } from '@solid-primitives/i18n';
|
import { useI18n } from '@solid-primitives/i18n';
|
||||||
import { getFormatedLength } from '../../lib/ol';
|
import { getFormattedLength } from '../../lib/ol';
|
||||||
import { DisplayOrGetStartEndAddresses } from '../display-or-get-address';
|
import { DisplayOrGetStartEndAddresses } from '../display-or-get-address';
|
||||||
import { LineString } from 'ol/geom';
|
import { LineString } from 'ol/geom';
|
||||||
|
import { getFormattedHeightStats } from '../../lib/height';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
trksegId: string;
|
trksegId: string;
|
||||||
|
@ -40,12 +41,13 @@ const TrksegViewer: Component<Props> = ({ trksegId }) => {
|
||||||
content={
|
content={
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
{getFormatedLength(lineString)} {t('from')}{' '}
|
{getFormattedLength(lineString)}{' '}
|
||||||
<DisplayOrGetStartEndAddresses
|
<DisplayOrGetStartEndAddresses
|
||||||
id={trksegId}
|
id={trksegId}
|
||||||
wpts={() => trkseg().trkpt}
|
wpts={() => trkseg().trkpt}
|
||||||
putAction='putTrkpt'
|
putAction='putTrkpt'
|
||||||
/>
|
/>{', '}
|
||||||
|
{getFormattedHeightStats(trkseg().trkpt)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
|
@ -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`;
|
||||||
|
};
|
|
@ -1,7 +1,7 @@
|
||||||
import { LineString } from 'ol/geom';
|
import { LineString } from 'ol/geom';
|
||||||
import { getLength } from 'ol/sphere';
|
import { getLength } from 'ol/sphere';
|
||||||
|
|
||||||
export const getFormatedLength = (lineString: LineString) => {
|
export const getFormattedLength = (lineString: LineString) => {
|
||||||
const length = getLength(lineString, { projection: 'EPSG:4326' });
|
const length = getLength(lineString, { projection: 'EPSG:4326' });
|
||||||
if (length > 1000) {
|
if (length > 1000) {
|
||||||
const l = length / 1000;
|
const l = length / 1000;
|
||||||
|
|
Loading…
Reference in New Issue