Skip to content

Commit 343af24

Browse files
committed
Use dynamic y axis min and max for elevation chart
1 parent 15a6be2 commit 343af24

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • frontend/src/components/Map/components/AltimetricProfile

frontend/src/components/Map/components/AltimetricProfile/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useMap } from 'react-leaflet';
66
import { useIntl } from 'react-intl';
77
import { useRouter } from 'next/router';
88
import { getDefaultLanguage } from 'modules/header/utills';
9+
import { FeatureCollection, LineString } from 'geojson';
910

1011
interface AltimetricProfileProps {
1112
trekGeoJSON: string;
@@ -22,6 +23,11 @@ export const AltimetricProfile: React.FC<AltimetricProfileProps> = ({ trekGeoJSO
2223
return;
2324
}
2425

26+
const { features } = JSON.parse(trekGeoJSON) as FeatureCollection;
27+
const elevationValues = (features[0].geometry as LineString).coordinates.map(coord => coord[2]);
28+
const yAxisMin = Math.min(...elevationValues) * 0.75;
29+
const yAxisMax = Math.max(...elevationValues) * 1.25;
30+
2531
// @ts-expect-error the lib is not typed
2632
const elevationControl = L.control.elevation({
2733
theme: 'lightblue-theme',
@@ -33,6 +39,8 @@ export const AltimetricProfile: React.FC<AltimetricProfileProps> = ({ trekGeoJSO
3339
followMarker: false,
3440
legend: false,
3541
zooming: false,
42+
yAxisMin,
43+
yAxisMax,
3644
});
3745
elevationControl.addTo(map);
3846

0 commit comments

Comments
 (0)