Skip to content

Commit

Permalink
editor: fixes #3896
Browse files Browse the repository at this point in the history
  • Loading branch information
jacomyal committed Apr 13, 2023
1 parent 57323b9 commit f464d8d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions front/src/applications/editor/tools/speedSectionEdition/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<LineString>;
// 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,
Expand Down

0 comments on commit f464d8d

Please sign in to comment.