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
|
|
|
* |
14
|
|
|
* @licence GNU GPL v2+ |
15
|
|
|
* @author Kim Eik < [email protected] > |
16
|
|
|
* @author Jeroen De Dauw < [email protected] > |
17
|
|
|
*/ |
18
|
|
|
class Rectangle extends \Maps\LegacyModel\BaseFillableElement { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @since 3.0 |
22
|
|
|
* @var LatLongValue |
23
|
|
|
*/ |
24
|
|
|
protected $rectangleNorthEast; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @since 3.0 |
28
|
|
|
* @var LatLongValue |
29
|
|
|
*/ |
30
|
|
|
protected $rectangleSouthWest; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @since 3.0 |
34
|
|
|
* |
35
|
|
|
* @param LatLongValue $rectangleNorthEast |
36
|
|
|
* @param LatLongValue $rectangleSouthWest |
37
|
|
|
* |
38
|
|
|
* @throws InvalidArgumentException |
39
|
|
|
*/ |
40
|
|
|
public function __construct( LatLongValue $rectangleNorthEast, LatLongValue $rectangleSouthWest ) { |
41
|
|
|
if ( $rectangleNorthEast->equals( $rectangleSouthWest ) ) { |
42
|
|
|
throw new InvalidArgumentException( '$rectangleNorthEast cannot be equal to $rectangleSouthWest' ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// TODO: validate bounds are correct, if not, flip |
46
|
|
|
$this->setRectangleNorthEast( $rectangleNorthEast ); |
47
|
|
|
$this->setRectangleSouthWest( $rectangleSouthWest ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getJSONObject( string $defText = '', string $defTitle = '' ): array { |
51
|
|
|
$parentArray = parent::getJSONObject( $defText, $defTitle ); |
52
|
|
|
$array = [ |
53
|
|
|
'ne' => [ |
54
|
|
|
'lon' => $this->getRectangleNorthEast()->getLongitude(), |
55
|
|
|
'lat' => $this->getRectangleNorthEast()->getLatitude() |
56
|
|
|
], |
57
|
|
|
'sw' => [ |
58
|
|
|
'lon' => $this->getRectangleSouthWest()->getLongitude(), |
59
|
|
|
'lat' => $this->getRectangleSouthWest()->getLatitude() |
60
|
|
|
], |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
return array_merge( $parentArray, $array ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getRectangleNorthEast(): LatLongValue { |
67
|
|
|
return $this->rectangleNorthEast; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function setRectangleNorthEast( LatLongValue $rectangleNorthEast ) { |
71
|
|
|
$this->rectangleNorthEast = $rectangleNorthEast; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getRectangleSouthWest(): LatLongValue { |
75
|
|
|
return $this->rectangleSouthWest; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setRectangleSouthWest( LatLongValue $rectangleSouthWest ) { |
79
|
|
|
$this->rectangleSouthWest = $rectangleSouthWest; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|