|
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
|
7 |
|
public function __construct( LatLongValue $rectangleNorthEast, LatLongValue $rectangleSouthWest ) { |
|
41
|
7 |
|
if ( $rectangleNorthEast->equals( $rectangleSouthWest ) ) { |
|
42
|
1 |
|
throw new InvalidArgumentException( '$rectangleNorthEast cannot be equal to $rectangleSouthWest' ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// TODO: validate bounds are correct, if not, flip |
|
46
|
6 |
|
$this->setRectangleNorthEast( $rectangleNorthEast ); |
|
47
|
6 |
|
$this->setRectangleSouthWest( $rectangleSouthWest ); |
|
48
|
6 |
|
} |
|
49
|
|
|
|
|
50
|
4 |
|
public function getJSONObject( string $defText = '', string $defTitle = '' ): array { |
|
51
|
4 |
|
$parentArray = parent::getJSONObject( $defText, $defTitle ); |
|
52
|
|
|
$array = [ |
|
53
|
|
|
'ne' => [ |
|
54
|
4 |
|
'lon' => $this->getRectangleNorthEast()->getLongitude(), |
|
55
|
4 |
|
'lat' => $this->getRectangleNorthEast()->getLatitude() |
|
56
|
|
|
], |
|
57
|
|
|
'sw' => [ |
|
58
|
4 |
|
'lon' => $this->getRectangleSouthWest()->getLongitude(), |
|
59
|
4 |
|
'lat' => $this->getRectangleSouthWest()->getLatitude() |
|
60
|
|
|
], |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
4 |
|
return array_merge( $parentArray, $array ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
8 |
|
public function getRectangleNorthEast(): LatLongValue { |
|
67
|
8 |
|
return $this->rectangleNorthEast; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
8 |
|
public function setRectangleNorthEast( LatLongValue $rectangleNorthEast ) { |
|
71
|
8 |
|
$this->rectangleNorthEast = $rectangleNorthEast; |
|
72
|
8 |
|
} |
|
73
|
|
|
|
|
74
|
8 |
|
public function getRectangleSouthWest(): LatLongValue { |
|
75
|
8 |
|
return $this->rectangleSouthWest; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
8 |
|
public function setRectangleSouthWest( LatLongValue $rectangleSouthWest ) { |
|
79
|
8 |
|
$this->rectangleSouthWest = $rectangleSouthWest; |
|
80
|
8 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|