Skip to content
Open
Changes from 6 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
52 changes: 51 additions & 1 deletion lib/components/map/default-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import { connect } from 'react-redux'
import { findRequiredOptionsForTransportMode } from '@opentripplanner/trip-form'
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 @@ -18,10 +21,17 @@ import {
vehicleRentalQuery
} from '../../actions/api'
import { ComponentContext } from '../../util/contexts'
import { decodeQueryParams } from 'serialize-query-params'
import { getActiveItinerary, getActiveSearch } from '../../util/state'
import { getCurrentPosition } from '../../actions/location'
import { MainPanelContent } from '../../actions/ui-constants'
import {
modesQueryParamConfig,
onSettingsUpdate,
setModeButton
} 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 +288,15 @@ class DefaultMap extends Component {
carRentalQuery,
carRentalStations,
config,
enabledModeButtons,
getCurrentPosition,
intl,
itinerary,
mapConfig,
nearbyViewActive,
pending,
setLocation,
setQueryParam,
setViewedStop,
vehicleRentalQuery,
vehicleRentalStations,
Expand Down Expand Up @@ -319,6 +331,35 @@ class DefaultMap extends Component {
const baseLayerUrls = baseLayersWithNames?.map((bl) => bl.url)
const baseLayerNames = baseLayersWithNames?.map((bl) => bl.name)

const overlayTypes = overlays
?.find((overlay) => overlay?.type === 'otp2')
?.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')) {
const requiredOptions:
| { modeButton: string; modeSetting?: string }
| undefined = findRequiredOptionsForTransportMode(
config.modes.modeButtons,
config.modes.modeSettingDefinitions,
{ mode: 'SCOOTER', qualifier: 'RENT' }
)
if (requiredOptions) {
const modeSetter = setModeButton(
enabledModeButtons,
onSettingsUpdate(setQueryParam)
)

modeSetter(requiredOptions.modeButton, true)

if (requiredOptions.modeSetting)
onSettingsUpdate(setQueryParam)({
[requiredOptions.modeSetting]: true
})
}
}
setLocation(location)
}

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

Expand Down Expand Up @@ -435,7 +476,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 @@ -481,11 +522,19 @@ const mapStateToProps = (state) => {
)
)
: null
const urlSearchParams = new URLSearchParams(state.router.location.search)
const { modes } = state.otp.config

return {
bikeRentalStations: state.otp.overlay.bikeRental.stations,
carRentalStations: state.otp.overlay.carRental.stations,
config: state.otp.config,
enabledModeButtons:
decodeQueryParams(modesQueryParamConfig, {
modeButtons: urlSearchParams.get('modeButtons')
})?.modeButtons ||
modes?.initialState?.enabledModeButtons ||
{},
itinerary: getActiveItinerary(state),
mapConfig: state.otp.config.map,
nearbyViewActive:
Expand All @@ -504,6 +553,7 @@ const mapDispatchToProps = {
getCurrentPosition,
setLocation,
setMapPopupLocationAndGeocode,
setQueryParam,
setViewedStop,
updateOverlayVisibility,
vehicleRentalQuery
Expand Down
Loading