@@ 23-106 (lines=84) @@ | ||
20 | /** |
|
21 | * @author GeLo <[email protected]> |
|
22 | */ |
|
23 | class HeatmapLayer implements ExtendableInterface, OptionsAwareInterface |
|
24 | { |
|
25 | use OptionsAwareTrait; |
|
26 | use VariableAwareTrait; |
|
27 | ||
28 | /** |
|
29 | * @var Coordinate[] |
|
30 | */ |
|
31 | private $coordinates = []; |
|
32 | ||
33 | /** |
|
34 | * @param Coordinate[] $coordinates |
|
35 | * @param mixed[] $options |
|
36 | */ |
|
37 | public function __construct(array $coordinates = [], array $options = []) |
|
38 | { |
|
39 | $this->setCoordinates($coordinates); |
|
40 | $this->setOptions($options); |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * @return bool |
|
45 | */ |
|
46 | public function hasCoordinates() |
|
47 | { |
|
48 | return !empty($this->coordinates); |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * @return Coordinate[] |
|
53 | */ |
|
54 | public function getCoordinates() |
|
55 | { |
|
56 | return $this->coordinates; |
|
57 | } |
|
58 | ||
59 | /** |
|
60 | * @param Coordinate[] $coordinates |
|
61 | */ |
|
62 | public function setCoordinates(array $coordinates) |
|
63 | { |
|
64 | $this->coordinates = []; |
|
65 | $this->addCoordinates($coordinates); |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * @param Coordinate[] $coordinates |
|
70 | */ |
|
71 | public function addCoordinates(array $coordinates) |
|
72 | { |
|
73 | foreach ($coordinates as $coordinate) { |
|
74 | $this->addCoordinate($coordinate); |
|
75 | } |
|
76 | } |
|
77 | ||
78 | /** |
|
79 | * @param Coordinate $coordinate |
|
80 | * |
|
81 | * @return bool |
|
82 | */ |
|
83 | public function hasCoordinate(Coordinate $coordinate) |
|
84 | { |
|
85 | return in_array($coordinate, $this->coordinates, true); |
|
86 | } |
|
87 | ||
88 | /** |
|
89 | * @param Coordinate $coordinate |
|
90 | */ |
|
91 | public function addCoordinate(Coordinate $coordinate) |
|
92 | { |
|
93 | if (!$this->hasCoordinate($coordinate)) { |
|
94 | $this->coordinates[] = $coordinate; |
|
95 | } |
|
96 | } |
|
97 | ||
98 | /** |
|
99 | * @param Coordinate $coordinate |
|
100 | */ |
|
101 | public function removeCoordinate(Coordinate $coordinate) |
|
102 | { |
|
103 | unset($this->coordinates[array_search($coordinate, $this->coordinates, true)]); |
|
104 | $this->coordinates = empty($this->coordinates) ? [] : array_values($this->coordinates); |
|
105 | } |
|
106 | } |
|
107 |
@@ 24-105 (lines=82) @@ | ||
21 | * |
|
22 | * @author GeLo <[email protected]> |
|
23 | */ |
|
24 | 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 | public function __construct(array $coordinates = [], array $options = []) |
|
39 | { |
|
40 | $this->addCoordinates($coordinates); |
|
41 | $this->addOptions($options); |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * @return bool |
|
46 | */ |
|
47 | public function hasCoordinates() |
|
48 | { |
|
49 | return !empty($this->coordinates); |
|
50 | } |
|
51 | ||
52 | /** |
|
53 | * @return Coordinate[] |
|
54 | */ |
|
55 | public function getCoordinates() |
|
56 | { |
|
57 | return $this->coordinates; |
|
58 | } |
|
59 | ||
60 | /** |
|
61 | * @param Coordinate[] $coordinates |
|
62 | */ |
|
63 | public function setCoordinates(array $coordinates) |
|
64 | { |
|
65 | $this->coordinates = []; |
|
66 | $this->addCoordinates($coordinates); |
|
67 | } |
|
68 | ||
69 | /** |
|
70 | * @param Coordinate[] $coordinates |
|
71 | */ |
|
72 | public function addCoordinates(array $coordinates) |
|
73 | { |
|
74 | foreach ($coordinates as $coordinate) { |
|
75 | $this->addCoordinate($coordinate); |
|
76 | } |
|
77 | } |
|
78 | ||
79 | /** |
|
80 | * @param Coordinate $coordinate |
|
81 | * |
|
82 | * @return bool |
|
83 | */ |
|
84 | public function hasCoordinate(Coordinate $coordinate) |
|
85 | { |
|
86 | return in_array($coordinate, $this->coordinates, true); |
|
87 | } |
|
88 | ||
89 | /** |
|
90 | * @param Coordinate $coordinate |
|
91 | */ |
|
92 | public function addCoordinate(Coordinate $coordinate) |
|
93 | { |
|
94 | $this->coordinates[] = $coordinate; |
|
95 | } |
|
96 | ||
97 | /** |
|
98 | * @param Coordinate $coordinate |
|
99 | */ |
|
100 | public function removeCoordinate(Coordinate $coordinate) |
|
101 | { |
|
102 | unset($this->coordinates[array_search($coordinate, $this->coordinates, true)]); |
|
103 | $this->coordinates = empty($this->coordinates) ? [] : array_values($this->coordinates); |
|
104 | } |
|
105 | } |
|
106 |