1
- import { Component , PropTypes } from 'react'
1
+ import React , { Component , PropTypes } from 'react'
2
2
import { connect } from 'react-redux'
3
+ import { Marker , Popup } from 'react-leaflet'
4
+ import { divIcon } from 'leaflet'
3
5
4
6
import { bikeRentalQuery } from '../../actions/api'
5
7
@@ -10,28 +12,62 @@ class BikeRentalOverlay extends Component {
10
12
}
11
13
12
14
componentDidMount ( ) {
13
- console . log ( 'refreshing bike stations' ) ;
14
- this . state . refreshStations ( )
15
+ // ititial station retrieval
16
+ this . props . refreshStations ( )
17
+
18
+ // set up timer to refresh stations periodically
19
+ this . _refreshTimer = setInterval ( ( ) => {
20
+ this . props . refreshStations ( )
21
+ } , 30000 ) // defaults to every 30 sec. TODO: make this configurable?
22
+ }
23
+
24
+ componentWillUnmount ( ) {
25
+ clearInterval ( this . _refreshTimer )
15
26
}
16
27
17
28
render ( ) {
18
- // const { from, to } = this.props.query
19
- console . log ( 'render stations: ' + this . props . stations )
20
- return null
21
- /*return (
29
+ return (
22
30
< div >
23
- <Endpoint type='from' location={from} {...this.props} />
24
- <Endpoint type='to' location={to} {...this.props} />
31
+ { this . props . stations . map ( ( station ) => {
32
+ const icon = station . isFloatingBike
33
+ ? divIcon ( {
34
+ html : `<i class="fa fa-bicycle fa-stack-2x" style="color: #000000"></i>` ,
35
+ className : ''
36
+ } )
37
+ : divIcon ( {
38
+ html : `<i class="fa fa-circle fa-stack-2x" style="color: #000000"></i>` ,
39
+ className : ''
40
+ } )
41
+ return (
42
+ < Marker
43
+ icon = { icon }
44
+ position = { [ station . y , station . x ] }
45
+ >
46
+ < Popup >
47
+ { station . isFloatingBike
48
+ ? < span >
49
+ < b > Floating bike: { station . name } </ b >
50
+ </ span >
51
+ : < span >
52
+ < b > { station . name } </ b > < br />
53
+ Available bikes: { station . bikesAvailable } < br />
54
+ Available docks: { station . spacesAvailable } < br />
55
+ </ span >
56
+ }
57
+ </ Popup >
58
+ </ Marker >
59
+ )
60
+ } ) }
25
61
</ div >
26
- )*/
62
+ )
27
63
}
28
64
}
29
65
30
66
// connect to the redux store
31
67
32
68
const mapStateToProps = ( state , ownProps ) => {
33
69
return {
34
- stations : state . otp . overlay . bike_rental . stations
70
+ stations : state . otp . overlay . bikeRental . stations
35
71
}
36
72
}
37
73
0 commit comments