Skip to content

Commit a0f149e

Browse files
boyurdevice25
authored andcommitted
feat: 🎸 add changeMode
1 parent 3fcc88b commit a0f149e

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

src/components/Draw/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
```jsx
2-
<MapGL
3-
style={{ width: "100%", height: "400px" }}
4-
mapStyle="mapbox://styles/mapbox/light-v9"
5-
accessToken={MAPBOX_ACCESS_TOKEN}
6-
latitude={37.78}
7-
longitude={-122.41}
8-
zoom={11}
9-
>
10-
<Draw />
11-
</MapGL>
2+
<div>
3+
<MapGL
4+
style={{ width: "100%", height: "400px" }}
5+
mapStyle="mapbox://styles/mapbox/light-v9"
6+
accessToken={MAPBOX_ACCESS_TOKEN}
7+
latitude={37.78}
8+
longitude={-122.41}
9+
zoom={11}
10+
>
11+
<Draw />
12+
</MapGL>
13+
</div>
1214
```

src/components/Draw/index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@ export type Props = {
6565
/** Over ride the default modes with your own. */
6666
modes?: Object,
6767

68-
/** The mode that user will first land in. */
69-
defaultMode?:
70-
'simple_select'
71-
| 'direct_select'
72-
| 'draw_line_string'
73-
| 'draw_polygon'
74-
| 'draw_point',
68+
/** The mode that will used. */
69+
mode?: String,
70+
71+
/** The mode options. */
72+
modeOptions?: Object,
7573

7674
/**
7775
* Properties of a feature will also be available for styling
@@ -223,7 +221,8 @@ class Draw extends React.PureComponent<Props> {
223221
displayControlsDefault: true,
224222
styles: theme,
225223
modes,
226-
defaultMode: 'simple_select',
224+
mode: 'simple_select',
225+
modeOptions: {},
227226
userProperties: false,
228227
data: null,
229228
onDrawCreate: null,
@@ -258,7 +257,8 @@ class Draw extends React.PureComponent<Props> {
258257
displayControlsDefault: this.props.displayControlsDefault,
259258
styles: this.props.styles,
260259
modes: this.props.modes,
261-
defaultMode: this.props.defaultMode,
260+
defaultMode: this.props.mode,
261+
modeOptions: this.props.modeOptions,
262262
userProperties: this.props.userProperties
263263
}, this.props.position);
264264

@@ -286,11 +286,15 @@ class Draw extends React.PureComponent<Props> {
286286
this._draw = draw;
287287
}
288288

289-
componentDidUpdate() {
289+
componentDidUpdate(prevProps) {
290290
if (this.props.data) {
291291
// $FlowFixMe
292292
this._draw.set(this.props.data);
293293
}
294+
295+
if (prevProps.mode !== this.props.mode) {
296+
this._draw.changeMode(this.props.mode);
297+
}
294298
}
295299

296300
componentWillUnmount(): void {

0 commit comments

Comments
 (0)