Skip to content

Commit

Permalink
fix(DrawButton): remove text feature from layer on cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
simonseyock authored and dnlkoch committed Feb 20, 2024
1 parent f6d998c commit 421bc13
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Button/DrawButton/DrawButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { useDraw, UseDrawProps } from '@terrestris/react-util/dist/Hooks/useDraw/useDraw';
import useMap from '@terrestris/react-util/dist/Hooks/useMap/useMap';
import {usePropOrDefault} from '@terrestris/react-util/dist/Hooks/usePropOrDefault/usePropOrDefault';
import {DigitizeUtil} from '@terrestris/react-util/dist/Util/DigitizeUtil';
import OlFeature from 'ol/Feature';
import OlGeometry from 'ol/geom/Geometry';
import {
Expand Down Expand Up @@ -70,6 +73,12 @@ const DrawButton: React.FC<DrawButtonProps> = ({
pressed,
...passThroughProps
}) => {
const map = useMap();
const layer = usePropOrDefault(
digitizeLayer,
() => map ? DigitizeUtil.getDigitizeLayer(map) : undefined,
[map]
);
/**
* Currently drawn feature which should be represented as label or post-it.
*/
Expand All @@ -85,7 +94,7 @@ const DrawButton: React.FC<DrawButtonProps> = ({

useDraw({
onDrawEnd: onDrawEndInternal,
digitizeLayer,
digitizeLayer: layer,
drawInteractionConfig,
drawStyle,
drawType: drawType === 'Text' ? 'Point' : drawType,
Expand All @@ -107,6 +116,8 @@ const DrawButton: React.FC<DrawButtonProps> = ({
};

const onModalLabelCancelInternal = () => {
layer?.getSource()?.removeFeature(digitizeTextFeature);
setDigitizeTextFeature(null);
onModalLabelCancel?.();
digitizeLayer?.getSource()?.removeFeature(digitizeTextFeature);
setDigitizeTextFeature(null);
Expand Down

0 comments on commit 421bc13

Please sign in to comment.