-
Notifications
You must be signed in to change notification settings - Fork 817
/
Copy pathclickableMarkers.js
79 lines (66 loc) · 1.88 KB
/
clickableMarkers.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
import React, { Component } from 'react';
import Map from '../../src/index';
import InfoWindow from '../../src/components/InfoWindow';
import Marker from '../../src/components/Marker';
class WithMarkers extends Component {
state = {
activeMarker: {},
selectedPlace: {},
showingInfoWindow: false
};
onMarkerClick = (props, marker) =>
this.setState({
activeMarker: marker,
selectedPlace: props,
showingInfoWindow: true
});
onInfoWindowClose = () =>
this.setState({
activeMarker: null,
showingInfoWindow: false
});
onMapClicked = () => {
if (this.state.showingInfoWindow)
this.setState({
activeMarker: null,
showingInfoWindow: false
});
};
render() {
if (!this.props.loaded) return <div>Loading...</div>;
return (
<Map
className="map"
google={this.props.google}
onClick={this.onMapClicked}
style={{ height: '100%', position: 'relative', width: '100%' }}
zoom={14}>
<Marker
name="SOMA"
onClick={this.onMarkerClick}
position={{ lat: 37.778519, lng: -122.40564 }}
/>
<Marker
name="Dolores park"
onClick={this.onMarkerClick}
position={{ lat: 37.759703, lng: -122.428093 }}
/>
<Marker name="Current location" onClick={this.onMarkerClick} />
<InfoWindow
marker={this.state.activeMarker}
onClose={this.onInfoWindowClose}
visible={this.state.showingInfoWindow}>
<div>
<h1>{this.state.selectedPlace.name}</h1>
</div>
</InfoWindow>
<InfoWindow position={{ lat: 37.765703, lng: -122.42564 }} visible>
<small>
Click on any of the markers to display an additional info.
</small>
</InfoWindow>
</Map>
);
}
}
export default WithMarkers;