Skip to content

Commit 722e6df

Browse files
committed
Updates with InfoWindow docs
1 parent 5e32315 commit 722e6df

File tree

3 files changed

+79
-9
lines changed

3 files changed

+79
-9
lines changed

README.md

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,83 @@ const Container = React.createClass({
189189
});
190190
```
191191

192-
// TODO: Document InfoWindow component
192+
### InfoWindow
193+
194+
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+
![](http://d.pr/i/16w0V.png)
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+
const WithMarkers = 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.
193269

194270
## Automatically Lazy-loading google api
195271

@@ -222,8 +298,6 @@ npm install
222298
make dev
223299
```
224300

225-
226-
227301
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/).
228302

229303

examples/components/clickableMarkers.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ const WithMarkers = React.createClass({
1414
}
1515
},
1616

17-
onMapMoved: function(props, map) {
18-
const center = map.center;
19-
},
20-
2117
onMarkerClick: function(props, marker, e) {
2218
this.setState({
2319
selectedPlace: props,
@@ -52,8 +48,7 @@ const WithMarkers = React.createClass({
5248
style={{width: '100%', height: '100%', position: 'relative'}}
5349
className={'map'}
5450
zoom={14}
55-
onClick={this.onMapClicked}
56-
onDragend={this.onMapMoved}>
51+
onClick={this.onMapClicked}>
5752
<Marker
5853
onClick={this.onMarkerClick}
5954
name={'SOMA'}

examples/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const routes = (
5555
)
5656

5757
const mountNode = document.querySelector('#root')
58+
console.log(mountNode);
5859
if (mountNode) {
5960
ReactDOM.render(routes, mountNode);
6061
} else {

0 commit comments

Comments
 (0)