From 888c5045de3dd0359b1bc51e2782a6c37292e30a Mon Sep 17 00:00:00 2001 From: wlfrdssn <61554783+wlfrdssn@users.noreply.github.com> Date: Thu, 26 Dec 2024 15:33:00 +0100 Subject: [PATCH] Bugfix reuse control There was a bug that allowed a normal or finish control to be used as the start control when reusing a control. I have separated them so that 'start' can only be reused with 'start,' 'normal' with 'normal,' and 'finish' with 'finish.' --- src/tools/CreateCourse.tsx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/tools/CreateCourse.tsx b/src/tools/CreateCourse.tsx index fdd1a01..9ad5eee 100644 --- a/src/tools/CreateCourse.tsx +++ b/src/tools/CreateCourse.tsx @@ -192,11 +192,37 @@ export default function CreateCourse(): JSX.Element { map.un("pointermove", onPointerMove); }; } + + async function onPointerMove(e: MapBrowserEvent) { const features = await otherControlsLayer.getFeatures(e.pixel); if (features.length > 0) { const [feature] = features; + + const controlKind = feature.get("kind"); + + const numberControls = controlsSource?.getFeatures().length || 0; + + let expectedKind: "start" | "normal" | "finish"; + + if (numberControls === 0) { + expectedKind = "start"; + } else if (activeModeRef.current === "Finish") { + expectedKind = "finish"; + } else { + expectedKind = "normal"; + } + + if (controlKind !== expectedKind) { + if (highlightFeatureRef.current) { + const previousHighlight = highlightFeatureRef.current; + highlightFeatureRef.current = undefined; + previousHighlight.changed(); + } + return; + } + if (feature !== highlightFeatureRef.current) { highlightFeatureRef.current = feature; feature.changed(); @@ -261,3 +287,4 @@ function getEvent({ addControl, }; } +