Skip to content

Commit

Permalink
route hints regarding mtb_rating and hike_rating
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Apr 10, 2024
1 parent 302e8c0 commit 5df77da
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 5 deletions.
4 changes: 2 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const config = {
//
// profiles: {
// car:{}, small_truck:{}, truck:{}, scooter:{},
// foot:{ details: ['foot_network', 'access_conditional', 'foot_conditional'] }, hike:{ details: ['foot_network', 'access_conditional', 'foot_conditional'] },
// bike:{ details: ['get_off_bike', 'bike_network', 'access_conditional', 'bike_conditional' ] }, mtb:{ details: ['get_off_bike', 'bike_network', 'access_conditional', 'bike_conditional'] }, racingbike:{ details: ['get_off_bike', 'bike_network', 'access_conditional', 'bike_conditional'] },
// foot:{ details: ['foot_network', 'access_conditional', 'foot_conditional', 'hike_rating'] }, hike:{ details: ['foot_network', 'access_conditional', 'foot_conditional', 'hike_rating' ] },
// bike:{ details: ['get_off_bike', 'bike_network', 'access_conditional', 'bike_conditional' ] }, mtb:{ details: ['get_off_bike', 'bike_network', 'access_conditional', 'bike_conditional', 'mtb_rating'] }, racingbike:{ details: ['get_off_bike', 'bike_network', 'access_conditional', 'bike_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 @@ -106,6 +106,8 @@ interface Details {
readonly track_type: [number, number, string][]
readonly country: [number, number, string][]
readonly get_off_bike: [number, number, boolean][]
readonly mtb_rating: [number, number, boolean][]
readonly hike_rating: [number, number, boolean][]
}

export interface GeocodingResult {
Expand Down
46 changes: 43 additions & 3 deletions src/sidebar/RoutingResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,17 @@ function RoutingResult({
const footAccessCondInfo = !ApiImpl.isFootLike(profile)
? new RouteInfo()
: getInfoFor(path.points, path.details.foot_conditional, s => s != null && s.length > 0)
const hikeRatingInfo = !ApiImpl.isFootLike(profile)
? new RouteInfo()
: getInfoFor(path.points, path.details.hike_rating, s => s > 0)

const bikeAccessCondInfo = !ApiImpl.isBikeLike(profile)
? new RouteInfo()
: getInfoFor(path.points, path.details.bike_conditional, s => s != null && s.length > 0)
const mtbRatingInfo = !ApiImpl.isBikeLike(profile)
? new RouteInfo()
: getInfoFor(path.points, path.details.mtb_rating, s => s > 1)

const privateOrDeliveryInfo = ApiImpl.isMotorVehicle(profile)
? getInfoFor(
path.points,
Expand Down Expand Up @@ -118,6 +126,8 @@ function RoutingResult({
stepsInfo.distance > 0 ||
borderInfo.values.length > 0 ||
getOffBikeInfo.distance > 0 ||
mtbRatingInfo.distance > 0 ||
hikeRatingInfo.distance > 0 ||
steepInfo.distance > 0

const settings = useContext(SettingsContext)
Expand Down Expand Up @@ -268,6 +278,34 @@ function RoutingResult({
segments={tollInfo.segments}
values={[]}
/>
<RHButton
setDescription={b => setDescriptionRH(b)}
description={tr('way_contains', [tr('challenging_sections')])}
setType={t => setSelectedRH(t)}
type={'mtb_rating'}
child={<DangerousIcon />}
value={
mtbRatingInfo.distance > 0 &&
metersToShortText(mtbRatingInfo.distance, showDistanceInMiles)
}
selected={selectedRH}
segments={mtbRatingInfo.segments}
values={mtbRatingInfo.values}
/>
<RHButton
setDescription={b => setDescriptionRH(b)}
description={tr('way_contains', [tr('challenging_sections')])}
setType={t => setSelectedRH(t)}
type={'hike_rating'}
child={<DangerousIcon />}
value={
hikeRatingInfo.distance > 0 &&
metersToShortText(hikeRatingInfo.distance, showDistanceInMiles)
}
selected={selectedRH}
segments={hikeRatingInfo.segments}
values={hikeRatingInfo.values}
/>
<RHButton
setDescription={b => setDescriptionRH(b)}
description={tr('way_contains', [tr('steps')])}
Expand Down Expand Up @@ -366,9 +404,11 @@ function RHButton(p: {
let tmpDescription
if (p.type == 'get_off_bike') tmpDescription = p.description
else if (p.type == 'border') tmpDescription = p.description + ': ' + p.values[index]
else if (p.values && p.values[index])
tmpDescription = p.description + ': ' + p.value + ' ' + p.values[index]
else tmpDescription = p.description + ': ' + p.value
else if (p.values && p.values[index]) {
if (p.type.includes('rating'))
tmpDescription = p.description + ': ' + p.value + ' (' + p.type + ':' + p.values[index] + ')'
else tmpDescription = p.description + ': ' + p.value + ' ' + p.values[index]
} else tmpDescription = p.description + ': ' + p.value

p.setDescription(tmpDescription)
Dispatcher.dispatch(new PathDetailsElevationSelected(p.segments))
Expand Down
2 changes: 2 additions & 0 deletions src/stores/RouteStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export default class RouteStore extends Store<RouteStoreState> {
track_type: [],
country: [],
get_off_bike: [],
mtb_rating: [],
hike_rating: [],
},
distance: 0,
points_order: [],
Expand Down
Loading

0 comments on commit 5df77da

Please sign in to comment.