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\Overlay; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Base\Coordinate; |
15
|
|
|
use Ivory\GoogleMap\Utility\OptionsAwareInterface; |
16
|
|
|
use Ivory\GoogleMap\Utility\OptionsAwareTrait; |
17
|
|
|
use Ivory\GoogleMap\Utility\VariableAwareTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Polygon |
21
|
|
|
* |
22
|
|
|
* @author GeLo <[email protected]> |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
class Polygon implements ExtendableInterface, OptionsAwareInterface |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
use OptionsAwareTrait; |
27
|
|
|
use VariableAwareTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Coordinate[] |
31
|
|
|
*/ |
32
|
|
|
private $coordinates = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param Coordinate[] $coordinates |
36
|
|
|
* @param mixed[] $options |
37
|
|
|
*/ |
38
|
48 |
|
public function __construct(array $coordinates = [], array $options = []) |
39
|
|
|
{ |
40
|
48 |
|
$this->addCoordinates($coordinates); |
41
|
48 |
|
$this->addOptions($options); |
42
|
48 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
24 |
|
public function hasCoordinates() |
48
|
|
|
{ |
49
|
24 |
|
return !empty($this->coordinates); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return Coordinate[] |
54
|
|
|
*/ |
55
|
40 |
|
public function getCoordinates() |
56
|
|
|
{ |
57
|
40 |
|
return $this->coordinates; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param Coordinate[] $coordinates |
62
|
|
|
*/ |
63
|
8 |
|
public function setCoordinates(array $coordinates) |
64
|
|
|
{ |
65
|
8 |
|
$this->coordinates = []; |
66
|
8 |
|
$this->addCoordinates($coordinates); |
67
|
8 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param Coordinate[] $coordinates |
71
|
|
|
*/ |
72
|
48 |
|
public function addCoordinates(array $coordinates) |
73
|
|
|
{ |
74
|
48 |
|
foreach ($coordinates as $coordinate) { |
75
|
28 |
|
$this->addCoordinate($coordinate); |
76
|
24 |
|
} |
77
|
48 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param Coordinate $coordinate |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
16 |
|
public function hasCoordinate(Coordinate $coordinate) |
85
|
|
|
{ |
86
|
16 |
|
return in_array($coordinate, $this->coordinates, true); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param Coordinate $coordinate |
91
|
|
|
*/ |
92
|
36 |
|
public function addCoordinate(Coordinate $coordinate) |
93
|
|
|
{ |
94
|
36 |
|
$this->coordinates[] = $coordinate; |
95
|
36 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param Coordinate $coordinate |
99
|
|
|
*/ |
100
|
4 |
|
public function removeCoordinate(Coordinate $coordinate) |
101
|
|
|
{ |
102
|
4 |
|
unset($this->coordinates[array_search($coordinate, $this->coordinates, true)]); |
103
|
4 |
|
$this->coordinates = empty($this->coordinates) ? [] : array_values($this->coordinates); |
104
|
4 |
|
} |
105
|
|
|
} |
106
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.