1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maps\Elements; |
4
|
|
|
|
5
|
|
|
use DataValues\Geo\Values\LatLongValue; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class describing a single location (geographical point). |
9
|
|
|
* |
10
|
|
|
* TODO: rethink the design of this class after deciding on what actual role it has |
11
|
|
|
* |
12
|
|
|
* @since 3.0 |
13
|
|
|
* |
14
|
|
|
* @licence GNU GPL v2+ |
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
16
|
|
|
* @author Daniel Werner |
17
|
|
|
*/ |
18
|
|
|
class Location extends BaseElement { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var LatLongValue |
22
|
|
|
*/ |
23
|
|
|
private $coordinates; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $address; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $icon = ''; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $group = ''; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $inlineLabel = ''; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $visitedIcon = ''; |
49
|
|
|
|
50
|
72 |
|
public function __construct( LatLongValue $coordinates ) { |
51
|
72 |
|
$this->coordinates = $coordinates; |
52
|
72 |
|
} |
53
|
|
|
|
54
|
|
|
public static function newFromLatLon( float $lat, float $lon ): self { |
55
|
|
|
return new self( new LatLongValue( $lat, $lon ) ); |
56
|
|
|
} |
57
|
|
|
|
58
|
7 |
|
public function getCoordinates(): LatLongValue { |
59
|
7 |
|
return $this->coordinates; |
60
|
|
|
} |
61
|
|
|
|
62
|
13 |
|
public function getJSONObject( string $defText = '', string $defTitle = '', string $defIconUrl = '', |
63
|
|
|
string $defGroup = '', string $defInlineLabel = '', string $defVisitedIcon = '' ): array { |
64
|
|
|
|
65
|
13 |
|
$parentArray = parent::getJSONObject( $defText, $defTitle ); |
|
|
|
|
66
|
|
|
|
67
|
|
|
$array = [ |
68
|
13 |
|
'lat' => $this->coordinates->getLatitude(), |
69
|
13 |
|
'lon' => $this->coordinates->getLongitude(), |
70
|
13 |
|
'icon' => $this->hasIcon() ? \MapsMapper::getFileUrl( $this->getIcon() ) : $defIconUrl, |
|
|
|
|
71
|
|
|
]; |
72
|
13 |
|
$val = $this->getAddress(); |
73
|
13 |
|
if ( $val !== '' ) { |
74
|
|
|
$array['address'] = $val; |
75
|
|
|
} |
76
|
13 |
|
$val = $this->hasGroup() ? $this->getGroup() : $defGroup; |
77
|
13 |
|
if ( !empty( $val ) ) { |
78
|
|
|
$array['group'] = $val; |
79
|
|
|
} |
80
|
13 |
|
$val = $this->hasInlineLabel() ? $this->getInlineLabel() : $defInlineLabel; |
81
|
13 |
|
if ( !empty( $val ) ) { |
82
|
1 |
|
$array['inlineLabel'] = $val; |
83
|
|
|
} |
84
|
13 |
|
$val = $this->hasVisitedIcon() ? $this->getVisitedIcon() : $defVisitedIcon; |
85
|
13 |
|
if ( !empty( $val ) ) { |
86
|
|
|
$array['visitedicon'] = $val; |
87
|
|
|
} |
88
|
|
|
|
89
|
13 |
|
return array_merge( $parentArray, $array ); |
90
|
|
|
} |
91
|
|
|
|
92
|
13 |
|
public function hasIcon(): bool { |
93
|
13 |
|
return $this->icon !== ''; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getIcon(): string { |
97
|
|
|
return $this->icon; |
98
|
|
|
} |
99
|
|
|
|
100
|
1 |
|
public function setIcon( string $icon ) { |
101
|
1 |
|
$this->icon = $icon; |
102
|
1 |
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns the address corresponding to this location. |
106
|
|
|
* If there is none, and empty sting is returned. |
107
|
|
|
*/ |
108
|
13 |
|
public function getAddress(): string { |
109
|
13 |
|
if ( is_null( $this->address ) ) { |
110
|
13 |
|
$this->address = ''; |
111
|
|
|
} |
112
|
|
|
|
113
|
13 |
|
return $this->address; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Returns whether Location is assigned to a group. |
118
|
|
|
*/ |
119
|
13 |
|
public function hasGroup(): bool { |
120
|
13 |
|
return $this->group !== ''; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function getGroup(): string { |
124
|
|
|
return $this->group; |
125
|
|
|
} |
126
|
|
|
|
127
|
1 |
|
public function setGroup( string $group ) { |
128
|
1 |
|
$this->group = trim( $group ); |
129
|
1 |
|
} |
130
|
|
|
|
131
|
13 |
|
public function hasInlineLabel(): bool { |
132
|
13 |
|
return $this->inlineLabel !== ''; |
133
|
|
|
} |
134
|
|
|
|
135
|
1 |
|
public function getInlineLabel(): string { |
136
|
1 |
|
return $this->inlineLabel; |
137
|
|
|
} |
138
|
|
|
|
139
|
1 |
|
public function setInlineLabel( string $label ) { |
140
|
1 |
|
$this->inlineLabel = $label; |
141
|
1 |
|
} |
142
|
|
|
|
143
|
13 |
|
public function hasVisitedIcon(): bool { |
144
|
13 |
|
return $this->visitedIcon !== ''; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getVisitedIcon(): string { |
148
|
|
|
return $this->visitedIcon; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function setVisitedIcon( string $visitedIcon ) { |
152
|
|
|
$this->visitedIcon = $visitedIcon; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
This method has been deprecated.