-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMPRouteLeg.ts
158 lines (151 loc) · 4.73 KB
/
MPRouteLeg.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { MPRouteStep, MPRouteProperty, MPRoutePropertyParams, MPRouteCoordinate, MPRouteCoordinateParams, MPRoute } from "../../index";
/**
* A leg of a {@link MPRoute} is defined as all steps between any context shifts (entering/exiting buildings, changing floors).
*
* A leg is comprised of a list of {@link steps} as well as a {@link startLocation} and an {@link endLocation}.
*
* @export
* @class MPRouteLeg
* @typedef {MPRouteLeg}
*/
export default class MPRouteLeg {
/**
* Creates an instance of MPRouteLeg.
*
* @constructor
* @private
* @param {?MPRouteStep[]} [steps] The steps the leg consists of.
* @param {?MPRouteProperty} [distance] The distance of the leg.
* @param {?MPRouteProperty} [duration] The expected time it takes to traverse the leg.
* @param {?string} [startAddress] The address at the start of the leg.
* @param {?string} [endAdress] The address at the end of the leg.
* @param {?MPRouteCoordinate} [startLocation] The start coordinate of the leg.
* @param {?MPRouteCoordinate} [endLocation] The end coordinate of the leg.
* @param {?string} [legStartReason] The reason for the start of the leg.
* @param {?string} [legEndReason] The reason for the end of the leg.
* @param {?number} [stopIndex] The index of the stop.
*/
private constructor(
public readonly steps?: MPRouteStep[],
public readonly distance?: MPRouteProperty,
public readonly duration?: MPRouteProperty,
public readonly startAddress?: string,
public readonly endAdress?: string,
public readonly startLocation?: MPRouteCoordinate,
public readonly endLocation?: MPRouteCoordinate,
public readonly legStartReason?: string,
public readonly legEndReason?: string,
public readonly stopIndex?: number,
) { }
/**
* Creator for MPRouteLeg, used to decode JSON from the MapsIndoors SDK.
*
* @public
* @static
* @param {MPRouteLegParams} object
* @returns {MPRouteLeg}
*/
public static create(object: MPRouteLegParams): MPRouteLeg {
return new MPRouteLeg(
object?.steps ? object?.steps.map((step: any) => MPRouteStep.create(step)) : undefined,
MPRouteProperty.create(object?.distance as MPRoutePropertyParams),
MPRouteProperty.create(object?.duration as MPRoutePropertyParams),
object?.start_address,
object?.end_address,
MPRouteCoordinate.create(object?.start_location as MPRouteCoordinateParams),
MPRouteCoordinate.create(object?.end_location as MPRouteCoordinateParams),
object?.leg_start_reason,
object?.leg_end_reason,
object?.stop_index,
);
}
/**
* Parses the object to a JSON object that is compatible with the MapsIndoors SDK.
*
* @public
* @returns {MPRouteLegParams}
*/
public toJSON(): MPRouteLegParams {
return {
start_address: this.startAddress,
end_address: this.endAdress,
start_location: this.startLocation,
end_location: this.endLocation,
steps: this.steps,
distance: this.distance,
duration: this.duration,
leg_start_reason: this.legStartReason,
leg_end_reason: this.legEndReason,
stop_index: this.stopIndex,
};
}
}
/**
* Parameter interface for {@link MPRouteLeg}.
*
* @export
* @interface MPRouteLegParams
* @typedef {MPRouteLegParams}
*/
export interface MPRouteLegParams {
/**
* The steps the leg consists of.
*
* @type {?MPRouteStep[]}
*/
steps?: MPRouteStep[];
/**
* The distance of the leg.
*
* @type {?MPRouteProperty}
*/
distance?: MPRouteProperty;
/**
* The expected time it takes to traverse the leg.
*
* @type {?MPRouteProperty}
*/
duration?: MPRouteProperty;
/**
* The address at the start of the leg.
*
* @type {?string}
*/
start_address?: string;
/**
* The address at the end of the leg.
*
* @type {?string}
*/
end_address?: string;
/**
* The start coordinate of the leg.
*
* @type {?MPRouteCoordinate}
*/
start_location?: MPRouteCoordinate;
/**
* The end coordinate of the leg.
*
* @type {?MPRouteCoordinate}
*/
end_location?: MPRouteCoordinate;
/**
* The reason for the start of the leg.
*
* @type {?string}
*/
leg_start_reason?: string;
/**
* The reason for the end of the leg.
*
* @type {?string}
*/
leg_end_reason?: string;
/**
* The index of the stop.
*
* @type {?number}
*/
stop_index?: number;
}