Skip to content

Commit 8b16da5

Browse files
authored
add combobox for speed types (#319)
1 parent ac0837d commit 8b16da5

File tree

9 files changed

+540
-8
lines changed

9 files changed

+540
-8
lines changed

package-lock.json

Lines changed: 67 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"check:deps": "npx taze@latest -Ilwr"
3131
},
3232
"dependencies": {
33+
"@base-ui/react": "^1.1.0",
3334
"@dnd-kit/core": "^6.3.1",
3435
"@dnd-kit/sortable": "^10.0.0",
3536
"@dnd-kit/utilities": "^3.2.2",

src/components/settings-panel/settings-options.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ interface EnumSetting {
2121
enums: Array<{ key: string; text: string; value: string }>;
2222
}
2323

24+
interface ListSetting {
25+
name: string;
26+
param: string;
27+
description: string;
28+
options: Array<string>;
29+
}
30+
2431
interface SettingsGroup {
2532
numeric: NumericSetting[];
2633
boolean: BooleanSetting[];
2734
enum: EnumSetting[];
35+
list: ListSetting[];
2836
}
2937

3038
export type SettingsProfile =
@@ -39,11 +47,13 @@ export type SettingsProfile =
3947
const createSettings = (
4048
numeric: NumericSetting[],
4149
boolean: BooleanSetting[],
42-
enumSettings: EnumSetting[] = []
50+
enumSettings: EnumSetting[] = [],
51+
listSettings: ListSetting[] = []
4352
): SettingsGroup => ({
4453
numeric: [...numeric],
4554
boolean: [...boolean],
4655
enum: enumSettings,
56+
list: listSettings,
4757
});
4858

4959
const length = {
@@ -256,6 +266,13 @@ const includeHot = {
256266
"A boolean value which indicates the desire to include tolled HOV roads which require the driver to pay a toll if the occupant requirement isn't met. Default false.",
257267
};
258268

269+
const speedTypes = {
270+
name: 'Speed Types',
271+
param: 'speed_types',
272+
description: 'Which speed types to use.',
273+
options: ['current', 'predicted', 'freeflow', 'constrained'],
274+
};
275+
259276
const transitStartEndMaxDistance = {
260277
name: 'Transit Start/End Max Distance',
261278
param: 'transit_start_end_max_distance',
@@ -851,6 +868,7 @@ export const settingsInit = {
851868
denoise: 0.1,
852869
generalize: 0,
853870
alternates: 0,
871+
speed_types: ['current', 'freeflow', 'predicted', 'constrained'],
854872
};
855873

856874
export const settingsInitTruckOverride = {
@@ -918,17 +936,23 @@ export const profileSettings: Record<SettingsProfile, SettingsGroup> = {
918936
...borderSettings,
919937
useTruckRoutes,
920938
],
921-
[hazardousMaterials, shortest, ignoreHierarchies]
939+
[hazardousMaterials, shortest, ignoreHierarchies],
940+
[],
941+
[speedTypes]
922942
),
923943

924944
car: createSettings(
925945
[...commonVehicleProfileNumeric],
926-
[...commonVehicleProfileBoolean]
946+
[...commonVehicleProfileBoolean],
947+
[],
948+
[speedTypes]
927949
),
928950

929951
bus: createSettings(
930952
[length, weight, ...commonVehicleProfileNumeric],
931-
[...commonVehicleProfileBoolean]
953+
[...commonVehicleProfileBoolean],
954+
[],
955+
[speedTypes]
932956
),
933957

934958
pedestrian: createSettings(
@@ -955,7 +979,9 @@ export const profileSettings: Record<SettingsProfile, SettingsGroup> = {
955979
...gateSettings,
956980
...borderSettings,
957981
],
958-
[shortest, ignoreHierarchies]
982+
[shortest, ignoreHierarchies],
983+
[],
984+
[speedTypes]
959985
),
960986

961987
bicycle: createSettings(
@@ -966,7 +992,9 @@ export const profileSettings: Record<SettingsProfile, SettingsGroup> = {
966992

967993
motorcycle: createSettings(
968994
[...commonVehicleProfileNumeric],
969-
[...commonVehicleProfileBoolean]
995+
[...commonVehicleProfileBoolean],
996+
[],
997+
[speedTypes]
970998
),
971999
};
9721000

src/components/settings-panel/settings-panel.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { useDirectionsQuery } from '@/hooks/use-directions-queries';
3737
import { useIsochronesQuery } from '@/hooks/use-isochrones-queries';
3838
import { CollapsibleSection } from '@/components/ui/collapsible-section';
3939
import { ServerSettings } from '@/components/settings-panel/server-settings';
40+
import { MultiSelectSetting } from '../ui/multiselect-setting';
4041

4142
type ProfileWithSettings = Exclude<Profile, 'auto'>;
4243

@@ -238,6 +239,26 @@ export const SettingsPanel = () => {
238239
/>
239240
)
240241
)}
242+
{profileSettings[profile as ProfileWithSettings].list.map(
243+
(option, key) => (
244+
<MultiSelectSetting
245+
key={key}
246+
id={option.param}
247+
label={option.name}
248+
description={option.description}
249+
value={
250+
(settings[option.param] as string[]) ?? ['current']
251+
}
252+
options={option.options}
253+
onValueChange={(value) => {
254+
handleUpdateSettings({
255+
name: option.param,
256+
value,
257+
});
258+
}}
259+
/>
260+
)
261+
)}
241262
</div>
242263
</CollapsibleSection>
243264
)}

src/components/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@ export interface PossibleSettings {
7979
denoise: number;
8080
generalize: number;
8181
alternates: number;
82-
[key: string]: string | number | boolean | GeoJSON.GeoJSON[] | undefined;
82+
speed_types: string[];
83+
[key: string]:
84+
| string
85+
| string[]
86+
| number
87+
| boolean
88+
| GeoJSON.GeoJSON[]
89+
| undefined;
8390
}
8491

8592
export interface ParsedDirectionsGeometry {

0 commit comments

Comments
 (0)