Skip to content

Commit

Permalink
fix(map): update wording for map marker popups
Browse files Browse the repository at this point in the history
  • Loading branch information
evansiroky committed Sep 6, 2019
1 parent b17ab42 commit 016275a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 40 deletions.
77 changes: 37 additions & 40 deletions lib/components/map/vehicle-rental-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { connect } from 'react-redux'
import { CircleMarker, FeatureGroup, Marker, MapLayer, Popup, withLeaflet } from 'react-leaflet'
import { divIcon } from 'leaflet'

import SetFromToButtons from './set-from-to'
import { setLocation } from '../../actions/map'
import SetFromToButtons from './set-from-to'
import { getCompaniesLabelFromNetworks } from '../../util/itinerary'

class VehicleRentalOverlay extends MapLayer {
static propTypes = {
Expand Down Expand Up @@ -50,26 +51,52 @@ class VehicleRentalOverlay extends MapLayer {
}
}

_renderPopupForStation = (station) => {
const stationName = `${station.networks.join('/')} ${station.name || station.id}`
/**
* Render some popup html for a station. This contains custom logic for
* displaying rental vehicles in the TriMet MOD website that might not be
* applicable to other regions.
*/
_renderPopupForStation = (station, stationIsHub = false) => {
const {configCompanies, leaflet, setLocation} = this.props
const stationNetworks = getCompaniesLabelFromNetworks(
station.networks,
configCompanies
)
let stationName = station.name || station.id
if (station.isFloatingBike) {
stationName = `Free-floating bike: ${stationName}`
} else if (station.isFloatingCar) {
stationName = `${stationNetworks} ${stationName}`
} else if (station.isFloatingVehicle) {
// assumes that all floating vehicles are eScooters
stationName = `${stationNetworks} E-scooter`
} else {
stationIsHub = true
}
return (
<Popup>
<div className='map-overlay-popup'>
{/* Popup title */}
<div className='popup-title'>
Floating vehicle {stationName}
</div>
<div className='popup-title'>{stationName}</div>

{/* render dock info if it is available */}
{stationIsHub && (
<div className='popup-row'>
<div>Available bikes: {station.bikesAvailable}</div>
<div>Available docks: {station.spacesAvailable}</div>
</div>
)}

{/* Set as from/to toolbar */}
<div className='popup-row'>
<SetFromToButtons
map={this.props.leaflet.map}
map={leaflet.map}
location={{
lat: station.y,
lon: station.x,
name: stationName
}}
setLocation={this.props.setLocation}
setLocation={setLocation}
/>
</div>
</div>
Expand Down Expand Up @@ -124,38 +151,7 @@ class VehicleRentalOverlay extends MapLayer {
key={station.id}
position={[station.y, station.x]}
>
<Popup>
<div className='map-overlay-popup'>
{/* Popup title */}
<div className='popup-title'>
{station.isFloatingBike
? <span>Floating bike: {station.name}</span>
: <span>{station.name}</span>
}
</div>

{/* Details */}
{!station.isFloatingBike && (
<div className='popup-row'>
<div>Available bikes: {station.bikesAvailable}</div>
<div>Available docks: {station.spacesAvailable}</div>
</div>
)}

{/* Set as from/to toolbar */}
<div className='popup-row'>
<SetFromToButtons
map={this.props.leaflet.map}
location={{
lat: station.y,
lon: station.x,
name: station.name
}}
setLocation={this.props.setLocation}
/>
</div>
</div>
</Popup>
{this._renderPopupForStation(station, !station.isFloatingBike)}
</Marker>
)
}
Expand Down Expand Up @@ -239,6 +235,7 @@ class VehicleRentalOverlay extends MapLayer {

const mapStateToProps = (state, ownProps) => {
return {
configCompanies: state.otp.config.companies,
zoom: state.otp.config.map.initZoom
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/util/itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ function getCompanyForNetwork (networkString, companies = []) {
*/
export function getCompaniesLabelFromNetworks (networks, companies = []) {
return networks.map(network => getCompanyForNetwork(network, companies))
.filter(co => !!co)
.map(co => co.label)
.join('/')
}
Expand Down

0 comments on commit 016275a

Please sign in to comment.