Skip to content

Commit 4bf0f81

Browse files
committed
front: editor - compute track section length on creation - fix #3974
1 parent 6b73c88 commit 4bf0f81

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

front/src/applications/editor/components/LinearMetadata/FormLineStringLength.tsx

+5-9
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ export const FormLineStringLength: React.FC<WidgetProps> = (props) => {
2323
*/
2424
useEffect(() => {
2525
const distance = getLineStringDistance(formContext.geometry);
26-
if (formContext.isCreation) {
27-
setTimeout(() => onChange(distance), 0);
28-
} else {
29-
setMin(Math.round(distance - distance * DISTANCE_ERROR_RANGE));
30-
setMax(Math.round(distance + distance * DISTANCE_ERROR_RANGE));
31-
setGeoLength(distance);
32-
}
33-
}, [formContext.geometry, formContext.isCreation, onChange]);
26+
setMin(Math.round(distance - distance * DISTANCE_ERROR_RANGE));
27+
setMax(Math.round(distance + distance * DISTANCE_ERROR_RANGE));
28+
setGeoLength(distance);
29+
}, [formContext.geometry, formContext.isCreation]);
3430

3531
return (
3632
<div>
@@ -49,7 +45,7 @@ export const FormLineStringLength: React.FC<WidgetProps> = (props) => {
4945
}}
5046
/>
5147
)}
52-
{geoLength && (length < min || length > max) && (
48+
{geoLength > 0 && (length < min || length > max) && (
5349
<p className="text-warning">
5450
{t('Editor.errors.length-out-of-sync-with-geometry', { min, max })}.{' '}
5551
<button

front/src/applications/editor/tools/trackEdition/tool.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { featureCollection } from '@turf/helpers';
1212
import nearestPointOnLine, { NearestPointOnLine } from '@turf/nearest-point-on-line';
1313

1414
import { save } from 'reducers/editor';
15-
import { entityDoUpdate } from 'common/IntervalsDataViz/data';
15+
import { entityDoUpdate, getLineStringDistance } from 'common/IntervalsDataViz/data';
1616
import { ConfirmModal } from 'common/BootstrapSNCF/ModalSNCF';
1717
import { getMapMouseEventNearestFeature } from 'utils/mapHelper';
1818
import { NEW_ENTITY_ID } from 'applications/editor/data/utils';
@@ -195,7 +195,6 @@ const TrackEditionTool: Tool<TrackEditionState> = {
195195
// Interactions:
196196
onClickMap(e, { setState, state }) {
197197
const { editionState, anchorLinePoints, track, nearestPoint } = state;
198-
199198
if (editionState.type === 'addPoint') {
200199
// Adding a point on an existing section:
201200
if (
@@ -230,6 +229,11 @@ const TrackEditionTool: Tool<TrackEditionState> = {
230229
}
231230

232231
newState.nearestPoint = null;
232+
233+
// compute new length if it's newly tracksection
234+
if (newState.track.properties.id === NEW_ENTITY_ID) {
235+
newState.track.properties.length = getLineStringDistance(newState.track.geometry);
236+
}
233237
setState(newState);
234238
} else {
235239
setState({

0 commit comments

Comments
 (0)