1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Clubdeuce\WPGoogleMaps; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Map_View |
7
|
|
|
* @package Clubdeuce\WPGoogleMaps |
8
|
|
|
*/ |
9
|
|
|
class Map_View { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var Map_Model |
13
|
|
|
*/ |
14
|
|
|
protected $_model; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Map_View constructor. |
18
|
|
|
* |
19
|
|
|
* @param Map_Model $model |
20
|
|
|
*/ |
21
|
3 |
|
public function __construct( $model ) { |
22
|
|
|
|
23
|
3 |
|
$this->_model = $model; |
24
|
|
|
|
25
|
3 |
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param array $args |
29
|
|
|
*/ |
30
|
1 |
|
public function the_map( $args = array() ) { |
31
|
|
|
|
32
|
1 |
|
$args = wp_parse_args( $args, array( |
33
|
1 |
|
'template' => Google_Maps::source_dir() . '/templates/map-view.php', |
34
|
|
|
) ); |
35
|
|
|
|
36
|
1 |
|
require $args['template']; |
37
|
|
|
|
38
|
1 |
|
} |
39
|
|
|
|
40
|
1 |
|
public function the_map_params() { |
41
|
|
|
|
42
|
1 |
|
echo json_encode( $this->_map_params() ); |
43
|
|
|
|
44
|
1 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
2 |
|
protected function _map_params() { |
50
|
|
|
|
51
|
2 |
|
$model = $this->_model; |
52
|
|
|
$params = array( |
53
|
2 |
|
'center' => $model->center(), |
54
|
2 |
|
'height' => $model->height(), |
55
|
2 |
|
'styles' => $model->styles(), |
56
|
2 |
|
'zoom' => $model->zoom(), |
57
|
|
|
); |
58
|
|
|
|
59
|
2 |
|
return array_filter( $params ); |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
1 |
|
protected function _make_markers_args() { |
67
|
|
|
|
68
|
1 |
|
$marker_args = array(); |
69
|
|
|
|
70
|
1 |
|
foreach ( $this->_model->markers() as $marker ) { |
71
|
1 |
|
$marker_args[] = $this->_make_marker_args( $marker ); |
72
|
|
|
} |
73
|
|
|
|
74
|
1 |
|
return array_filter( $marker_args ); |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param Marker $marker |
80
|
|
|
* |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
1 |
|
protected function _make_marker_args( $marker ) { |
84
|
|
|
|
85
|
1 |
|
$args = array(); |
86
|
|
|
|
87
|
1 |
|
foreach ( $marker->marker_args() as $key => $value ) { |
88
|
1 |
|
$args[ $this->_camel_case( $key ) ] = $value; |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
if ( ! empty( $label = $this->_make_label_args( $marker->label() ) ) ) { |
92
|
1 |
|
$args['label'] = $label; |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
return $args; |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param Marker_Label $label |
101
|
|
|
* |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
1 |
|
protected function _make_label_args( $label ) { |
105
|
|
|
|
106
|
1 |
|
$args = array(); |
107
|
|
|
|
108
|
1 |
|
if ( ! empty( $label->text() ) ) { |
109
|
|
|
$args = array( |
110
|
1 |
|
'color' => $label->color(), |
111
|
1 |
|
'fontFamily' => $label->font_family(), |
112
|
1 |
|
'fontSize' => $label->font_size(), |
113
|
1 |
|
'fontWeight' => $label->font_weight(), |
114
|
1 |
|
'text' => $label->text(), |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
1 |
|
return $args; |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return array |
124
|
|
|
*/ |
125
|
1 |
|
protected function _make_info_windows() { |
126
|
|
|
|
127
|
1 |
|
$windows = array(); |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var Marker $marker |
131
|
|
|
*/ |
132
|
1 |
|
foreach( $this->_model->markers() as $marker ) { |
133
|
1 |
|
$info_window = $marker->info_window(); |
134
|
1 |
|
$windows[] = array( |
135
|
1 |
|
'content' => $info_window->content(), |
136
|
1 |
|
'pixel_offset' => $info_window->pixel_offset(), |
137
|
1 |
|
'position' => $info_window->position(), |
138
|
1 |
|
'max_width' => $info_window->max_width(), |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
1 |
|
return $windows; |
143
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
146
|
1 |
|
protected function _camel_case( $text, $delimiter = '_' ) { |
147
|
|
|
|
148
|
1 |
|
$parts = explode( $delimiter, $text ); |
149
|
|
|
|
150
|
1 |
|
if ( count( $parts ) ) { |
151
|
1 |
|
$text = ''; |
152
|
1 |
|
foreach( $parts as $key => $value ) { |
153
|
1 |
|
$text .= 0 < $key ? ucfirst( $value ) : $value; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
1 |
|
return $text; |
158
|
|
|
|
159
|
|
|
} |
160
|
|
|
} |