1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maps\Elements; |
4
|
|
|
|
5
|
|
|
use DataValues\Geo\Values\LatLongValue; |
6
|
|
|
use InvalidArgumentException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @since 3.0 |
10
|
|
|
* |
11
|
|
|
* @licence GNU GPL v2+ |
12
|
|
|
* @author Kim Eik < [email protected] > |
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
14
|
|
|
*/ |
15
|
|
|
class Circle extends \Maps\Elements\BaseFillableElement { |
16
|
|
|
|
17
|
|
|
private $circleCentre; |
18
|
|
|
private $circleRadius; |
19
|
|
|
|
20
|
7 |
|
public function __construct( LatLongValue $circleCentre, float $circleRadius ) { |
21
|
7 |
|
if ( !is_float( $circleRadius ) && !is_int( $circleRadius ) ) { |
22
|
|
|
throw new InvalidArgumentException( '$circleRadius must be a float or int' ); |
23
|
|
|
} |
24
|
|
|
|
25
|
7 |
|
if ( $circleRadius <= 0 ) { |
26
|
2 |
|
throw new InvalidArgumentException( '$circleRadius must be greater than zero' ); |
27
|
|
|
} |
28
|
|
|
|
29
|
5 |
|
$this->setCircleCentre( $circleCentre ); |
30
|
5 |
|
$this->setCircleRadius( $circleRadius ); |
31
|
5 |
|
} |
32
|
|
|
|
33
|
1 |
|
public function getJSONObject( string $defText = '', string $defTitle = '' ): array { |
34
|
1 |
|
return array_merge( |
35
|
1 |
|
parent::getJSONObject( $defText, $defTitle ), |
36
|
|
|
[ |
37
|
|
|
'centre' => [ |
38
|
1 |
|
'lon' => $this->getCircleCentre()->getLongitude(), |
39
|
1 |
|
'lat' => $this->getCircleCentre()->getLatitude() |
40
|
|
|
], |
41
|
1 |
|
'radius' => intval( $this->getCircleRadius() ), |
42
|
|
|
] |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
5 |
|
public function getCircleCentre(): LatLongValue { |
47
|
5 |
|
return $this->circleCentre; |
48
|
|
|
} |
49
|
|
|
|
50
|
5 |
|
public function setCircleCentre( LatLongValue $circleCentre ) { |
51
|
5 |
|
$this->circleCentre = $circleCentre; |
52
|
5 |
|
} |
53
|
|
|
|
54
|
5 |
|
public function getCircleRadius(): float { |
55
|
5 |
|
return $this->circleRadius; |
56
|
|
|
} |
57
|
|
|
|
58
|
5 |
|
public function setCircleRadius( float $circleRadius ) { |
59
|
5 |
|
$this->circleRadius = $circleRadius; |
60
|
5 |
|
} |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|