1
|
|
|
<?php namespace Arcanedev\GeoLocation\Google\Directions\Entities; |
2
|
|
|
use Arcanedev\GeoLocation\Entities\Position; |
3
|
|
|
use Arcanedev\GeoLocation\Entities\Viewport; |
4
|
|
|
use Illuminate\Support\Arr; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Route |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\GeoLocation\Google\Directions\Entities |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class Route |
13
|
|
|
{ |
14
|
|
|
/* ----------------------------------------------------------------- |
15
|
|
|
| Properties |
16
|
|
|
| ----------------------------------------------------------------- |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The route summary. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $summary; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \Arcanedev\GeoLocation\Google\Directions\Entities\LegCollection |
28
|
|
|
*/ |
29
|
|
|
protected $legs; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
protected $copyrights; |
33
|
|
|
|
34
|
|
|
/** @var \Arcanedev\GeoLocation\Entities\Viewport */ |
35
|
|
|
protected $bounds; |
36
|
|
|
|
37
|
|
|
/* ----------------------------------------------------------------- |
38
|
|
|
| Constructor |
39
|
|
|
| ----------------------------------------------------------------- |
40
|
|
|
*/ |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Route constructor. |
44
|
|
|
* |
45
|
|
|
* @param array $data |
46
|
|
|
*/ |
47
|
|
|
public function __construct(array $data) |
48
|
|
|
{ |
49
|
|
|
$this->summary = Arr::get($data, 'summary', ''); |
50
|
|
|
$this->legs = LegCollection::load(Arr::get($data, 'legs', [])); |
51
|
|
|
$this->copyrights = Arr::get($data, 'copyrights'); |
52
|
|
|
$this->setBounds(Arr::get($data, 'bounds', [])); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/* ----------------------------------------------------------------- |
56
|
|
|
| Getters & Setters |
57
|
|
|
| ----------------------------------------------------------------- |
58
|
|
|
*/ |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get the route summary. |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function summary() |
66
|
|
|
{ |
67
|
|
|
return $this->summary; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param array $bounds |
72
|
|
|
* |
73
|
|
|
* @return self |
74
|
|
|
*/ |
75
|
|
|
private function setBounds(array $bounds) |
76
|
|
|
{ |
77
|
|
|
$this->bounds = Viewport::create( |
78
|
|
|
Position::create(Arr::get($bounds, 'northeast.lat'), Arr::get($bounds, 'northeast.lng')), |
79
|
|
|
Position::create(Arr::get($bounds, 'southwest.lat'), Arr::get($bounds, 'southwest.lng')) |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the leg collection. |
87
|
|
|
* |
88
|
|
|
* @return \Arcanedev\GeoLocation\Google\Directions\Entities\LegCollection |
89
|
|
|
*/ |
90
|
|
|
public function legs() |
91
|
|
|
{ |
92
|
|
|
return $this->legs; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Get the copyrights. |
97
|
|
|
* |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function copyrights() |
101
|
|
|
{ |
102
|
|
|
return $this->copyrights; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get the bounds. |
107
|
|
|
* |
108
|
|
|
* @return \Arcanedev\GeoLocation\Entities\Viewport |
109
|
|
|
*/ |
110
|
|
|
public function bounds() |
111
|
|
|
{ |
112
|
|
|
return $this->bounds; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|