This repository was archived by the owner on Feb 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMarkers.js
107 lines (99 loc) · 3.07 KB
/
Markers.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React, { Component } from 'react'
import { Map, Marker, Popup } from '../../src/'
export default class Markers extends Component {
state = {
zoom: 13,
center: [54.98, 82.89],
markers: [],
pos: [54.98, 82.89],
draggable: false,
withPopup: false,
popupContent: 'Hello world!'
};
onChangePos = e => {
this.setState({
pos: e.target.value.split(',')
});
};
onChangeDraggable = () => {
this.setState({
draggable: !this.state.draggable
});
};
onChangeWithPopup = () => {
this.setState({
withPopup:!this.state.withPopup
});
};
onChangePopupContent = e => {
this.setState({
popupContent: e.target.value
});
};
addMarker = () => {
let markers = this.state.markers;
const pos = this.state.pos;
const draggable = this.state.draggable;
const popupContent = this.state.popupContent;
let popup = null;
if (this.state.withPopup) {
popup = (
<Popup>
{ popupContent }
</Popup>
);
}
markers.push(
<Marker
key={this.state.markers.length}
draggable={draggable}
pos={pos}
>
{ popup }
</Marker>
);
this.setState({
markers: markers
});
};
removeMarker = () => {
let markers = this.state.markers;
markers.pop();
this.setState({
markers: markers
});
};
render() {
return (
<div>
<div>
<label>Position: </label>
<input onChange={this.onChangePos} value={this.state.pos} style={{width: 100}}/>
<button onClick={this.addMarker}>Add marker</button>
</div>
<div>
<div>
<input type="checkbox" value={this.state.draggable} onChange={this.onChangeDraggable}/><label>Draggable</label>
</div>
<div>
<input type="checkbox" value={this.state.withPopup} onChange={this.onChangeWithPopup}/><label>Popup</label>
</div>
<div>
<label>Popup content: </label>
<input onChange={this.onChangePopupContent} disabled={!this.state.withPopup} value={this.state.popupContent} style={{width: 400}}/>
</div>
</div>
<div>
<button onClick={this.removeMarker} disabled={!this.state.markers.length}>Remove marker</button>
</div>
<Map
style={{width: "500px", height: "500px"}}
center={this.state.center}
zoom={this.state.zoom}
>
{ this.state.markers }
</Map>
</div>
);
}
}