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 pathMarkerIcon.js
86 lines (76 loc) · 2.4 KB
/
MarkerIcon.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
import React, { Component } from 'react'
import { Map, Marker, Icon, DivIcon } from '../../src/'
export default class MarkerIcon extends Component {
state = {
zoom: 13,
center: [54.98, 82.89],
url: 'http://maps.api.2gis.ru/2.0/example_logo.png',
size: [48, 48],
html: '<a href="https://2gis.com">HTML-link</a>',
insideMarker: []
};
onChangeUrl = e => {
this.setState({
url: e.target.value
});
};
onChangeSize= e => {
this.setState({
size: [e.target.value.split(',')[0], e.target.value.split(',')[1]]
});
};
onChangeHtml = e => {
this.setState({
html: e.target.value
});
};
changeToImage = () => {
this.setState({
insideMarker: <Icon
iconUrl={this.state.url}
iconSize={this.state.size}
/>
});
};
changeToDiv = () => {
this.setState({
insideMarker: <DivIcon
iconSize={this.state.size}
dangerouslySetInnerHTML={this.state.html}
>
</DivIcon>
});
};
render() {
return (
<div>
<div>
<label>Icon size: </label>
<input onChange={this.onChangeSize} value={this.state.size} />
</div>
<div>
<label>Image url: </label>
<input onChange={this.onChangeUrl} value={this.state.url} style={{width: 300}}/>
</div>
<div>
<label style={{display: 'block'}}>Div html: </label>
<textarea onChange={this.onChangeHtml} value={this.state.html} style={{width: 200, height: 60}}/>
</div>
<button onClick={this.changeToImage}>Change Icon to Image</button>
<br/>
<button onClick={this.changeToDiv}>Change Icon to Div</button>
<Map
style={{width: "500px", height: "500px"}}
center={this.state.center}
zoom={this.state.zoom}
>
<Marker
pos={this.state.center}
>
{ this.state.insideMarker }
</Marker>
</Map>
</div>
);
}
}