Skip to content

Commit

Permalink
Merge pull request #11 from openTdataCH/feature/taxi-booking
Browse files Browse the repository at this point in the history
Adds support for taxi mode (with booking)
  • Loading branch information
vasile authored Feb 19, 2023
2 parents 2d9d87e + e31ae92 commit 3baf385
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.9.4 - 19.02.2023
- Expose `ojp:LocationExtensionStructure` nodes from `Location` - see [Showing multiple Charging Points of One Charging Station #68](https://github.com/openTdataCH/ojp-demo-app-src/issues/68), [#9](https://github.com/openTdataCH/ojp-js/pull/9)
- Adds support for more values of on-demand bus mode - [#10](https://github.com/openTdataCH/ojp-js/pull/10)
- Adds support for taxi / booking via `ojp:BookingArrangements/ojp:BookingArrangement` - see [OJP demo app extension #87](https://github.com/openTdataCH/ojp-demo-app-src/issues/87), [#11](https://github.com/openTdataCH/ojp-js/pull/11)

## 0.9.3 - 22.01.2023
- Show transfer path guidance on the map - see [#5](https://github.com/openTdataCH/ojp-js/pull/5)
Expand Down
1 change: 1 addition & 0 deletions src/trip/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './leg/continous-leg/service-booking'
export * from './leg/timed-leg/stop-point-time'
export * from './leg/trip-leg'
export * from './leg/trip-continous-leg'
Expand Down
70 changes: 70 additions & 0 deletions src/trip/leg/continous-leg/service-booking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { XPathOJP } from "../../../helpers/xpath-ojp"

export interface BookingArrangement {
agencyCode: string,
agencyName: string,
infoURL: string,
}

export class ServiceBooking {
public bookingArrangements: BookingArrangement[]

constructor(bookingArrangements: BookingArrangement[]) {
this.bookingArrangements = bookingArrangements;
}

public static initWithContextNode(contextNode: Node): ServiceBooking | null {
const bookingArrangementsNodes = XPathOJP.queryNodes('ojp:service/ojp:BookingArrangements/ojp:BookingArrangement', contextNode);
if (bookingArrangementsNodes.length === 0) {
console.error('ERROR - no BookingArrangements nodes found');
return null;
}

const bookingArrangements: BookingArrangement[] = [];
bookingArrangementsNodes.forEach(bookingNode => {
const agencyCode = XPathOJP.queryText('ojp:BookingAgencyName/ojp:Text', bookingNode);
let infoURL = XPathOJP.queryText('ojp:InfoUrl', bookingNode);

if ((agencyCode === null) || (infoURL === null)) {
return;
}

infoURL = infoURL.trim();

if (infoURL.length < 2) {
return null;
}
// strip out <>
infoURL = infoURL.substring(1, infoURL.length - 1);

var el = document.createElement('textarea');
el.innerHTML = infoURL.trim();
infoURL = el.innerText;

bookingArrangements.push({
agencyCode: agencyCode.trim(),
agencyName: ServiceBooking.computeAgencyName(agencyCode),
infoURL: infoURL,
});
});

const serviceBooking = new ServiceBooking(bookingArrangements);

return serviceBooking;
}

private static computeAgencyName(agencyCode: string): string {
agencyCode = agencyCode.trim();
if (agencyCode === 'catalog_taxi_local.ch') {
return 'local.ch';
}
if (agencyCode === 'catalog_taxi_maps.google.ch') {
return 'maps.google.com';
}
if (agencyCode === 'catalog_taxi_openstreetmap.org') {
return 'openstreetmap.org';
}

return 'n/a catalog';
}
}
40 changes: 30 additions & 10 deletions src/trip/leg/trip-continous-leg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ import { TripLegPropertiesEnum, TripLegDrawType, TripLegLineType } from '../../t
import { MapLegLineTypeColor } from '../../config/map-colors'
import { Duration } from '../../shared/duration'
import { IndividualTransportMode } from '../../types/individual-mode.types'
import { ServiceBooking } from './continous-leg/service-booking'

export class TripContinousLeg extends TripLeg {
public legTransportMode: IndividualTransportMode | null
public legDistance: number
public pathGuidance: PathGuidance | null
public walkDuration: Duration | null
public serviceBooking: ServiceBooking | null;

constructor(legType: LegType, legIDx: number, legDistance: number, fromLocation: Location, toLocation: Location) {
super(legType, legIDx, fromLocation, toLocation)

this.legTransportMode = null
this.legDistance = legDistance
this.pathGuidance = null
this.walkDuration = null
this.walkDuration = null;
this.serviceBooking = null;
}

public static initFromTripLeg(legIDx: number, legNode: Node | null, legType: LegType): TripContinousLeg | null {
Expand All @@ -50,7 +53,10 @@ export class TripContinousLeg extends TripLeg {
tripLeg.legDuration = Duration.initFromContextNode(legNode)

tripLeg.pathGuidance = PathGuidance.initFromTripLeg(legNode);
tripLeg.legTransportMode = tripLeg.computeLegTransportMode(legNode)
tripLeg.legTransportMode = tripLeg.computeLegTransportMode(legNode);
if (tripLeg.legTransportMode === 'taxi') {
tripLeg.serviceBooking = ServiceBooking.initWithContextNode(legNode);
}

tripLeg.legTrack = LegTrack.initFromLegNode(legNode);

Expand Down Expand Up @@ -79,6 +85,10 @@ export class TripContinousLeg extends TripLeg {
return 'cycle'
}

if (legModeS === 'taxi') {
return 'taxi'
}

return null
}

Expand All @@ -101,6 +111,10 @@ export class TripContinousLeg extends TripLeg {
return this.legTransportMode === 'walk';
}

public isTaxi(): boolean {
return this.legTransportMode === 'taxi';
}

protected override computeSpecificJSONFeatures(): GeoJSON.Feature[] {
const features: GeoJSON.Feature[] = [];

Expand Down Expand Up @@ -140,14 +154,16 @@ export class TripContinousLeg extends TripLeg {
}

protected override computeLegLineType(): TripLegLineType {
if (this.legType === 'ContinousLeg') {
if (this.isDriveCarLeg()) {
return 'Self-Drive Car'
}
if (this.isDriveCarLeg()) {
return 'Self-Drive Car'
}

if (this.isSharedMobility()) {
return 'Shared Mobility'
}
if (this.isSharedMobility()) {
return 'Shared Mobility'
}

if (this.isTaxi()) {
return 'OnDemand';
}

if (this.legType === 'TransferLeg') {
Expand Down Expand Up @@ -181,7 +197,11 @@ export class TripContinousLeg extends TripLeg {
return MapLegLineTypeColor.Transfer
}

return MapLegLineTypeColor.Walk
if (this.isTaxi()) {
return MapLegLineTypeColor.OnDemand;
}

return MapLegLineTypeColor.Walk;
}

public formatDistance(): string {
Expand Down
2 changes: 1 addition & 1 deletion src/types/individual-mode.types.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type IndividualTransportMode = 'public_transport' | 'walk' | 'cycle' | 'escooter_rental' | 'car_sharing' | 'car_self_driving' | 'bicycle_rental' | 'charging_station'
export type IndividualTransportMode = 'public_transport' | 'walk' | 'cycle' | 'escooter_rental' | 'car_sharing' | 'car_self_driving' | 'bicycle_rental' | 'charging_station' | 'taxi'

0 comments on commit 3baf385

Please sign in to comment.