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\Elevation\Request; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Service\Base\Location\LocationInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author GeLo <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class PathElevationRequest implements ElevationRequestInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var LocationInterface[] |
23
|
|
|
*/ |
24
|
|
|
private $paths = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var int |
28
|
|
|
*/ |
29
|
|
|
private $samples; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param LocationInterface[] $paths |
33
|
|
|
* @param int $samples |
34
|
|
|
*/ |
35
|
|
|
public function __construct(array $paths, $samples = 3) |
36
|
|
|
{ |
37
|
|
|
$this->setPaths($paths); |
38
|
|
|
$this->setSamples($samples); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
|
|
public function hasPaths() |
45
|
|
|
{ |
46
|
|
|
return !empty($this->paths); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return LocationInterface[] |
51
|
|
|
*/ |
52
|
|
|
public function getPaths() |
53
|
|
|
{ |
54
|
|
|
return $this->paths; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param LocationInterface[] $paths |
59
|
|
|
*/ |
60
|
|
|
public function setPaths(array $paths) |
61
|
|
|
{ |
62
|
|
|
$this->paths = []; |
63
|
|
|
$this->addPaths($paths); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param LocationInterface[] $paths |
68
|
|
|
*/ |
69
|
|
|
public function addPaths(array $paths) |
70
|
|
|
{ |
71
|
|
|
foreach ($paths as $path) { |
72
|
|
|
$this->addPath($path); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param LocationInterface $path |
78
|
|
|
* |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
|
|
public function hasPath(LocationInterface $path) |
82
|
|
|
{ |
83
|
|
|
return in_array($path, $this->paths, true); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param LocationInterface $path |
88
|
|
|
*/ |
89
|
|
|
public function addPath(LocationInterface $path) |
90
|
|
|
{ |
91
|
|
|
if (!$this->hasPath($path)) { |
92
|
|
|
$this->paths[] = $path; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param LocationInterface $path |
98
|
|
|
*/ |
99
|
|
|
public function removePath(LocationInterface $path) |
100
|
|
|
{ |
101
|
|
|
unset($this->paths[array_search($path, $this->paths, true)]); |
102
|
|
|
$this->paths = array_values($this->paths); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return int |
107
|
|
|
*/ |
108
|
|
|
public function getSamples() |
109
|
|
|
{ |
110
|
|
|
return $this->samples; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param int $samples |
115
|
|
|
*/ |
116
|
|
|
public function setSamples($samples) |
117
|
|
|
{ |
118
|
|
|
$this->samples = $samples; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* {@inheritdoc} |
123
|
|
|
*/ |
124
|
|
|
public function build() |
125
|
|
|
{ |
126
|
|
|
return [ |
127
|
|
|
'path' => implode('|', array_map(function (LocationInterface $path) { |
128
|
|
|
return $path->build(); |
129
|
|
|
}, $this->paths)), |
130
|
|
|
'samples' => $this->samples, |
131
|
|
|
]; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|