• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

terrestris / react-geo / 19852072562

02 Dec 2025 08:29AM UTC coverage: 67.609%. Remained the same
19852072562

push

github

web-flow
Merge pull request #4457 from terrestris/dependabot/npm_and_yarn/express-4.22.1

build(deps-dev): bump express from 4.21.2 to 4.22.1

676 of 1088 branches covered (62.13%)

Branch coverage included in aggregate %.

1238 of 1743 relevant lines covered (71.03%)

13.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.67
/src/Button/DrawCutButton/DrawCutButton.tsx
1
import React, {FC, useCallback, useRef, useState} from 'react';
2

3
import {Popconfirm, PopconfirmProps} from 'antd';
4

5
import OlFeature from 'ol/Feature';
6
import OlGeometry from 'ol/geom/Geometry';
7
import OlVectorLayer from 'ol/layer/Vector';
8
import OlVectorSource from 'ol/source/Vector';
9
import OlStyleStroke from 'ol/style/Stroke';
10
import OlStyle, { StyleLike as OlStyleLike } from 'ol/style/Style';
11

12
import {useDrawCut} from '@terrestris/react-util';
13
import useOlLayer from '@terrestris/react-util/dist/Hooks/useOlLayer/useOlLayer';
14

15
import { CSS_PREFIX } from '../../constants';
16
import ToggleButton, {ToggleButtonProps} from '../ToggleButton/ToggleButton';
17

18
interface OwnProps {
19
  /**
20
   * Style object / style function for drawn feature.
21
   */
22
  drawStyle?: OlStyleLike;
23
  /**
24
   * Style object / style function for highlighting the cut geometry.
25
   */
26
  highlightStyle?: OlStyleLike;
27
  /**
28
   * The vector layer which will be used for digitize features.
29
   * The standard digitizeLayer can be retrieved via `DigitizeUtil.getDigitizeLayer(map)`.
30
   */
31
  digitizeLayer?: OlVectorLayer<OlVectorSource>;
32
  /**
33
   * This callback is called after the cut was performed with all changed features. Removed features geometry is set to
34
   * undefined.
35
   */
36
  onCutEnd?: (changed: OlFeature[]) => void;
37
  /**
38
   * Text to show in the Popconfirm after drawing the cut.
39
   */
40
  popConfirmText?: string;
41
  /**
42
   * Props to pass to the antd Popconfirm component.
43
   */
44
  popConfirmProps?: Omit<PopconfirmProps, 'onConfirm'|'onCancel'|'open'|'title'>;
45
}
46

47
export type DrawCutProps = OwnProps & Partial<ToggleButtonProps>;
48

49
export const defaultHighlightStyle = new OlStyle({
1✔
50
  stroke: new OlStyleStroke({
51
    color: 'rgba(232, 38, 11, 0.9)',
52
    width: 2
53
  })
54
});
55

56
/**
57
 * The className added to this component.
58
 */
59
const defaultClassName = `${CSS_PREFIX}drawcutbutton`;
1✔
60

61
export const DrawCutButton: FC<DrawCutProps> = ({
1✔
62
  digitizeLayer,
63
  drawStyle,
64
  className,
65
  onCutEnd,
66
  pressed,
67
  popConfirmProps,
68
  highlightStyle = defaultHighlightStyle,
6✔
69
  popConfirmText = 'Perform cut?',
5✔
70
  ...passThroughProps
71
}) => {
72
  const [popOpen, setPopOpen] = useState(false);
6✔
73

74
  const promise = useRef<PromiseWithResolvers<boolean>>();
6✔
75

76
  const highlightLayer = useOlLayer(() => new OlVectorLayer({
6✔
77
    source: new OlVectorSource(),
78
    style: highlightStyle
79
  }), [highlightStyle]);
80

81
  const onCutStart = useCallback((geom: OlGeometry) => {
6✔
82
    if (promise.current) {
×
83
      promise.current.reject();
×
84
    }
85

86
    promise.current = Promise.withResolvers();
×
87

88
    highlightLayer?.getSource()?.clear();
×
89
    highlightLayer?.getSource()?.addFeature(new OlFeature(geom));
×
90

91
    setPopOpen(true);
×
92

93
    return promise.current.promise;
×
94
  }, [highlightLayer]);
95

96
  const resolvePopConfirm = useCallback((value: boolean) => {
6✔
97
    return () => {
12✔
98
      promise.current?.resolve(value);
×
99
      promise.current = undefined;
×
100
      highlightLayer?.getSource()?.clear();
×
101
      setPopOpen(false);
×
102
    };
103
  }, [highlightLayer]);
104

105
  useDrawCut({
6✔
106
    digitizeLayer,
107
    drawStyle,
108
    active: !!pressed,
109
    onCutStart,
110
    onCutEnd
111
  });
112

113
  const finalClassName = className
6✔
114
    ? `${defaultClassName} ${className}`
115
    : defaultClassName;
116

117
  const btnWrapperClass = `${CSS_PREFIX}digitize-button-wrapper`;
6✔
118

119
  return (
6✔
120
    <span className={btnWrapperClass}>
121
      <Popconfirm
122
        open={popOpen}
123
        onConfirm={resolvePopConfirm(true)}
124
        onCancel={resolvePopConfirm(false)}
125
        title={popConfirmText}
126
        {...popConfirmProps}
127
      >
128
        <ToggleButton
129
          pressed={pressed}
130
          className={finalClassName}
131
          disabled={popOpen}
132
          {...passThroughProps}
133
        />
134
      </Popconfirm>
135
    </span>
136
  );
137
};
138

139
export default DrawCutButton;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc