1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Google Map package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\GoogleMap\Service\Directions; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Base\Coordinate; |
15
|
|
|
use Ivory\GoogleMap\Service\Base\Distance; |
16
|
|
|
use Ivory\GoogleMap\Service\Base\Duration; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsLeg |
20
|
|
|
* |
21
|
|
|
* @author GeLo <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class DirectionsLeg |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var Distance|null |
27
|
|
|
*/ |
28
|
|
|
private $distance; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Duration|null |
32
|
|
|
*/ |
33
|
|
|
private $duration; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Duration|null |
37
|
|
|
*/ |
38
|
|
|
private $durationInTraffic; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string|null |
42
|
|
|
*/ |
43
|
|
|
private $endAddress; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var Coordinate|null |
47
|
|
|
*/ |
48
|
|
|
private $endLocation; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string|null |
52
|
|
|
*/ |
53
|
|
|
private $startAddress; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var Coordinate|null |
57
|
|
|
*/ |
58
|
|
|
private $startLocation; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var DirectionsStep[] |
62
|
|
|
*/ |
63
|
|
|
private $steps = []; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var mixed[] |
67
|
|
|
*/ |
68
|
|
|
private $viaWaypoints = []; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
|
public function hasDistance() |
74
|
|
|
{ |
75
|
|
|
return $this->distance !== null; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return Distance|null |
80
|
|
|
*/ |
81
|
|
|
public function getDistance() |
82
|
|
|
{ |
83
|
|
|
return $this->distance; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param Distance|null $distance |
88
|
|
|
*/ |
89
|
|
|
public function setDistance(Distance $distance = null) |
90
|
|
|
{ |
91
|
|
|
$this->distance = $distance; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
|
|
public function hasDuration() |
98
|
|
|
{ |
99
|
|
|
return $this->duration !== null; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return Duration|null |
104
|
|
|
*/ |
105
|
|
|
public function getDuration() |
106
|
|
|
{ |
107
|
|
|
return $this->duration; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param Duration|null $duration |
112
|
|
|
*/ |
113
|
|
|
public function setDuration(Duration $duration = null) |
114
|
|
|
{ |
115
|
|
|
$this->duration = $duration; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
|
|
public function hasDurationInTraffic() |
122
|
|
|
{ |
123
|
|
|
return $this->durationInTraffic !== null; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return Duration|null |
128
|
|
|
*/ |
129
|
|
|
public function getDurationInTraffic() |
130
|
|
|
{ |
131
|
|
|
return $this->durationInTraffic; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param Duration|null $durationInTraffic |
136
|
|
|
*/ |
137
|
|
|
public function setDurationInTraffic(Duration $durationInTraffic = null) |
138
|
|
|
{ |
139
|
|
|
$this->durationInTraffic = $durationInTraffic; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return bool |
144
|
|
|
*/ |
145
|
|
|
public function hasEndAddress() |
146
|
|
|
{ |
147
|
|
|
return $this->endAddress !== null; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string|null |
152
|
|
|
*/ |
153
|
|
|
public function getEndAddress() |
154
|
|
|
{ |
155
|
|
|
return $this->endAddress; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string|null $endAddress |
160
|
|
|
*/ |
161
|
|
|
public function setEndAddress($endAddress = null) |
162
|
|
|
{ |
163
|
|
|
$this->endAddress = $endAddress; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return bool |
168
|
|
|
*/ |
169
|
|
|
public function hasEndLocation() |
170
|
|
|
{ |
171
|
|
|
return $this->endLocation !== null; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return Coordinate|null |
176
|
|
|
*/ |
177
|
|
|
public function getEndLocation() |
178
|
|
|
{ |
179
|
|
|
return $this->endLocation; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param Coordinate|null $endLocation |
184
|
|
|
*/ |
185
|
|
|
public function setEndLocation(Coordinate $endLocation = null) |
186
|
|
|
{ |
187
|
|
|
$this->endLocation = $endLocation; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return bool |
192
|
|
|
*/ |
193
|
|
|
public function hasStartAddress() |
194
|
|
|
{ |
195
|
|
|
return $this->startAddress !== null; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return string|null |
200
|
|
|
*/ |
201
|
|
|
public function getStartAddress() |
202
|
|
|
{ |
203
|
|
|
return $this->startAddress; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param string|null $startAddress |
208
|
|
|
*/ |
209
|
|
|
public function setStartAddress($startAddress = null) |
210
|
|
|
{ |
211
|
|
|
$this->startAddress = $startAddress; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return bool |
216
|
|
|
*/ |
217
|
|
|
public function hasStartLocation() |
218
|
|
|
{ |
219
|
|
|
return $this->startLocation !== null; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return Coordinate|null |
224
|
|
|
*/ |
225
|
|
|
public function getStartLocation() |
226
|
|
|
{ |
227
|
|
|
return $this->startLocation; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param Coordinate|null $startLocation |
232
|
|
|
*/ |
233
|
|
|
public function setStartLocation(Coordinate $startLocation = null) |
234
|
|
|
{ |
235
|
|
|
$this->startLocation = $startLocation; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @return bool |
240
|
|
|
*/ |
241
|
|
|
public function hasSteps() |
242
|
|
|
{ |
243
|
|
|
return !empty($this->steps); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @return DirectionsStep[] |
248
|
|
|
*/ |
249
|
|
|
public function getSteps() |
250
|
|
|
{ |
251
|
|
|
return $this->steps; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @param DirectionsStep[] $steps |
256
|
|
|
*/ |
257
|
|
|
public function setSteps(array $steps) |
258
|
|
|
{ |
259
|
|
|
$this->steps = []; |
260
|
|
|
$this->addSteps($steps); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @param DirectionsStep[] $steps |
265
|
|
|
*/ |
266
|
|
|
public function addSteps(array $steps) |
267
|
|
|
{ |
268
|
|
|
foreach ($steps as $step) { |
269
|
|
|
$this->addStep($step); |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @param DirectionsStep $step |
275
|
|
|
* |
276
|
|
|
* @return bool |
277
|
|
|
*/ |
278
|
|
|
public function hasStep(DirectionsStep $step) |
279
|
|
|
{ |
280
|
|
|
return in_array($step, $this->steps, true); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @param DirectionsStep $step |
285
|
|
|
*/ |
286
|
|
|
public function addStep(DirectionsStep $step) |
287
|
|
|
{ |
288
|
|
|
if (!$this->hasStep($step)) { |
289
|
|
|
$this->steps[] = $step; |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @param DirectionsStep $step |
295
|
|
|
*/ |
296
|
|
|
public function removeStep(DirectionsStep $step) |
297
|
|
|
{ |
298
|
|
|
unset($this->steps[array_search($step, $this->steps, true)]); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @return bool |
303
|
|
|
*/ |
304
|
|
|
public function hasViaWaypoints() |
305
|
|
|
{ |
306
|
|
|
return !empty($this->viaWaypoints); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @return mixed[] |
311
|
|
|
*/ |
312
|
|
|
public function getViaWaypoints() |
313
|
|
|
{ |
314
|
|
|
return $this->viaWaypoints; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* @param mixed[] $viaWaypoints |
319
|
|
|
*/ |
320
|
|
|
public function setViaWaypoints(array $viaWaypoints) |
321
|
|
|
{ |
322
|
|
|
$this->viaWaypoints = $viaWaypoints; |
323
|
|
|
} |
324
|
|
|
} |
325
|
|
|
|