Skip to content

Commit

Permalink
Bugfix reuse control
Browse files Browse the repository at this point in the history
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.'
  • Loading branch information
wlfrdssn authored Dec 26, 2024
1 parent 59c9140 commit 888c504
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/tools/CreateCourse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,37 @@ export default function CreateCourse(): JSX.Element {
map.un("pointermove", onPointerMove);
};
}



async function onPointerMove(e: MapBrowserEvent<PointerEvent>) {
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();
Expand Down Expand Up @@ -261,3 +287,4 @@ function getEvent({
addControl,
};
}

0 comments on commit 888c504

Please sign in to comment.