1
|
|
|
<?php namespace Arcanedev\GeoLocation\Entities; |
2
|
|
|
|
3
|
|
|
use Arcanedev\GeoLocation\Contracts\Entities\Position as PositionContract; |
4
|
|
|
use Arcanedev\GeoLocation\Contracts\Entities\Viewport as ViewportContract; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Viewport |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\GeoLocation\Entities |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class Viewport implements ViewportContract |
13
|
|
|
{ |
14
|
|
|
/* ----------------------------------------------------------------- |
15
|
|
|
| Properties |
16
|
|
|
| ----------------------------------------------------------------- |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/** @var \Arcanedev\GeoLocation\Contracts\Entities\Position */ |
20
|
|
|
protected $northeast; |
21
|
|
|
|
22
|
|
|
/** @var \Arcanedev\GeoLocation\Contracts\Entities\Position */ |
23
|
|
|
protected $southwest; |
24
|
|
|
|
25
|
|
|
/* ----------------------------------------------------------------- |
26
|
|
|
| Constructor |
27
|
|
|
| ----------------------------------------------------------------- |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Viewport constructor. |
32
|
|
|
* |
33
|
|
|
* @param \Arcanedev\GeoLocation\Contracts\Entities\Position $northeast |
34
|
|
|
* @param \Arcanedev\GeoLocation\Contracts\Entities\Position $southwest |
35
|
|
|
*/ |
36
|
21 |
|
public function __construct(PositionContract $northeast, PositionContract $southwest) |
37
|
|
|
{ |
38
|
21 |
|
$this->setNorthEast($northeast)->setSouthWest($southwest); |
39
|
21 |
|
} |
40
|
|
|
|
41
|
|
|
/* ----------------------------------------------------------------- |
42
|
|
|
| Getters & Setters |
43
|
|
|
| ----------------------------------------------------------------- |
44
|
|
|
*/ |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get the North/East coordinates. |
48
|
|
|
* |
49
|
|
|
* @return \Arcanedev\GeoLocation\Contracts\Entities\Position |
50
|
|
|
*/ |
51
|
6 |
|
public function getNorthEast() |
52
|
|
|
{ |
53
|
6 |
|
return $this->northeast; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Set the North/East coordinates. |
58
|
|
|
* |
59
|
|
|
* @param \Arcanedev\GeoLocation\Contracts\Entities\Position $northeast |
60
|
|
|
* |
61
|
|
|
* @return self |
62
|
|
|
*/ |
63
|
21 |
|
public function setNorthEast(PositionContract $northeast) |
64
|
|
|
{ |
65
|
21 |
|
$this->northeast = $northeast; |
66
|
|
|
|
67
|
21 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the South/West coordinates. |
72
|
|
|
* |
73
|
|
|
* @return \Arcanedev\GeoLocation\Contracts\Entities\Position |
74
|
|
|
*/ |
75
|
6 |
|
public function getSouthWest() |
76
|
|
|
{ |
77
|
6 |
|
return $this->southwest; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set the South/West coordinates. |
82
|
|
|
* |
83
|
|
|
* @param \Arcanedev\GeoLocation\Contracts\Entities\Position $southwest |
84
|
|
|
* |
85
|
|
|
* @return self |
86
|
|
|
*/ |
87
|
21 |
|
public function setSouthWest(PositionContract $southwest) |
88
|
|
|
{ |
89
|
21 |
|
$this->southwest = $southwest; |
90
|
|
|
|
91
|
21 |
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/* ----------------------------------------------------------------- |
95
|
|
|
| Main Methods |
96
|
|
|
| ----------------------------------------------------------------- |
97
|
|
|
*/ |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Create a new viewport instance. |
101
|
|
|
* |
102
|
|
|
* @param \Arcanedev\GeoLocation\Contracts\Entities\Position $northeast |
103
|
|
|
* @param \Arcanedev\GeoLocation\Contracts\Entities\Position $southwest |
104
|
|
|
* |
105
|
|
|
* @return self |
106
|
|
|
*/ |
107
|
18 |
|
public static function create(PositionContract $northeast, PositionContract $southwest) |
108
|
|
|
{ |
109
|
18 |
|
return new static($northeast, $southwest); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Convert the object to its JSON representation. |
114
|
|
|
* |
115
|
|
|
* @param int $options |
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
3 |
|
public function toJson($options = 0) |
120
|
|
|
{ |
121
|
3 |
|
return json_encode($this->jsonSerialize(), $options); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Convert the object into something JSON serializable. |
126
|
|
|
* |
127
|
|
|
* @return array |
128
|
|
|
*/ |
129
|
3 |
|
public function jsonSerialize() |
130
|
|
|
{ |
131
|
3 |
|
return $this->toArray(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Get the instance as an array. |
136
|
|
|
* |
137
|
|
|
* @return array |
138
|
|
|
*/ |
139
|
15 |
|
public function toArray() |
140
|
|
|
{ |
141
|
|
|
return [ |
142
|
15 |
|
'northeast' => $this->northeast->toArray(), |
143
|
15 |
|
'southwest' => $this->southwest->toArray(), |
144
|
5 |
|
]; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|