Skip to content

Commit 87acad8

Browse files
authored
mapping of profile groups (#401)
* mapping of profile groups * make group options usable for all profiles * simplify * formatting * fix test * minor fixes and only group ecargobike and racingbike * move helper/utils out of QueryStore into utils.ts * avoid unrelated changes * reduce changes * minor * lastProfiles not working anyway * keep track of option (profile) in a certain group * avoid error in console * minor renames
1 parent 3305d66 commit 87acad8

18 files changed

Lines changed: 872 additions & 43 deletions

File tree

config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ const config = {
4545
//
4646
// 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
4747
// bike: { profile: 'raw_bike', ... }
48+
49+
// You can 'collapse' or group certain profiles to reduce the number of profiles in the panel. Instead they're listed in the settings but still a profile icon is shown.
50+
// Note: the name of the group must be the default option for this group.
51+
// profile_group_mapping: {
52+
// car: {
53+
// options: [
54+
// { profile: 'car' },
55+
// { profile: 'car_avoid_motorway' },
56+
// { profile: 'car_avoid_ferry' },
57+
// { profile: 'car_avoid_toll' }
58+
// ]
59+
// },
60+
// bike: {
61+
// options: [
62+
// { profile: 'bike' },
63+
// { profile: 'mtb' },
64+
// { profile: 'racingbike' },
65+
// { profile: 'ecargobike' }
66+
// ]
67+
// }
68+
// }
4869
}
4970

5071
// this is needed for jest (with our current setup at least)

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function LargeScreenLayout({ query, route, map, error, mapOptions, encodedValues
192192
drawAreas={drawAreas}
193193
/>
194194
)}
195-
<Search points={query.queryPoints} map={map} />
195+
<Search points={query.queryPoints} profile={query.routingProfile} map={map} />
196196
<div>{!error.isDismissed && <ErrorMessage error={error} />}</div>
197197
<RoutingResults
198198
info={route.routingResult.info}

src/actions/Actions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ export class SetVehicleProfile implements Action {
3737
}
3838
}
3939

40+
export class SetVehicleProfileGroup implements Action {
41+
readonly group: string
42+
43+
constructor(group: string) {
44+
this.group = group
45+
}
46+
}
47+
4048
export class AddPoint implements Action {
4149
readonly atIndex: number
4250
readonly coordinate: Coordinate

src/api/Api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export class ApiImpl implements Api {
445445

446446
public static isMotorVehicle(profile: string) {
447447
return (
448-
profile.includes('car') ||
448+
(profile.includes('car') && !profile.includes('cargobike')) ||
449449
profile.includes('truck') ||
450450
profile.includes('scooter') ||
451451
profile.includes('bus') ||

src/custom.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ declare module 'heightgraph/src/heightgraph'
55
declare module 'custom-model-editor/src/index'
66

77
declare module 'config' {
8+
interface ProfileGroup {
9+
readonly options: { profile: string }[]
10+
}
11+
812
const routingApi: string
913
const geocodingApi: string
1014
const defaultTiles: string
@@ -31,6 +35,7 @@ declare module 'config' {
3135
}
3236
maxZoom?: number
3337
}
38+
const profile_group_mapping: Record<string, ProfileGroup>
3439
const profiles: object
3540
}
3641

src/map/findNextWayPoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Coordinate } from '@/stores/QueryStore'
2-
import { calcDist } from '@/distUtils'
2+
import { calcDist } from '@/utils'
33

44
/**
55
* Finds the way-point that follows the part of a route that is closest to a given location

src/pathDetails/PathDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Dispatcher from '@/stores/Dispatcher'
77
import { PathDetailsElevationSelected, PathDetailsHover, PathDetailsRangeSelected } from '@/actions/Actions'
88
import QueryStore, { Coordinate, QueryPointType } from '@/stores/QueryStore'
99
import { Position } from 'geojson'
10-
import { calcDist } from '@/distUtils'
10+
import { calcDist } from '@/utils'
1111
import { tr } from '@/translation/Translation'
1212
import { SettingsContext } from '@/contexts/SettingsContext'
1313

src/sidebar/MobileSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default function ({ query, route, error, encodedValues, drawAreas, map }:
7474
drawAreas={drawAreas}
7575
/>
7676
)}
77-
<Search points={query.queryPoints} map={map} />
77+
<Search points={query.queryPoints} profile={query.routingProfile} map={map} />
7878
</div>
7979
)}
8080
{!error.isDismissed && <ErrorMessage error={error} />}

src/sidebar/RoutingResults.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Details from '@/sidebar/list.svg'
1010
import GPXDownload from '@/sidebar/file_download.svg'
1111
import Instructions from '@/sidebar/instructions/Instructions'
1212
import { LineString, Position } from 'geojson'
13-
import { calcDist } from '@/distUtils'
13+
import { calcDist } from '@/utils'
1414
import { useMediaQuery } from 'react-responsive'
1515
import { tr } from '@/translation/Translation'
1616
import { ApiImpl } from '@/api/Api'

src/sidebar/SettingsBox.module.css

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@
2626
align-items: center;
2727
}
2828

29+
.groupProfileOptionsHeader {
30+
font-weight: bold;
31+
}
32+
33+
.groupProfileOptions div {
34+
padding: 4px 20px;
35+
}
36+
37+
.groupProfileOptions label,
38+
input {
39+
cursor: pointer;
40+
}
41+
42+
.groupProfileOptions label {
43+
margin-left: 10px;
44+
}
45+
2946
.toggleButton {
3047
display: flex;
3148
align-items: center;
@@ -73,7 +90,8 @@
7390

7491
.title,
7592
.infoLine,
76-
.settingsTable {
93+
.settingsTable,
94+
.groupProfileOptionsHeader {
7795
font-size: 14px;
7896
color: gray;
7997
}

0 commit comments

Comments
 (0)