-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMPRouteStep.ts
177 lines (170 loc) · 4.83 KB
/
MPRouteStep.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import { Platform } from "react-native";
import { MPRouteProperty, MPRoutePropertyParams, MPRouteCoordinate, MPRouteCoordinateParams } from "../../index";
/**
* Description placeholder.
*
* @export
* @class MPRouteStep
* @typedef {MPRouteStep}
*/
export default class MPRouteStep {
/**
* Creates an instance of MPRouteStep.
*
* @constructor
* @private
* @param {?MPRouteProperty} [distance]
* @param {?MPRouteProperty} [duration]
* @param {?MPRouteStep[]} [steps]
* @param {?MPRouteCoordinate[]} [geometry]
* @param {?string} [highway]
* @param {?string} [abutters]
* @param {?string} [maneuver]
* @param {?MPRouteCoordinate} [startLocation]
* @param {?MPRouteCoordinate} [endLocation]
* @param {?string} [htmlInstructions]
* @param {?string} [travelMode]
* @param {?string[]} [availableTravelModes]
*/
private constructor(
public readonly distance?: MPRouteProperty,
public readonly duration?: MPRouteProperty,
public readonly steps?: MPRouteStep[],
public readonly geometry?: MPRouteCoordinate[],
public readonly highway?: string,
public readonly abutters?: string,
public readonly maneuver?: string,
public readonly startLocation?: MPRouteCoordinate,
public readonly endLocation?: MPRouteCoordinate,
public readonly htmlInstructions?: string,
public readonly travelMode?: string,
public readonly availableTravelModes?: string[],
) { }
/**
* Creator for MPRouteStep, used to decode JSON from the MapsIndoors SDK.
*
* @public
* @static
* @param {MPRouteStepParams} object
* @returns {MPRouteStep}
*/
public static create(object: MPRouteStepParams): MPRouteStep {
return new MPRouteStep(
MPRouteProperty.create(object?.distance as MPRoutePropertyParams),
MPRouteProperty.create(object?.duration as MPRoutePropertyParams),
object?.steps ? object?.steps.map((subStep: any) => MPRouteStep.create(subStep)): undefined,
object?.geometry ? object?.geometry.map((geo: any) => MPRouteCoordinate.create(geo)): undefined,
Platform.OS === "ios" ? (object as any).highway?.type: object?.highway,
object?.abutters,
object?.maneuver,
MPRouteCoordinate.create(object?.start_location as MPRouteCoordinateParams),
MPRouteCoordinate.create(object?.end_location as MPRouteCoordinateParams),
object?.html_instructions,
object?.travel_mode,
object?.available_travel_modes,
);
}
/**
* Parses the object to a JSON object that is compatible with the MapsIndoors SDK.
*
* @public
* @returns {MPRouteStepParams}
*/
public toJSON(): MPRouteStepParams {
return {
distance: this.distance,
duration: this.duration,
start_location: this.startLocation,
end_location: this.endLocation,
geometry: this.geometry,
highway: this.highway,
abutters: this.abutters,
html_instructions: this.htmlInstructions,
maneuver: this.maneuver,
travel_mode: this.travelMode,
steps: this.steps,
available_travel_modes: this.availableTravelModes,
};
}
}
/**
* Parameter interface for {@link MPRouteStep}.
*
* @export
* @interface MPRouteStepParams
* @typedef {MPRouteStepParams}
*/
export interface MPRouteStepParams {
/**
* Description placeholder.
*
* @type {?MPRouteProperty}
*/
distance?: MPRouteProperty,
/**
* Description placeholder.
*
* @type {?MPRouteProperty}
*/
duration?: MPRouteProperty,
/**
* Description placeholder.
*
* @type {?MPRouteStep[]}
*/
steps?: MPRouteStep[],
/**
* Description placeholder.
*
* @type {?MPRouteCoordinate[]}
*/
geometry?: MPRouteCoordinate[],
/**
* Description placeholder.
*
* @type {?string}
*/
highway?: string,
/**
* Description placeholder.
*
* @type {?string}
*/
abutters?: string,
/**
* Description placeholder.
*
* @type {?string}
*/
maneuver?: string,
/**
* Description placeholder.
*
* @type {?MPRouteCoordinate}
*/
start_location?: MPRouteCoordinate,
/**
* Description placeholder.
*
* @type {?MPRouteCoordinate}
*/
end_location?: MPRouteCoordinate,
/**
* Description placeholder.
*
* @type {?string}
*/
html_instructions?: string,
/**
* Description placeholder.
*
* @type {?string}
*/
travel_mode?: string,
/**
* Description placeholder.
*
* @type {?string[]}
*/
available_travel_modes?: string[],
}