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