@@ -4,8 +4,9 @@ import { connect } from 'react-redux'
4
4
import { CircleMarker , FeatureGroup , Marker , MapLayer , Popup , withLeaflet } from 'react-leaflet'
5
5
import { divIcon } from 'leaflet'
6
6
7
- import SetFromToButtons from './set-from-to'
8
7
import { setLocation } from '../../actions/map'
8
+ import SetFromToButtons from './set-from-to'
9
+ import { getCompaniesLabelFromNetworks } from '../../util/itinerary'
9
10
10
11
class VehicleRentalOverlay extends MapLayer {
11
12
static propTypes = {
@@ -50,26 +51,52 @@ class VehicleRentalOverlay extends MapLayer {
50
51
}
51
52
}
52
53
53
- _renderPopupForStation = ( station ) => {
54
- const stationName = `${ station . networks . join ( '/' ) } ${ station . name || station . id } `
54
+ /**
55
+ * Render some popup html for a station. This contains custom logic for
56
+ * displaying rental vehicles in the TriMet MOD website that might not be
57
+ * applicable to other regions.
58
+ */
59
+ _renderPopupForStation = ( station , stationIsHub = false ) => {
60
+ const { configCompanies, leaflet, setLocation} = this . props
61
+ const stationNetworks = getCompaniesLabelFromNetworks (
62
+ station . networks ,
63
+ configCompanies
64
+ )
65
+ let stationName = station . name || station . id
66
+ if ( station . isFloatingBike ) {
67
+ stationName = `Free-floating bike: ${ stationName } `
68
+ } else if ( station . isFloatingCar ) {
69
+ stationName = `${ stationNetworks } ${ stationName } `
70
+ } else if ( station . isFloatingVehicle ) {
71
+ // assumes that all floating vehicles are E-scooters
72
+ stationName = `${ stationNetworks } E-scooter`
73
+ } else {
74
+ stationIsHub = true
75
+ }
55
76
return (
56
77
< Popup >
57
78
< div className = 'map-overlay-popup' >
58
79
{ /* Popup title */ }
59
- < div className = 'popup-title' >
60
- Floating vehicle { stationName }
61
- </ div >
80
+ < div className = 'popup-title' > { stationName } </ div >
81
+
82
+ { /* render dock info if it is available */ }
83
+ { stationIsHub && (
84
+ < div className = 'popup-row' >
85
+ < div > Available bikes: { station . bikesAvailable } </ div >
86
+ < div > Available docks: { station . spacesAvailable } </ div >
87
+ </ div >
88
+ ) }
62
89
63
90
{ /* Set as from/to toolbar */ }
64
91
< div className = 'popup-row' >
65
92
< SetFromToButtons
66
- map = { this . props . leaflet . map }
93
+ map = { leaflet . map }
67
94
location = { {
68
95
lat : station . y ,
69
96
lon : station . x ,
70
97
name : stationName
71
98
} }
72
- setLocation = { this . props . setLocation }
99
+ setLocation = { setLocation }
73
100
/>
74
101
</ div >
75
102
</ div >
@@ -124,38 +151,7 @@ class VehicleRentalOverlay extends MapLayer {
124
151
key = { station . id }
125
152
position = { [ station . y , station . x ] }
126
153
>
127
- < Popup >
128
- < div className = 'map-overlay-popup' >
129
- { /* Popup title */ }
130
- < div className = 'popup-title' >
131
- { station . isFloatingBike
132
- ? < span > Floating bike: { station . name } </ span >
133
- : < span > { station . name } </ span >
134
- }
135
- </ div >
136
-
137
- { /* Details */ }
138
- { ! station . isFloatingBike && (
139
- < div className = 'popup-row' >
140
- < div > Available bikes: { station . bikesAvailable } </ div >
141
- < div > Available docks: { station . spacesAvailable } </ div >
142
- </ div >
143
- ) }
144
-
145
- { /* Set as from/to toolbar */ }
146
- < div className = 'popup-row' >
147
- < SetFromToButtons
148
- map = { this . props . leaflet . map }
149
- location = { {
150
- lat : station . y ,
151
- lon : station . x ,
152
- name : station . name
153
- } }
154
- setLocation = { this . props . setLocation }
155
- />
156
- </ div >
157
- </ div >
158
- </ Popup >
154
+ { this . _renderPopupForStation ( station , ! station . isFloatingBike ) }
159
155
</ Marker >
160
156
)
161
157
}
@@ -239,6 +235,7 @@ class VehicleRentalOverlay extends MapLayer {
239
235
240
236
const mapStateToProps = ( state , ownProps ) => {
241
237
return {
238
+ configCompanies : state . otp . config . companies ,
242
239
zoom : state . otp . config . map . initZoom
243
240
}
244
241
}
0 commit comments