forked from elangobharathi/react-leaflet-freedraw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Freedraw.jsx
56 lines (47 loc) · 1.4 KB
/
Freedraw.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import LeafletFreedraw, { clickUndo, clickRedo } from 'leaflet-craft';
import { MapLayer, withLeaflet } from 'react-leaflet';
class FreeCraft extends MapLayer {
createLeafletElement(props) {
return new LeafletFreedraw({ ...props });
}
updateLeafletElement(fromProps, toProps) {
if (fromProps.showUndoRedoBar !== toProps.showUndoRedoBar) {
this.leafletElement.toggleUndoRedoBar(toProps.showUndoRedoBar);
if(!toProps.showUndoRedoBar) {
this.leafletElement.mode(0);
}
}
if (fromProps.showControlBar !== toProps.showControlBar) {
this.leafletElement.toggleControlBar(toProps.showControlBar);
if(!toProps.showControlBar) {
this.leafletElement.mode(0);
}
}
if (fromProps.mode != toProps.mode) {
this.leafletElement.mode(toProps.mode);
}
}
componentDidMount() {
const { map } = this.props.leaflet;
map.addLayer(this.leafletElement);
this.attachEvents(map);
}
attachEvents(map) {
this.leafletElement.on('markers', e => {
if (e.eventType === 'create') {
clickUndo(map);
clickRedo(map);
}
});
// this.leafletElement.on('mode', this.props.onModeChange);
}
componentWillUnmount() {
// this.leafletElement.mode(0);
const { map } = this.props.leaflet;
map.removeLayer(this.leafletElement);
}
render() {
return null;
}
}
export default withLeaflet(FreeCraft);