Skip to content

Commit

Permalink
Merge pull request #24 from wlfrdssn/Bugfix-reuse-controls
Browse files Browse the repository at this point in the history
Bugfix reuse control
  • Loading branch information
perliedman authored Dec 27, 2024
2 parents a51562b + 888c504 commit a869717
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 a869717

Please sign in to comment.