You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `<InfoWindow />` component included in this library is gives us the ability to pop up a "more info" window on our google map.
195
+
196
+

197
+
198
+
The visibility of the `<InfoWindow />` component is controlled by a `visible` prop. The `visible` prop is a boolean (`React.PropTypes.bool`) that shows the `<InfoWindow />` when true and hides it when false.
199
+
200
+
```javascript
201
+
constWithMarkers=React.createClass({
202
+
getInitialState:function() {
203
+
return {
204
+
showingInfoWindow:false,
205
+
activeMarker: {},
206
+
selectedPlace: {},
207
+
}
208
+
},
209
+
210
+
onMarkerClick:function(props, marker, e) {
211
+
this.setState({
212
+
selectedPlace: props,
213
+
activeMarker: marker,
214
+
showingInfoWindow:true
215
+
});
216
+
},
217
+
218
+
onMapClicked:function(props) {
219
+
if (this.state.showingInfoWindow) {
220
+
this.setState({
221
+
showingInfoWindow:false,
222
+
activeMarker:null
223
+
})
224
+
}
225
+
},
226
+
227
+
render:function() {
228
+
return (
229
+
<Map google={this.props.google}
230
+
onClick={this.onMapClicked}>
231
+
<Marker onClick={this.onMarkerClick}
232
+
name={'Current location'} />
233
+
234
+
<InfoWindow
235
+
marker={this.state.activeMarker}
236
+
visible={this.state.showingInfoWindow}>
237
+
<div>
238
+
<h1>{this.state.selectedPlace.name}</h1>
239
+
</div>
240
+
</InfoWindow>
241
+
</Map>
242
+
)
243
+
}
244
+
});
245
+
```
246
+
247
+
### Events
248
+
249
+
The `<InfoWindow />` throws events when it's showing/hiding. Every event is optional and can accept a handler to be called when the event is fired.
250
+
251
+
```javascript
252
+
<InfoWindow
253
+
onOpen={this.windowHasOpened}
254
+
onClose={this.windowHasClosed}
255
+
visible={this.state.showingInfoWindow}>
256
+
<div>
257
+
<h1>{this.state.selectedPlace.name}</h1>
258
+
</div>
259
+
</InfoWindow>
260
+
```
261
+
262
+
#### onClose
263
+
264
+
The `onClose` event is fired when the `<InfoWindow />` has been closed. It's useful for changing state in the parent component to keep track of the state of the `<InfoWindow />`.
265
+
266
+
#### onOpen
267
+
268
+
The `onOpen` event is fired when the window has been mounted in the google map instance. It's useful for keeping track of the state of the `<InfoWindow />` from within the parent component.
193
269
194
270
## Automatically Lazy-loading google api
195
271
@@ -222,8 +298,6 @@ npm install
222
298
make dev
223
299
```
224
300
225
-
226
-
227
301
The Google Map React component library uses React and the Google API to give easy access to the Google Maps library. This Google Map React component library was built alongside the blog post [blog.fullstack.io/articles/react-google-map-component/](http://blog.fullstack.io/articles/react-google-map-component/).
0 commit comments