Skip to content

Commit

Permalink
add conditional access info
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Mar 13, 2024
1 parent a2528d0 commit 7a95db1
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 11 deletions.
5 changes: 3 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const config = {
details: [
'road_class',
'road_environment',
'road_access',
'surface',
'max_speed',
'average_speed',
Expand All @@ -39,8 +40,8 @@ const config = {
//
// profiles: {
// car:{}, small_truck:{}, truck:{}, scooter:{},
// foot:{ details: ['foot_network'] }, hike:{ details: ['foot_network'] },
// bike:{ details: ['get_off_bike', 'bike_network'] }, mtb:{ details: ['get_off_bike', 'bike_network'] }, racingbike:{ details: ['get_off_bike', 'bike_network'] },
// foot:{ details: ['foot_network', 'access_conditional'] }, hike:{ details: ['foot_network', 'access_conditional'] },
// bike:{ details: ['get_off_bike', 'bike_network', 'access_conditional'] }, mtb:{ details: ['get_off_bike', 'bike_network', 'access_conditional'] }, racingbike:{ details: ['get_off_bike', 'bike_network', 'access_conditional'] },
// }
//
// E.g. the 'bike' entry will add a "bike" profile for which we send a request with the specified 'details' parameter. You can even change the profile itself when you specify
Expand Down
2 changes: 2 additions & 0 deletions src/api/graphhopper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ interface Details {
readonly max_speed: [number, number, number][]
readonly road_class: [number, number, string][]
readonly road_environment: [number, number, string][]
readonly road_access: [number, number, string][]
readonly access_conditional: [number, number, string][]
readonly track_type: [number, number, string][]
readonly country: [number, number, string][]
readonly get_off_bike: [number, number, boolean][]
Expand Down
63 changes: 54 additions & 9 deletions src/sidebar/RoutingResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useMediaQuery } from 'react-responsive'
import { tr } from '@/translation/Translation'
import { ApiImpl } from '@/api/Api'
import FordIcon from '@/sidebar/routeHints/water.svg'
import CondAccessIcon from '@/sidebar/routeHints/remove_road.svg'
import FerryIcon from '@/sidebar/routeHints/directions_boat.svg'
import PrivateIcon from '@/sidebar/routeHints/privacy_tip.svg'
import StepsIcon from '@/sidebar/routeHints/floor.svg'
Expand Down Expand Up @@ -64,28 +65,46 @@ function RoutingResult({
: styles.resultSummary

useEffect(() => setExpanded(isSelected && isExpanded), [isSelected])
const fordInfo = getInfoFor(path.points, path.details.road_environment, { ford: true })
const tollInfo = getInfoFor(path.points, path.details.toll, { all: true, hgv: ApiImpl.isTruck(profile) })
const ferryInfo = getInfoFor(path.points, path.details.road_environment, { ferry: true })
const fordInfo = getInfoFor(path.points, path.details.road_environment, s => s === 'ford')
const tollInfo = getInfoFor(
path.points,
path.details.toll,
s => s === 'all' || (s === 'hgv' && ApiImpl.isTruck(profile))
)
const ferryInfo = getInfoFor(path.points, path.details.road_environment, s => s === 'ferry')
const accessCondInfo = getInfoFor(path.points, path.details.access_conditional, s => s != null && s.length > 0)
const privateOrDeliveryInfo = ApiImpl.isMotorVehicle(profile)
? getInfoFor(
path.points,
path.details.road_access,
s => s === 'private' || s === 'customers' || s === 'delivery'
)
: new RouteInfo()
const badTrackInfo = !ApiImpl.isMotorVehicle(profile)
? new RouteInfo()
: getInfoFor(path.points, path.details.track_type, { grade2: true, grade3: true, grade4: true, grade5: true })
: getInfoFor(
path.points,
path.details.track_type,
s => s === 'grade2' || s === 'grade3' || s === 'grade4' || s === 'grade5'
)
const trunkInfo = ApiImpl.isMotorVehicle(profile)
? new RouteInfo()
: getInfoFor(path.points, path.details.road_class, { motorway: true, trunk: true })
: getInfoFor(path.points, path.details.road_class, s => s === 'motorway' || s === 'trunk')
const stepsInfo = !ApiImpl.isBikeLike(profile)
? new RouteInfo()
: getInfoFor(path.points, path.details.road_class, { steps: true })
: getInfoFor(path.points, path.details.road_class, s => s === 'steps')
const steepInfo = ApiImpl.isMotorVehicle(profile) ? new RouteInfo() : getHighSlopeInfo(path.points, 15)
const getOffBikeInfo = !ApiImpl.isBikeLike(profile)
? new RouteInfo()
: getInfoFor(path.points, path.details.get_off_bike, { true: true })
: getInfoFor(path.points, path.details.get_off_bike, s => s)
const countriesInfo = crossesBorderInfo(path.points, path.details.country)

const showHints =
fordInfo.distance > 0 ||
tollInfo.distance > 0 ||
ferryInfo.distance > 0 ||
accessCondInfo.distance > 0 ||
privateOrDeliveryInfo.distance > 0 ||
trunkInfo.distance > 0 ||
badTrackInfo.distance > 0 ||
stepsInfo.distance > 0 ||
Expand Down Expand Up @@ -171,6 +190,32 @@ function RoutingResult({
selected={selectedRH}
segments={ferryInfo.segments}
/>
<RHButton
setDescription={b => setDescriptionRH(b)}
description={tr('way_contains_restrictions')}
setType={t => setSelectedRH(t)}
type={'access_conditional'}
child={<CondAccessIcon />}
value={
accessCondInfo.distance > 0 &&
metersToShortText(accessCondInfo.distance, showDistanceInMiles)
}
selected={selectedRH}
segments={accessCondInfo.segments}
/>
<RHButton
setDescription={b => setDescriptionRH(b)}
description={tr('way_contains', [tr('private_sections')])}
setType={t => setSelectedRH(t)}
type={'private'}
child={<PrivateIcon />}
value={
privateOrDeliveryInfo.distance > 0 &&
metersToShortText(privateOrDeliveryInfo.distance, showDistanceInMiles)
}
selected={selectedRH}
segments={privateOrDeliveryInfo.segments}
/>
<RHButton
setDescription={b => setDescriptionRH(b)}
description={tr('way_contains_toll')}
Expand Down Expand Up @@ -332,12 +377,12 @@ function toBBox(segment: Coordinate[]): Bbox {
return bbox as Bbox
}

function getInfoFor(points: LineString, details: [number, number, any][], values: { [Identifier: string]: boolean }) {
function getInfoFor(points: LineString, details: [number, number, any][], fnc: { (s: any): boolean }) {
if (!details) return new RouteInfo()
let info = new RouteInfo()
const coords = points.coordinates
for (const i in details) {
if (values[details[i][2]]) {
if (fnc(details[i][2])) {
const from = details[i][0],
to = details[i][1]
const segCoords: Coordinate[] = []
Expand Down
13 changes: 13 additions & 0 deletions src/sidebar/routeHints/remove_road.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/stores/RouteStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class RouteStore extends Store<RouteStoreState> {
toll: [],
road_environment: [],
road_class: [],
road_access: [],
access_conditional: [],
track_type: [],
country: [],
get_off_bike: [],
Expand Down
Loading

0 comments on commit 7a95db1

Please sign in to comment.