Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion lib/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ export function matchContentToUrl (location) {
dispatch(setMainPanelContent(MainPanelContent.STOP_VIEWER))
}
break
case 'start':
case '@':
// Parse comma separated params (ensuring numbers are parsed correctly).
const [lat, lon, zoom, routerId] = id.split(',').map(s => isNaN(s) ? s : +s)
let [lat, lon, zoom, routerId] = id ? idToParams(id) : []
if (!lat || !lon) {
// Attempt to parse path. (Legacy UI otp.js used slashes in the
// pathname to specify lat, lon, etc.)
[,, lat, lon, zoom, routerId] = idToParams(location.pathname, '/')
}
// Update map location/zoom and optionally override router ID.
dispatch(setMapCenter({ lat, lon }))
dispatch(setMapZoom({ zoom }))
Expand All @@ -82,6 +88,10 @@ export function matchContentToUrl (location) {
}
}

function idToParams (id, delimiter = ',') {
return id.split(delimiter).map(s => isNaN(s) ? s : +s)
}

/**
* Event listener for responsive webapp that handles a back button press and
* sets the active search and itinerary according to the URL query params.
Expand Down
5 changes: 5 additions & 0 deletions lib/components/app/responsive-webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class RouterWrapper extends Component {
// to a quirk with react-router.
// https://github.com/ReactTraining/react-router/issues/5870#issuecomment-394194338
'/@/:latLonZoomRouter',
'/start/:latLonZoomRouter',
// Route viewer (and route ID).
'/route',
'/route/:id',
Expand All @@ -194,6 +195,10 @@ class RouterWrapper extends Component {
path='/print'
component={PrintLayout}
/>
{/* For any other route, simply return the web app. */}
<Route
render={() => <WebappWithRouter {...this.props} />}
/>
</Switch>
</div>
</ConnectedRouter>
Expand Down