|
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
|
|
|
* |
|
12
|
|
|
* @licence GNU GPL v2+ |
|
13
|
|
|
* @author Kim Eik < [email protected] > |
|
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
15
|
|
|
*/ |
|
16
|
|
|
class Circle extends \MapsBaseFillableElement { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var LatLongValue |
|
20
|
|
|
*/ |
|
21
|
|
|
private $circleCentre; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var integer|float |
|
25
|
|
|
*/ |
|
26
|
|
|
private $circleRadius; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param LatLongValue $circleCentre |
|
30
|
|
|
* @param integer|float $circleRadius |
|
31
|
|
|
* |
|
32
|
|
|
* @throws InvalidArgumentException |
|
33
|
|
|
*/ |
|
34
|
7 |
|
public function __construct( LatLongValue $circleCentre, $circleRadius ) { |
|
35
|
7 |
|
if ( !is_float( $circleRadius ) && !is_int( $circleRadius ) ) { |
|
36
|
1 |
|
throw new InvalidArgumentException( '$circleRadius must be a float or int' ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
6 |
|
if ( $circleRadius <= 0 ) { |
|
40
|
2 |
|
throw new InvalidArgumentException( '$circleRadius must be greater than zero' ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
4 |
|
parent::__construct(); |
|
44
|
|
|
|
|
45
|
4 |
|
$this->setCircleCentre( $circleCentre ); |
|
46
|
4 |
|
$this->setCircleRadius( $circleRadius ); |
|
47
|
4 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getJSONObject( string $defText = '', string $defTitle = '' ): array { |
|
50
|
|
|
$parentArray = parent::getJSONObject( $defText, $defTitle ); |
|
51
|
|
|
|
|
52
|
|
|
$array = [ |
|
53
|
|
|
'centre' => [ |
|
54
|
|
|
'lon' => $this->getCircleCentre()->getLongitude(), |
|
55
|
|
|
'lat' => $this->getCircleCentre()->getLatitude() |
|
56
|
|
|
], |
|
57
|
|
|
'radius' => intval( $this->getCircleRadius() ), |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
return array_merge( $parentArray, $array ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
4 |
|
public function getCircleCentre(): LatLongValue { |
|
64
|
4 |
|
return $this->circleCentre; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
4 |
|
public function setCircleCentre( LatLongValue $circleCentre ) { |
|
68
|
4 |
|
$this->circleCentre = $circleCentre; |
|
69
|
4 |
|
} |
|
70
|
|
|
|
|
71
|
4 |
|
public function getCircleRadius(): float { |
|
72
|
4 |
|
return $this->circleRadius; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
4 |
|
public function setCircleRadius( float $circleRadius ) { |
|
76
|
4 |
|
$this->circleRadius = $circleRadius; |
|
77
|
4 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|