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 |
|
'styles' => $model->styles(), |
55
|
2 |
|
'zoom' => $model->zoom(), |
56
|
|
|
); |
57
|
|
|
|
58
|
2 |
|
return array_filter( $params ); |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
1 |
|
protected function _make_markers_args() { |
66
|
|
|
|
67
|
1 |
|
$marker_args = array(); |
68
|
|
|
|
69
|
1 |
|
foreach ( $this->_model->markers() as $marker ) { |
70
|
|
|
$args = array( |
71
|
1 |
|
'position' => $marker->position(), |
72
|
1 |
|
'title' => $marker->title(), |
73
|
|
|
); |
74
|
|
|
|
75
|
1 |
|
if ( ! empty( $label = self::_make_label_args( $marker->label() ) ) ) { |
|
|
|
|
76
|
1 |
|
$args['label'] = $label; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
$marker_args[] = $args; |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
return array_filter( $marker_args ); |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param Marker_Label $label |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
1 |
|
protected function _make_label_args( $label ) { |
92
|
|
|
|
93
|
1 |
|
$args = array(); |
94
|
|
|
|
95
|
1 |
|
if ( ! empty( $label->text() ) ) { |
96
|
|
|
$args = array( |
97
|
1 |
|
'color' => $label->color(), |
98
|
1 |
|
'fontFamily' => $label->font_family(), |
99
|
1 |
|
'fontSize' => $label->font_size(), |
100
|
1 |
|
'fontWeight' => $label->font_weight(), |
101
|
1 |
|
'text' => $label->text(), |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
1 |
|
return $args; |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return array |
111
|
|
|
*/ |
112
|
1 |
|
protected function _make_info_windows() { |
113
|
|
|
|
114
|
1 |
|
$windows = array(); |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @var Marker $marker |
118
|
|
|
*/ |
119
|
1 |
|
foreach( $this->_model->markers() as $marker ) { |
120
|
1 |
|
$info_window = $marker->info_window(); |
121
|
1 |
|
$windows[] = array( |
122
|
1 |
|
'content' => $info_window->content(), |
123
|
1 |
|
'pixel_offset' => $info_window->pixel_offset(), |
124
|
1 |
|
'position' => $info_window->position(), |
125
|
1 |
|
'max_width' => $info_window->max_width(), |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
1 |
|
return $windows; |
130
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
} |