1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Clubdeuce\WPGoogleMaps; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Map |
7
|
|
|
* @package Clubdeuce\WPGoogleMaps |
8
|
|
|
*/ |
9
|
|
|
class Map extends Model_Base { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
protected $_center; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The Map element height (default: 400px). |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $_height = '400px'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The string to use for the map HTML element id property |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $_html_id; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Marker[] |
31
|
|
|
*/ |
32
|
|
|
protected $_markers = array(); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The Map element width (default: 100%). |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $_width = '100%'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var int |
42
|
|
|
*/ |
43
|
|
|
protected $_zoom = 5; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param Marker $marker |
47
|
|
|
*/ |
48
|
1 |
|
function add_marker( $marker ) { |
|
|
|
|
49
|
|
|
|
50
|
1 |
|
$this->_markers[] = $marker; |
51
|
|
|
|
52
|
1 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param Marker[] $markers |
56
|
|
|
*/ |
57
|
1 |
|
function add_markers( $markers ) { |
|
|
|
|
58
|
|
|
|
59
|
1 |
|
$this->_markers = array_merge( $this->_markers, $markers ); |
60
|
|
|
|
61
|
1 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
3 |
|
function center() { |
|
|
|
|
67
|
|
|
|
68
|
3 |
|
return $this->_center; |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
2 |
|
function height() { |
|
|
|
|
76
|
|
|
|
77
|
2 |
|
return $this->_height; |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
2 |
|
function html_id() { |
|
|
|
|
85
|
|
|
|
86
|
2 |
|
if ( ! isset( $this->_html_id ) ) { |
87
|
1 |
|
$this->_html_id = sprintf( 'map-%1$s', md5( serialize( array( $this->center(), $this->markers() ) ) ) ); |
88
|
|
|
} |
89
|
|
|
|
90
|
2 |
|
return $this->_html_id; |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return Marker[] |
96
|
|
|
*/ |
97
|
1 |
|
function markers() { |
|
|
|
|
98
|
|
|
|
99
|
1 |
|
return $this->_markers; |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
1 |
|
function width() { |
|
|
|
|
107
|
|
|
|
108
|
1 |
|
return $this->_width; |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return int |
114
|
|
|
*/ |
115
|
3 |
|
function zoom() { |
|
|
|
|
116
|
|
|
|
117
|
3 |
|
return $this->_zoom; |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param array $center |
123
|
|
|
*/ |
124
|
1 |
|
function set_center( $center ) { |
|
|
|
|
125
|
|
|
|
126
|
1 |
|
$center = wp_parse_args( $center, array( |
127
|
1 |
|
'lat' => null, |
128
|
|
|
'lng' => null, |
129
|
|
|
) ); |
130
|
|
|
|
131
|
1 |
|
$this->_center = $center; |
132
|
|
|
|
133
|
1 |
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param int $zoom |
137
|
|
|
*/ |
138
|
1 |
|
function set_zoom( $zoom ) { |
|
|
|
|
139
|
|
|
|
140
|
1 |
|
$this->_zoom = (int)$zoom; |
141
|
|
|
|
142
|
1 |
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param string $height |
146
|
|
|
*/ |
147
|
1 |
|
function set_height( $height ) { |
|
|
|
|
148
|
|
|
|
149
|
1 |
|
$this->_height = $height; |
150
|
|
|
|
151
|
1 |
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param string $id |
155
|
|
|
*/ |
156
|
1 |
|
function set_html_id( $id ) { |
|
|
|
|
157
|
|
|
|
158
|
1 |
|
$this->_html_id = $id; |
159
|
|
|
|
160
|
1 |
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return array |
164
|
|
|
* |
165
|
|
|
* @todo Refactor to make_params |
166
|
|
|
*/ |
167
|
1 |
|
function make_args() { |
|
|
|
|
168
|
|
|
|
169
|
|
|
return array( |
170
|
1 |
|
'center' => $this->center(), |
171
|
1 |
|
'zoom' => (int)$this->zoom(), |
172
|
|
|
); |
173
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
} |
177
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.