@wemap/routers 12.12.4 → 13.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,13 @@
1
+ import { StepDirection } from './model/Step';
1
2
  /**
2
3
  * Get route duration
3
4
  * @param {Number} speed in km/h
4
5
  * @returns {Number} duration in seconds
5
6
  */
6
7
  export declare function getDurationFromLength(length: number, speed?: number): number;
8
+ /**
9
+ * Get direction from angle (radians)
10
+ * @param {Number} angle in radians
11
+ * @returns {String} direction
12
+ */
13
+ export declare function getDirectionFromAngle(_angle: number): StepDirection;
@@ -47,6 +47,8 @@ export default class Itinerary {
47
47
  get coords(): Coordinates[];
48
48
  set steps(_: Step[]);
49
49
  get steps(): Step[];
50
+ set price(_: number);
51
+ get price(): number;
50
52
  set transitMode(_: TransitMode);
51
53
  get transitMode(): TransitMode;
52
54
  set distance(_: number);
@@ -76,6 +78,8 @@ export default class Itinerary {
76
78
  * - all steps number
77
79
  * - first/last steps
78
80
  * - previousBearing/nextBearing/angle of first and last step of each leg
81
+ * - distance/duration of first and last step of each leg
82
+ * - remove type depart | arrive if step is not first or last
79
83
  */
80
84
  updateStepsFromLegs(): void;
81
85
  }
@@ -20,6 +20,7 @@ export type TransportInfo = {
20
20
  routeColor?: string;
21
21
  routeTextColor?: string;
22
22
  directionName?: string;
23
+ price?: number;
23
24
  };
24
25
  type LegCommon = {
25
26
  transitMode: TransitMode;
@@ -1,10 +1,22 @@
1
1
  import { Coordinates, CoordinatesCompressedJson } from '@wemap/geo';
2
- import { LevelChange } from './LevelChange.js';
3
- import { StepExtra } from './StepExtra.js';
4
- export type Step = {
2
+ type AtLeast<T, K extends keyof T> = Partial<T> & Pick<T, K>;
3
+ export declare const SHARED_STEP_TYPE: readonly ["moving-walkway"];
4
+ export type SharedStepType = typeof SHARED_STEP_TYPE[number];
5
+ export declare const VERTICAL_STEP_TYPE: readonly ["moving-walkway", "elevator", "escalator", "stairs", "incline-plane"];
6
+ export type VerticalStepType = typeof VERTICAL_STEP_TYPE[number];
7
+ export declare const VERTICAL_DIRECTION: readonly ["up", "down"];
8
+ export type VerticalDirection = typeof VERTICAL_DIRECTION[number];
9
+ export declare const HORIZONTAL_STEP_TYPE: readonly ["moving-walkway", "depart", "turn", "continue", "roundabout", "exit-roundabout", "arrive", "subway-entrance", "gate", "transit"];
10
+ export type HorizontalStepType = typeof HORIZONTAL_STEP_TYPE[number];
11
+ export declare const HORIZONTAL_DIRECTION: readonly ["straight", "right", "slight-right", "sharp-right", "left", "slight-left", "sharp-left", "u-turn"];
12
+ export type HorizontalDirection = typeof HORIZONTAL_DIRECTION[number];
13
+ export type StepDirection = VerticalDirection | HorizontalDirection;
14
+ export type StepType = VerticalStepType | HorizontalStepType;
15
+ interface BaseStep {
5
16
  firstStep: boolean;
6
17
  lastStep: boolean;
7
18
  number: number;
19
+ levelDifference: number | null;
8
20
  angle: number;
9
21
  previousBearing: number;
10
22
  nextBearing: number;
@@ -12,31 +24,34 @@ export type Step = {
12
24
  duration: number;
13
25
  readonly coords: Coordinates;
14
26
  readonly name: string | null;
15
- readonly levelChange: LevelChange | null;
16
- readonly extras: StepExtra | null;
17
- };
27
+ }
28
+ interface VerticalStep extends BaseStep {
29
+ type: VerticalStepType | null;
30
+ direction: VerticalDirection;
31
+ }
32
+ interface HorizontalStep extends BaseStep {
33
+ type: HorizontalStepType | null;
34
+ direction: HorizontalDirection | null;
35
+ }
36
+ export type Step = VerticalStep | HorizontalStep;
18
37
  export type StepJson = {
19
38
  firstStep?: boolean;
20
39
  lastStep?: boolean;
21
40
  number: number;
22
41
  coords: CoordinatesCompressedJson;
23
42
  name?: string;
43
+ type: StepType | null;
24
44
  angle: number;
45
+ direction: StepDirection | null;
25
46
  previousBearing: number;
26
47
  nextBearing: number;
27
48
  distance: number;
28
49
  duration: number;
29
- levelChange?: LevelChange;
30
- extras?: StepExtra;
31
- };
32
- export type MinStepInfo = {
33
- coords: Coordinates;
34
- name?: string;
35
- levelChange?: LevelChange;
36
- extras?: StepExtra;
37
- distance?: number;
38
- duration?: number;
50
+ levelDifference?: number | null;
39
51
  };
52
+ export type MinStepInfo = AtLeast<Step, 'coords'>;
40
53
  export declare function stepToJson(step: Step): StepJson;
41
54
  export declare function jsonToStep(json: StepJson): Step;
42
55
  export declare function stepEquals(step1: Step, step2: Step): boolean;
56
+ export declare function isStepLevelChange(step?: Step | MinStepInfo | null): step is VerticalStep;
57
+ export {};
@@ -53,9 +53,6 @@ declare const remoteRouters: readonly [{
53
53
  };
54
54
  };
55
55
  Arrival: {
56
- /**
57
- * Singleton
58
- */
59
56
  Time: string;
60
57
  Site: {
61
58
  Name: string;
@@ -118,9 +115,6 @@ declare const remoteRouters: readonly [{
118
115
  };
119
116
  };
120
117
  Arrival: {
121
- /**
122
- * Singleton
123
- */
124
118
  Time: string;
125
119
  Site: {
126
120
  Name: string;
@@ -543,9 +537,11 @@ declare const remoteRouters: readonly [{
543
537
  getItineraries(endpointUrl: string, routerRequest: RouterRequest): Promise<import('../model/Itinerary.js').default[]>;
544
538
  getURL(endpointUrl: string, routerRequest: RouterRequest): string;
545
539
  inputModeCorrespondance: (routerRequest: RouterRequest) => "walking" | "bike" | "driving" | "pmr" | "bike-safest" | "bike-fastest";
540
+ osrmTypeToStepType(type: "depart" | "turn" | "roundabout" | "arrive" | "exit roundabout"): "moving-walkway" | "depart" | "turn" | "continue" | "roundabout" | "exit-roundabout" | "arrive" | "subway-entrance" | "gate" | "transit";
541
+ osrmModifierToStepDirection(modifier: "straight" | "right" | "left" | "sharp right" | "sharp left" | "slight right" | "slight left" | "u turn"): "straight" | "right" | "slight-right" | "sharp-right" | "left" | "slight-left" | "sharp-left" | "u-turn";
546
542
  coordinatesToJson({ lat, lng, level }: import('@wemap/geo/dist/src/coordinates/Coordinates.js').default): import('geojson').Position;
547
543
  jsonToCoordinates(json: import('geojson').Position): import('@wemap/geo/dist/src/coordinates/Coordinates.js').default;
548
- getModifierFromAngle(_angle: number): "sharp right" | "sharp left" | "slight right" | "slight left" | "right" | "left" | "u turn" | "straight";
544
+ getModifierFromAngle(_angle: number): "straight" | "right" | "left" | "sharp right" | "sharp left" | "slight right" | "slight left" | "u turn";
549
545
  noRouteFoundJson(message: object): {
550
546
  code: string;
551
547
  message: object;
@@ -564,11 +560,15 @@ declare const remoteRouters: readonly [{
564
560
  duration: number;
565
561
  name?: string | undefined;
566
562
  maneuver: {
563
+ /**
564
+ * Singleton
565
+ */
567
566
  bearing_before: number;
568
567
  bearing_after: number;
569
568
  location: import('geojson').Position;
570
- modifier: "sharp right" | "sharp left" | "slight right" | "slight left" | "right" | "left" | "u turn" | "straight";
571
- type: "depart" | "turn" | "arrive";
569
+ modifier: "straight" | "right" | "left" | "sharp right" | "sharp left" | "slight right" | "slight left" | "u turn";
570
+ type: "depart" | "turn" | "roundabout" | "arrive" | "exit roundabout";
571
+ exit?: number | undefined;
572
572
  };
573
573
  }[];
574
574
  }[];
@@ -593,11 +593,15 @@ declare const remoteRouters: readonly [{
593
593
  duration: number;
594
594
  name?: string | undefined;
595
595
  maneuver: {
596
+ /**
597
+ * Singleton
598
+ */
596
599
  bearing_before: number;
597
600
  bearing_after: number;
598
601
  location: import('geojson').Position;
599
- modifier: "sharp right" | "sharp left" | "slight right" | "slight left" | "right" | "left" | "u turn" | "straight";
600
- type: "depart" | "turn" | "arrive";
602
+ modifier: "straight" | "right" | "left" | "sharp right" | "sharp left" | "slight right" | "slight left" | "u turn";
603
+ type: "depart" | "turn" | "roundabout" | "arrive" | "exit roundabout";
604
+ exit?: number | undefined;
601
605
  };
602
606
  }[];
603
607
  }[];
@@ -705,6 +709,11 @@ declare const remoteRouters: readonly [{
705
709
  }[];
706
710
  };
707
711
  }): import('../model/Itinerary.js').default[];
712
+ }, {
713
+ readonly rname: "tictactrip";
714
+ getItineraries(endpointUrl: string, routerRequest: RouterRequest): Promise<import('../model/Itinerary.js').default[]>;
715
+ getBodyParams(routerRequest: RouterRequest): import('./tictactrip/type.js').TictactripRequest;
716
+ parseResponse(json: import('./tictactrip/type.js').TictactripResponse): import('../model/Itinerary.js').default[];
708
717
  }, {
709
718
  readonly rname: "wemap-multi";
710
719
  getItineraries(endpointUrl: string, routerRequest: Omit<RouterRequest, "origin" | "destination" | "waypoints"> & {
@@ -4,9 +4,10 @@ import { default as Itinerary } from '../../model/Itinerary.js';
4
4
  import { default as RemoteRouter } from '../RemoteRouter.js';
5
5
  import { TravelMode } from '../../model/TravelMode.js';
6
6
  import { RouterRequest } from '../../model/RouterRequest.js';
7
+ import { HorizontalDirection, HorizontalStepType } from '../../model/Step.js';
7
8
  type OsrmCoordinates = Position;
8
9
  type OsrmModifier = 'sharp right' | 'sharp left' | 'slight right' | 'slight left' | 'right' | 'left' | 'u turn' | 'straight';
9
- type OsrmManeuverType = 'depart' | 'turn' | 'arrive';
10
+ type OsrmManeuverType = 'depart' | 'turn' | 'roundabout' | 'exit roundabout' | 'arrive';
10
11
  type OsrmStep = {
11
12
  geometry: LineString;
12
13
  distance: number;
@@ -18,6 +19,7 @@ type OsrmStep = {
18
19
  location: OsrmCoordinates;
19
20
  modifier: OsrmModifier;
20
21
  type: OsrmManeuverType;
22
+ exit?: number;
21
23
  };
22
24
  };
23
25
  type OsrmJson = {
@@ -49,6 +51,8 @@ declare class OsrmRemoteRouter extends RemoteRouter {
49
51
  */
50
52
  getURL(endpointUrl: string, routerRequest: RouterRequest): string;
51
53
  inputModeCorrespondance: (routerRequest: RouterRequest) => OsrmMode;
54
+ osrmTypeToStepType(type: OsrmManeuverType): HorizontalStepType;
55
+ osrmModifierToStepDirection(modifier: OsrmModifier): HorizontalDirection;
52
56
  coordinatesToJson({ lat, lng, level }: Coordinates): OsrmCoordinates;
53
57
  /**
54
58
  * @param {object} json
@@ -0,0 +1,18 @@
1
+ import { default as Itinerary } from '../../model/Itinerary.js';
2
+ import { default as RemoteRouter } from '../RemoteRouter.js';
3
+ import { RouterRequest } from '../../model/RouterRequest.js';
4
+ import { TictactripResponse, TictactripRequest } from './type.js';
5
+ /**
6
+ * Singleton.
7
+ */
8
+ declare class TictactripRemoteRouter extends RemoteRouter {
9
+ /**
10
+ * @override
11
+ */
12
+ get rname(): "tictactrip";
13
+ getItineraries(endpointUrl: string, routerRequest: RouterRequest): Promise<Itinerary[]>;
14
+ getBodyParams(routerRequest: RouterRequest): TictactripRequest;
15
+ parseResponse(json: TictactripResponse): Itinerary[];
16
+ }
17
+ declare const _default: TictactripRemoteRouter;
18
+ export default _default;
@@ -0,0 +1,73 @@
1
+ export type TictactripRequest = {
2
+ origin: {
3
+ latitude: number;
4
+ longitude: number;
5
+ };
6
+ destination: {
7
+ latitude: number;
8
+ longitude: number;
9
+ };
10
+ outbound_date: string;
11
+ passengers: {
12
+ age: number;
13
+ }[];
14
+ };
15
+ export interface TictactripProvider {
16
+ id: string;
17
+ name: string;
18
+ company: string;
19
+ transportType: string;
20
+ }
21
+ export interface TictactripLocation {
22
+ id: string;
23
+ name: string;
24
+ city: string;
25
+ region: string;
26
+ country: string;
27
+ address: string;
28
+ latitude: number;
29
+ longitude: number;
30
+ }
31
+ export interface TictactripSegment {
32
+ id: string;
33
+ provider: TictactripProvider;
34
+ origin: TictactripLocation;
35
+ destination: TictactripLocation;
36
+ priceCents: number;
37
+ durationMinutes: number;
38
+ departureUTC: number;
39
+ arrivalUTC: number;
40
+ originOffset: string;
41
+ destinationOffset: string;
42
+ arrivalLocalISO: string;
43
+ departureLocalISO: string;
44
+ transportType: 'bus' | 'train';
45
+ vehicleIdentifier: string;
46
+ co2g: number;
47
+ bookingClass: string;
48
+ fareName: string;
49
+ notAvailableReason: string | null;
50
+ includedBaggage: boolean;
51
+ }
52
+ export interface TictactripTrip {
53
+ id: string;
54
+ direction: string;
55
+ origin: TictactripLocation;
56
+ destination: TictactripLocation;
57
+ available: boolean;
58
+ priceCents: number;
59
+ durationMinutes: number;
60
+ departureUTC: number;
61
+ arrivalUTC: number;
62
+ originOffset: string;
63
+ isIdentityDocumentRequired: boolean;
64
+ arrivalLocalISO: string;
65
+ departureLocalISO: string;
66
+ destinationOffset: string;
67
+ transportType: 'TRAIN' | 'BUS' | 'MULTIMODAL';
68
+ providers: TictactripProvider[];
69
+ segments: TictactripSegment[];
70
+ }
71
+ export type TictactripResponse = {
72
+ trips: Record<string, TictactripTrip>;
73
+ };
@@ -1,6 +1,6 @@
1
1
  import { Coordinates } from '@wemap/geo';
2
2
  import { diffAngle, rad2deg, roundFactor } from '@wemap/maths';
3
- import { ItineraryInfoManager, Step } from '@wemap/routers';
3
+ import { ItineraryInfoManager, Step, isStepLevelChange } from '@wemap/routers';
4
4
 
5
5
  export default class InstructionManager {
6
6
 
@@ -30,9 +30,9 @@ export default class InstructionManager {
30
30
 
31
31
  let type, direction, directionExtra, levelChange;
32
32
 
33
- if (step.levelChange) {
33
+ if (isStepLevelChange(step)) {
34
34
  type = 'level-change';
35
- levelChange = step.levelChange;
35
+ levelChange = step.levelDifference;
36
36
  } else {
37
37
  type = 'turn';
38
38
  const turnInfo = InstructionManager.getTurnInfoFromAngle(step.angle);
@@ -65,52 +65,53 @@ export default class InstructionManager {
65
65
  }
66
66
 
67
67
  let suffix = '';
68
- if (step.extras?.isGate) {
68
+ if (step.type === 'gate') {
69
69
  suffix = ` on gate ${step.name}`;
70
70
  } else if (step.name) {
71
71
  suffix = ` on ${step.name}`;
72
72
  }
73
73
 
74
- if (step.levelChange) {
75
- if (step.levelChange.direction === 'up') {
76
- if (step.levelChange.type === 'stairs') {
74
+ if (isStepLevelChange(step)) {
75
+ if (step.direction === 'up') {
76
+ if (step.type === 'stairs') {
77
77
  return 'Go up the stairs';
78
78
  }
79
- if (step.levelChange.type === 'escalator') {
79
+ if (step.type === 'escalator') {
80
80
  return 'Go up the escalator';
81
81
  }
82
- if (step.levelChange.type === 'elevator') {
82
+ if (step.type === 'elevator') {
83
83
  return 'Go up the elevator';
84
84
  }
85
- if (step.levelChange.type === 'moving walkway') {
85
+ if (step.type === 'moving-walkway') {
86
86
  return 'Go up the moving walkway';
87
87
  }
88
- if (step.levelChange.type === 'incline plane') {
88
+ if (step.type === 'incline-plane') {
89
89
  return 'Go up the incline plane';
90
90
  }
91
91
  return 'Go up' + suffix;
92
92
  }
93
- if (step.levelChange.direction === 'down') {
94
- if (step.levelChange.type === 'stairs') {
93
+ if (step.direction === 'down') {
94
+ if (step.type === 'stairs') {
95
95
  return 'Go down the stairs';
96
96
  }
97
- if (step.levelChange.type === 'escalator') {
97
+ if (step.type === 'escalator') {
98
98
  return 'Go down the escalator';
99
99
  }
100
- if (step.levelChange.type === 'elevator') {
100
+ if (step.type === 'elevator') {
101
101
  return 'Go down the elevator';
102
102
  }
103
- if (step.levelChange.type === 'moving walkway') {
103
+ if (step.type === 'moving-walkway') {
104
104
  return 'Go down the moving walkway';
105
105
  }
106
- if (step.levelChange.type === 'incline plane') {
106
+ if (step.type === 'incline-plane') {
107
107
  return 'Go down the incline plane';
108
108
  }
109
109
  return 'Go down' + suffix;
110
110
  }
111
- if (step.extras?.subwayEntrance) {
112
- return `Take exit ${step.extras.subwayEntranceRef}`;
113
- }
111
+ }
112
+
113
+ if (step.type === 'subway-entrance') {
114
+ return `Take exit ${step.name}`;
114
115
  }
115
116
 
116
117
  if (isTurn) {
@@ -160,16 +161,16 @@ export default class InstructionManager {
160
161
 
161
162
  let instruction = InstructionManager.getInstructionFromStep(nextStep);
162
163
 
163
- const stepWithImportantInfo = itineraryInfoManager._steps.find(step => step.levelChange
164
+ const stepWithImportantInfo = itineraryInfoManager._steps.find(step => isStepLevelChange(step)
164
165
  && step.number > nextStep.number
165
166
  && step.coords.distanceTo(nextStep.coords) < 10
166
167
  ) || null;
167
168
 
168
- if (stepWithImportantInfo && stepWithImportantInfo.levelChange) {
169
+ if (stepWithImportantInfo && isStepLevelChange(stepWithImportantInfo)) {
169
170
  const nextBearing = nextStep.coords.bearingTo(stepWithImportantInfo.coords);
170
171
  const { direction } = InstructionManager.getTurnInfoFromAngle(nextBearing - nextStep.previousBearing);
171
172
  instruction = direction === 'straight' ? 'Continue straight' : `Turn ${direction}`;
172
- const { direction: levelDirection, type: levelType } = stepWithImportantInfo.levelChange;
173
+ const { direction: levelDirection, type: levelType } = stepWithImportantInfo;
173
174
  instruction += ` and take the ${levelType} going ${levelDirection}`;
174
175
  }
175
176
 
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/routers"
13
13
  },
14
14
  "name": "@wemap/routers",
15
- "version": "12.12.4",
15
+ "version": "13.1.0",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -34,10 +34,10 @@
34
34
  "@turf/convex": "^6.5.0",
35
35
  "@turf/helpers": "^6.5.0",
36
36
  "@types/mapbox__polyline": "^1.0.2",
37
- "@wemap/geo": "^12.12.0",
38
- "@wemap/logger": "^12.10.9",
39
- "@wemap/maths": "^12.10.9",
40
- "@wemap/osm": "^12.12.3",
37
+ "@wemap/geo": "^13.1.0",
38
+ "@wemap/logger": "^13.0.0",
39
+ "@wemap/maths": "^13.0.0",
40
+ "@wemap/osm": "^13.1.0",
41
41
  "@wemap/salesman.js": "^2.1.0"
42
42
  },
43
43
  "devDependencies": {
@@ -62,5 +62,5 @@
62
62
  "types": "./dist/helpers/*.d.ts"
63
63
  }
64
64
  },
65
- "gitHead": "150f561ed17ba6ac7050d846b45dbd4a056f82ec"
65
+ "gitHead": "4e46ef122f3139bc2e16c0368b53e0a8ea52db72"
66
66
  }
@@ -1,7 +0,0 @@
1
- export type LevelChangeType = 'elevator' | 'escalator' | 'stairs' | 'moving walkway' | 'incline plane';
2
- export type LevelChange = {
3
- direction: 'up' | 'down';
4
- difference: number;
5
- type?: LevelChangeType;
6
- };
7
- export declare function areLevelChangeEquals(l1: LevelChange, l2: LevelChange): boolean;