Skip to content

Commit

Permalink
Make controls selectable again; select interaction needs to be after …
Browse files Browse the repository at this point in the history
…modify

Fixes #12.
  • Loading branch information
perliedman committed Aug 27, 2022
1 parent 67d4f34 commit f0c6198
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/tools/EditControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,6 @@ export default function EditControls() {
highlightFeatureRef,
});

const [selectedControlId, setSelectedControlId] = useState();
const selectOptions = useMemo(
() => ({
style,
layers: (layer) => layer.getSource() === controlsSource,
}),
[style, controlsSource]
);
const selectedFeature =
controlsSource && selectedControlId
? controlsSource
.getFeatures()
.find((feature) => feature.get("id") === selectedControlId)
: null;
useSelect(
map,
selectedFeature,
(feature) => setSelectedControlId(feature?.get("id")),
selectOptions
);

useEffect(() => {
if (map && controlsSource) {
const styleFunction = (_, resolution) =>
Expand Down Expand Up @@ -178,6 +157,27 @@ export default function EditControls() {
allControls,
]);

const [selectedControlId, setSelectedControlId] = useState();
const selectOptions = useMemo(
() => ({
style,
layers: (layer) => layer.getSource() === controlsSource,
}),
[style, controlsSource]
);
const selectedFeature =
controlsSource && selectedControlId
? controlsSource
.getFeatures()
.find((feature) => feature.get("id") === selectedControlId)
: null;
useSelect(
map,
selectedFeature,
(feature) => setSelectedControlId(feature?.get("id")),
selectOptions
);

useHotkeys("delete,backspace", deleteSelected, [selectedFeature]);
useHotkeys("up", () => moveSelected(0, 1), [
selectedFeature,
Expand Down

0 comments on commit f0c6198

Please sign in to comment.