@@ -4,8 +4,9 @@ import { connect } from 'react-redux'
44import { CircleMarker , FeatureGroup , Marker , MapLayer , Popup , withLeaflet } from 'react-leaflet'
55import { divIcon } from 'leaflet'
66
7- import SetFromToButtons from './set-from-to'
87import { setLocation } from '../../actions/map'
8+ import SetFromToButtons from './set-from-to'
9+ import { getCompaniesLabelFromNetworks } from '../../util/itinerary'
910
1011class VehicleRentalOverlay extends MapLayer {
1112 static propTypes = {
@@ -50,26 +51,52 @@ class VehicleRentalOverlay extends MapLayer {
5051 }
5152 }
5253
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 eScooters
72+ stationName = `${ stationNetworks } E-scooter`
73+ } else {
74+ stationIsHub = true
75+ }
5576 return (
5677 < Popup >
5778 < div className = 'map-overlay-popup' >
5879 { /* 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+ ) }
6289
6390 { /* Set as from/to toolbar */ }
6491 < div className = 'popup-row' >
6592 < SetFromToButtons
66- map = { this . props . leaflet . map }
93+ map = { leaflet . map }
6794 location = { {
6895 lat : station . y ,
6996 lon : station . x ,
7097 name : stationName
7198 } }
72- setLocation = { this . props . setLocation }
99+ setLocation = { setLocation }
73100 />
74101 </ div >
75102 </ div >
@@ -124,38 +151,7 @@ class VehicleRentalOverlay extends MapLayer {
124151 key = { station . id }
125152 position = { [ station . y , station . x ] }
126153 >
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 ) }
159155 </ Marker >
160156 )
161157 }
@@ -239,6 +235,7 @@ class VehicleRentalOverlay extends MapLayer {
239235
240236const mapStateToProps = ( state , ownProps ) => {
241237 return {
238+ configCompanies : state . otp . config . companies ,
242239 zoom : state . otp . config . map . initZoom
243240 }
244241}
0 commit comments