1
- import { default as React , Component } from " react" ;
2
- import { GoogleMapLoader , GoogleMap , InfoWindow , Marker } from " react-google-maps" ;
1
+ import { default as React , Component } from ' react' ;
2
+ import { GoogleMapLoader , GoogleMap , InfoWindow , Marker } from ' react-google-maps' ;
3
3
4
4
class Gmap extends Component {
5
5
6
6
constructor ( props ) {
7
7
super ( props ) ;
8
8
this . state = {
9
- // specify the center of the map
10
9
center : {
11
10
lat : 37.784817 ,
12
- lng : - 122.406358
13
- }
14
-
15
- }
11
+ lng : - 122.406358 ,
12
+ } ,
13
+ } ;
16
14
}
17
15
18
16
componentWillReceiveProps ( ) {
19
17
console . log ( 'Received new props!' ) ;
20
18
}
21
19
22
- // this will close all other infoWindows except the user clicked on
20
+ // Close all other infoWindows except the user clicked on
23
21
closeOtherInfoWindows ( socketIdToKeepOpen ) {
24
- // iterate all the users markers
25
- { Object . keys ( this . props . users ) . map ( ( socketId , index ) => {
26
- let marker = this . props . users [ socketId ] ;
27
- // if userIdToKeepOpen is not current marker
28
- if ( marker . showInfo && socketId !== socketIdToKeepOpen ) {
29
- // close the marker window
22
+ Object . keys ( this . props . users ) . forEach ( ( socketId ) => {
23
+ const marker = this . props . users [ socketId ] ;
24
+ if ( marker . showInfo && socketId !== socketIdToKeepOpen ) {
30
25
console . log ( 'Closing info window of:' , socketId ) ;
31
26
this . handleMarkerClose ( marker ) ;
32
27
}
33
-
34
- } ) ; //end the map over users object
35
-
36
- }
28
+ } ) ;
37
29
}
38
30
39
- handleMeetRequest ( receiverId ) {
31
+ handleMeetRequest ( ) {
40
32
console . log ( 'Sending meeting request from user.' ) ;
41
33
// change state here for request sent
42
34
}
43
35
44
- //Toggle to 'true' to show InfoWindow and re-renders component
36
+ // Toggle to 'true' to show InfoWindow and re-renders component
45
37
handleMarkerClick ( marker ) {
46
38
console . log ( 'Inside handleMarkerClick' ) ;
47
39
this . closeOtherInfoWindows ( marker . socketId ) ;
48
- marker . showInfo = true ;
40
+ const user = marker ;
41
+ user . showInfo = true ;
49
42
this . setState ( this . state ) ;
50
43
}
51
44
52
45
handleMarkerClose ( marker ) {
53
- marker . showInfo = false ;
46
+ const user = marker ;
47
+ user . showInfo = false ;
54
48
this . setState ( this . state ) ;
55
49
}
56
50
57
51
renderInfoWindow ( ref , marker ) {
58
52
return (
59
-
60
- //You can nest components inside of InfoWindow!
61
53
< InfoWindow
62
54
key = { `${ ref } _info_window` }
63
- onCloseclick = { this . handleMarkerClose . bind ( this , marker ) } >
55
+ onCloseclick = { this . handleMarkerClose . bind ( this , marker ) }
56
+ >
64
57
65
- {
66
- < div className = "markerInfoWindow" >
58
+ { < div className = "markerInfoWindow" >
67
59
< div className = "markerProfilePic" >
68
- < img src = { marker . image } />
60
+ < img alt = "" src = { marker . image } />
69
61
</ div >
70
62
< div className = "markerName" > { marker . name } </ div >
71
63
< div className = "markerBio" > { marker . bio } </ div >
72
- < button className = "buttonSendMeetReq" onClick = { this . handleMeetRequest . bind ( this , marker ) } > Let's Meet</ button >
64
+ < button className = "buttonSendMeetReq" onClick = { this . handleMeetRequest . bind ( this , marker ) } >
65
+ Let's Meet
66
+ </ button >
73
67
</ div >
74
68
}
75
69
76
70
</ InfoWindow >
77
-
78
71
) ;
79
-
80
72
}
81
73
82
74
render ( ) {
83
-
84
75
return (
85
76
86
77
< GoogleMapLoader
@@ -90,57 +81,47 @@ class Gmap extends Component {
90
81
style = { {
91
82
margin : 'auto' ,
92
83
width : '600px' ,
93
- height : '600px'
94
- } } >
84
+ height : '600px' ,
85
+ } }
86
+ >
95
87
</ div >
96
88
}
97
89
googleMapElement = {
98
90
< GoogleMap
99
91
// google map options:
100
92
center = { this . state . center }
101
- // higher zoom level will reduce the area covered
102
93
defaultZoom = { 14 }
103
- ref = 'map' >
104
-
105
- { Object . keys ( this . props . users ) . map ( ( socketId , index ) =>
106
- {
107
- const marker = this . props . users [ socketId ] ;
108
- // used to reference the marker to for positioning the infowindow
109
- const ref = `marker_${ socketId } ` ;
110
- return (
111
- // use the Marker component to render user as a marker on map
112
- < Marker
113
- key = { socketId }
114
- ref = { ref }
115
- position = { { lat : marker . lat , lng : marker . lng } }
116
- onClick = { this . handleMarkerClick . bind ( this , marker ) } >
117
-
118
- { marker . showInfo ? this . renderInfoWindow ( ref , marker ) : null }
119
- </ Marker >
120
- ) ;
121
-
122
- } ) // end map over users here
123
- }
94
+ ref = "map"
95
+ >
96
+
97
+ { Object . keys ( this . props . users ) . map ( ( socketId ) => {
98
+ const marker = this . props . users [ socketId ] ;
99
+ // used to reference the marker for positioning the infowindow
100
+ const ref = `marker_${ socketId } ` ;
101
+ return (
102
+ // use the Marker component to render user as a marker on map
103
+ < Marker
104
+ key = { socketId }
105
+ ref = { ref }
106
+ position = { { lat : marker . lat , lng : marker . lng } }
107
+ onClick = { this . handleMarkerClick . bind ( this , marker ) }
108
+ >
109
+ { marker . showInfo ? this . renderInfoWindow ( ref , marker ) : null }
110
+ </ Marker >
111
+ ) ;
112
+ } ) // end map over users here
113
+ }
124
114
125
115
</ GoogleMap >
126
116
}
127
117
128
- /> //end of GoogleMapLoader
129
-
118
+ /> // end of GoogleMapLoader
130
119
) ;
131
-
132
120
}
133
121
}
134
122
135
- export default Gmap ;
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
123
+ Gmap . propTypes = {
124
+ users : React . PropTypes . object ,
125
+ } ;
146
126
127
+ export default Gmap ;
0 commit comments