Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/components/map/default-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { connect } from 'react-redux'
import { GeolocateControl, NavigationControl } from 'react-map-gl'
import { getCurrentDate } from '@opentripplanner/core-utils/lib/time'
import { injectIntl } from 'react-intl'
import { MapLocationActionArg } from '@opentripplanner/types'
import { QueryParamChangeEvent } from '@opentripplanner/trip-form/lib/types'
import BaseMap from '@opentripplanner/base-map'
import generateOTP2TileLayers from '@opentripplanner/otp2-tile-overlay'
import React, { Component } from 'react'
Expand All @@ -21,7 +23,9 @@ import { ComponentContext } from '../../util/contexts'
import { getActiveItinerary, getActiveSearch } from '../../util/state'
import { getCurrentPosition } from '../../actions/location'
import { MainPanelContent } from '../../actions/ui-constants'
import { onSettingsUpdate } from '../form/util'
import { setLocation, setMapPopupLocationAndGeocode } from '../../actions/map'
import { setQueryParam } from '../../actions/form'
import { setViewedStop } from '../../actions/ui'
import { updateOverlayVisibility } from '../../actions/config'
import TransitOperatorIcons from '../util/connected-transit-operator-icons'
Expand Down Expand Up @@ -278,13 +282,15 @@ class DefaultMap extends Component {
carRentalQuery,
carRentalStations,
config,
currentQuery,
getCurrentPosition,
intl,
itinerary,
mapConfig,
nearbyViewActive,
pending,
setLocation,
setQueryParam,
setViewedStop,
vehicleRentalQuery,
vehicleRentalStations,
Expand Down Expand Up @@ -319,6 +325,23 @@ class DefaultMap extends Component {
const baseLayerUrls = baseLayersWithNames?.map((bl) => bl.url)
const baseLayerNames = baseLayersWithNames?.map((bl) => bl.name)

const overlayTypes = overlays
?.filter((overlay) => overlay?.type === 'otp2')?.[0]
?.layers?.map((layer) => layer?.type)
const handleSetLocation = (location: MapLocationActionArg) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one approach, but could we not fix this by adjusting query params? What if we check for map state in the places where query params are set? Might that be a better separation of concerns than setting modes within the map component?

if (overlayTypes && overlayTypes.includes('rentalVehicles')) {
let selectedModeButtons = currentQuery.modeButtons ?? ''
// if selectedModeButtons is undefined, the mode buttons are in their default state, which includes transit
if (selectedModeButtons.length === 0)
selectedModeButtons = 'transit_bike_rent'
else if (!selectedModeButtons.includes('bike_rent'))
selectedModeButtons += '_bike_rent'
const evt: QueryParamChangeEvent = { modeButtons: selectedModeButtons }
onSettingsUpdate(setQueryParam)(evt)
}
setLocation(location)
}

const routeBasedTransitVehicleOverlayNameOverride =
overlays?.find((o) => o.type === 'vehicles-one-route') || undefined

Expand Down Expand Up @@ -435,7 +458,7 @@ class DefaultMap extends Component {
name: getLayerName(l, config, intl) || l.network || l.type
})),
vectorTilesEndpoint,
setLocation,
handleSetLocation,
setViewedStop,
viewedRouteStops,
config.companies,
Expand Down Expand Up @@ -486,6 +509,7 @@ const mapStateToProps = (state) => {
bikeRentalStations: state.otp.overlay.bikeRental.stations,
carRentalStations: state.otp.overlay.carRental.stations,
config: state.otp.config,
currentQuery: state.otp.currentQuery,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of importing query info into the map component...

itinerary: getActiveItinerary(state),
mapConfig: state.otp.config.map,
nearbyViewActive:
Expand All @@ -504,6 +528,7 @@ const mapDispatchToProps = {
getCurrentPosition,
setLocation,
setMapPopupLocationAndGeocode,
setQueryParam,
setViewedStop,
updateOverlayVisibility,
vehicleRentalQuery
Expand Down
Loading