From f464d8d8771ba8c7b4c8226962288b314307f18a Mon Sep 17 00:00:00 2001 From: Alexis Jacomy Date: Thu, 13 Apr 2023 15:53:06 +0200 Subject: [PATCH] editor: fixes #3896 --- .../editor/tools/speedSectionEdition/utils.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/front/src/applications/editor/tools/speedSectionEdition/utils.ts b/front/src/applications/editor/tools/speedSectionEdition/utils.ts index 20f35172c00..a41ecebde82 100644 --- a/front/src/applications/editor/tools/speedSectionEdition/utils.ts +++ b/front/src/applications/editor/tools/speedSectionEdition/utils.ts @@ -2,7 +2,7 @@ import { Position } from 'geojson'; import { last, cloneDeep } from 'lodash'; import along from '@turf/along'; import length from '@turf/length'; -import { feature, point } from '@turf/helpers'; +import { Feature, feature, lineString, LineString, point } from '@turf/helpers'; import lineSliceAlong from '@turf/line-slice-along'; import { NEW_ENTITY_ID } from '../../data/utils'; @@ -84,9 +84,19 @@ export function getTrackRangeFeatures( const computedLength = length(track); const adjustedBegin = Math.max((begin * computedLength) / dataLength, 0); const adjustedEnd = Math.min((end * computedLength) / dataLength, computedLength); + + let line: Feature; + // See https://github.com/Turfjs/turf/issues/1577 for this issue: + if (adjustedBegin === adjustedEnd) { + const { coordinates } = along(track.geometry, adjustedBegin).geometry; + line = lineString([coordinates, coordinates]); + } else { + line = lineSliceAlong(track.geometry, adjustedBegin, adjustedEnd); + } + return [ { - ...lineSliceAlong(track.geometry, adjustedBegin, adjustedEnd), + ...line, properties: { ...properties, ...range,