Skip to content

Commit

Permalink
feat(trip-planner): Allow to select different route profile
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacura committed Jun 12, 2024
1 parent 85e9fe5 commit 3963e7f
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 7 deletions.
16 changes: 14 additions & 2 deletions projects/hslayers/assets/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1042,14 +1042,26 @@
"TRIP_PLANNER": {
"clearWaypoints": "Vyčistit body trasy",
"missingAuth": "Přístup k navigační službě nepovolen",
"noRoutablePoint": "Nebyl nalezen směrovatelný bod trasy",
"noRoutablePoint": "Trasa mezi zadanými body nebyla nalezena",
"profiles": {
"driving-car": "automobil osobní",
"driving-hgv": "automobil nákladní",
"cycling-regular": "jízdní kolo běžné",
"cycling-road": "jízdní kolo silniční",
"cycling-mountain": "jízdní kolo horské",
"cycling-electric": "jízdní elektrokolo",
"foot-walking": "pěší - běžná chůze",
"foot-hiking": "pěší - turistika",
"wheelchair": "invalidní vozík"
},
"removeWaypoint": "Odebrat bod trasy",
"routerLayer": "Vrstva s trasou",
"serviceDown": "Navigační služba zdá se nefunguje. Je nám líto!",
"totalDistance": "Celková vzdálenost",
"travelRoute": "Trasa výletu",
"waypointDrawingHint": "Klikněte prosím do mapy pro přidání bodů trasy",
"waypointLayer": "Vrstva s body trasy",
"waypoints": "Body trasy"
"waypoints": "Body trasy",
"selectProfile": "Vyberte způsob dopravy"
}
}
5 changes: 3 additions & 2 deletions projects/hslayers/assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1042,14 +1042,15 @@
"TRIP_PLANNER": {
"clearWaypoints": "Clear waypoints",
"missingAuth": "Routing service not authorized",
"noRoutablePoint": "No routable point found",
"noRoutablePoint": "No route between waypoints could be found",
"removeWaypoint": "Remove waypoint",
"routerLayer": "Route layer",
"serviceDown": "Navigation service seems to be down. We are sorry!",
"totalDistance": "Total distance",
"travelRoute": "Travel route",
"waypointDrawingHint": "Please click on map to add waypoints",
"waypointLayer": "Waypoint layer",
"waypoints": "Waypoints"
"waypoints": "Waypoints",
"selectProfile": "Select transportation mode"
}
}
13 changes: 13 additions & 0 deletions projects/hslayers/components/trip-planner/ors-profiles.const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const profiles = [
'driving-car',
'driving-hgv',
'cycling-regular',
'cycling-road',
'cycling-mountain',
'cycling-electric',
'foot-walking',
'foot-hiking',
'wheelchair',
] as const;

export type RouteProfile = (typeof profiles)[number];
2 changes: 2 additions & 0 deletions projects/hslayers/components/trip-planner/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export * from './layer-selector.component';
export * from './ors-profiles.const';
export * from './route-profile-selector.component';
export * from './trip-planner.component';
export * from './trip-planner.module';
export * from './trip-planner.service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="flex-row w-100 m-auto justify-content-center align-items-center" style="display: flex">
<p class="m-0 p-0 flex-fill text-primary">{{'TRIP_PLANNER.selectProfile' | translateHs}}:</p>
<div ngbDropdown placement="bottom" style="max-width: 50%">
<button type="button" ngbDropdownToggle
class="btn btn-sm rounded-0 hs-toolbar-button d-flex align-items-center mw-100" aria-haspopup="true"
(click)="profilesExpanded = !profilesExpanded"
[attr.aria-expanded]="profilesExpanded">
<div class="text-truncate" *ngIf="selectedProfile !== undefined">
{{selectedProfile | translateHs : {module: 'TRIP_PLANNER.profiles'} }}
</div>
</button>
<div ngbDropdownMenu [ngClass]="{'show': profilesExpanded}" style="transform: translateX(25%); width: 15em">
<div class="d-flex align-items-center w-100 flex-column">
<a class="dropdown-item text-truncate" *ngFor="let profile of hsTripPlannerService.orsProfiles"
data-toggle="tooltip" [title]="profile | translateHs : {module: 'TRIP_PLANNER.profiles'}"
(click)="hsTripPlannerService.selectProfile(profile); profilesExpanded = false">{{profile |
translateHs : {module: 'TRIP_PLANNER.profiles'} }}</a>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Component, Input} from '@angular/core';

import {HsTripPlannerService} from './trip-planner.service';
import {RouteProfile} from './ors-profiles.const';

@Component({
selector: 'hs-trip-planner-profile-selector',
templateUrl: './route-profile-selector.component.html',
})
export class HsTripPlannerProfileSelectorComponent {
@Input() selectedProfile: RouteProfile;
profilesExpanded: boolean;

constructor(public hsTripPlannerService: HsTripPlannerService) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<hs-trip-planner-layer-selector usage="waypoints" [label]="'TRIP_PLANNER.waypointLayer' | translateHs"
[selectedWrapper]="HsTripPlannerService.selectedLayerWrapper.waypoints">
</hs-trip-planner-layer-selector>
<hs-trip-planner-profile-selector [selectedProfile]="HsTripPlannerService.selectedProfile"></hs-trip-planner-profile-selector>

<div *ngFor="let waypoint of HsTripPlannerService.waypoints" class="d-flex flex-row">
<div class="p-1 flex-grow-1">
Expand Down
13 changes: 11 additions & 2 deletions projects/hslayers/components/trip-planner/trip-planner.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import {
} from 'hslayers-ng/common/panels';
import {HsTripPlannerComponent} from './trip-planner.component';
import {HsTripPlannerLayerSelectorComponent} from './layer-selector.component';
import {HsTripPlannerProfileSelectorComponent} from './route-profile-selector.component';
import {TranslateCustomPipe} from 'hslayers-ng/services/language';

@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [HsTripPlannerComponent, HsTripPlannerLayerSelectorComponent],
declarations: [
HsTripPlannerComponent,
HsTripPlannerLayerSelectorComponent,
HsTripPlannerProfileSelectorComponent,
],
imports: [
FormsModule,
CommonModule,
Expand All @@ -22,6 +27,10 @@ import {TranslateCustomPipe} from 'hslayers-ng/services/language';
HsPanelHeaderComponent,
NgbDropdownModule,
],
exports: [HsTripPlannerComponent, HsTripPlannerLayerSelectorComponent],
exports: [
HsTripPlannerComponent,
HsTripPlannerLayerSelectorComponent,
HsTripPlannerProfileSelectorComponent,
],
})
export class HsTripPlannerModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {HsMapService} from 'hslayers-ng/services/map';
import {HsShareUrlService} from 'hslayers-ng/services/share';
import {HsToastService} from 'hslayers-ng/common/toast';
import {HsUtilsService} from 'hslayers-ng/services/utils';
import {RouteProfile, profiles} from './ors-profiles.const';
import {getHighlighted} from 'hslayers-ng/common/extensions';
import {getTitle, setTitle} from 'hslayers-ng/common/extensions';

Expand Down Expand Up @@ -51,6 +52,7 @@ export class HsTripPlannerService {
waypointRouteStyle;
waypoints: Waypoint[] = [];
trip: any = {};
orsProfiles = profiles;
movable_features = new Collection<Feature<Geometry>>();
modify: Modify;
waypointSource: VectorSource<Feature<Point>>;
Expand All @@ -63,6 +65,7 @@ export class HsTripPlannerService {
route?: {layer: VectorLayer<Feature>; title: string};
waypoints?: {layer: VectorLayer<Feature>; title: string};
} = {};
selectedProfile: RouteProfile = profiles[0];

constructor(
public HsMapService: HsMapService,
Expand Down Expand Up @@ -259,6 +262,14 @@ export class HsTripPlannerService {
}
}

async selectProfile(profile: RouteProfile): Promise<void> {
this.selectedProfile = profile;
for (const wp of this.waypoints) {
this.removeRoutesForWaypoint(wp);
}
await this.calculateRoutes();
}

getTextOnFeature(feature: Feature<Geometry>): string {
let tmp = '';
const wp: Waypoint = getWaypoint(feature);
Expand Down Expand Up @@ -429,7 +440,7 @@ export class HsTripPlannerService {
const wpt = this.waypoints[i + 1];
wpt.loading = true;
const url = this.HsUtilsService.proxify(
'https://api.openrouteservice.org/v2/directions/driving-car/geojson',
`https://api.openrouteservice.org/v2/directions/${this.selectedProfile}/geojson`,
);
const response = await lastValueFrom(
this.$http
Expand Down

0 comments on commit 3963e7f

Please sign in to comment.