|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the CJTTERABYTESOFT yii2-widgets |
|
5
|
|
|
* |
|
6
|
|
|
* (c) CJT TERABYTE LLC yii2-extension <https://github.com/cjtterabytesoft/yii2-jvectormap> |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
8
|
|
|
* file that was distributed with this source code |
|
9
|
|
|
* |
|
10
|
|
|
* @link: https://github.com/cjtterabytesoft/yii2-jvectormap |
|
11
|
|
|
* @author: Wilmer Arámbula <[email protected]> |
|
12
|
|
|
* @copyright: (c) CJT TERABYTE LLC |
|
13
|
|
|
* @Widget: [yii2-jvectormap] |
|
14
|
|
|
* @Library: [JVectorMap] |
|
15
|
|
|
* @since: 0.0.1-dev |
|
16
|
|
|
**/ |
|
17
|
|
|
|
|
18
|
|
|
namespace cjtterabytesoft\jvectormap; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
use yii; |
|
22
|
|
|
use yii\helpers\Html; |
|
23
|
|
|
use yii\helpers\Json; |
|
24
|
|
|
use yii\base\Widget; |
|
25
|
|
|
use cjtterabytesoft\jvectormap\assets\JvectormapAsset; |
|
26
|
|
|
use cjtterabytesoft\jvectormap\assets\MapAsset; |
|
27
|
|
|
use cjtterabytesoft\jvectormap\assets\MapcustomAsset; |
|
28
|
|
|
|
|
29
|
|
|
class Jvectormap extends Widget |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var string jvpath js map **/ |
|
32
|
|
|
public $jvpath = '@cjtterabytesoft/jvectormap/assets/maps/js/'; |
|
33
|
|
|
|
|
34
|
|
|
/** @var string jvpathcustom js map **/ |
|
35
|
|
|
public $jvpathcustom = '@webroot/maps/js/'; |
|
36
|
|
|
|
|
37
|
|
|
/** @var string $jvname js map **/ |
|
38
|
|
|
public $jvname = 'jquery-jvectormap-'; |
|
39
|
|
|
|
|
40
|
|
|
/** @var integer $jverror js map **/ |
|
41
|
|
|
public $jverror = 0; |
|
42
|
|
|
|
|
43
|
|
|
/** @var string $jvimage404 js map **/ |
|
44
|
|
|
public $jvimage404 = '/images/errors/404-map.png'; |
|
45
|
|
|
|
|
46
|
|
|
/** @var string $jvimage500 js map **/ |
|
47
|
|
|
public $jvimage500 = '/images/errors/500-map.png'; |
|
48
|
|
|
|
|
49
|
|
|
/** @var string bundle assets **/ |
|
50
|
|
|
public $bundle; |
|
51
|
|
|
|
|
52
|
|
|
/** @var string tag container **/ |
|
53
|
|
|
public $tag = 'div'; |
|
54
|
|
|
|
|
55
|
|
|
/** @var string $id [div] [$id - function Jquery.JVectorMap] **/ |
|
56
|
|
|
public $id; |
|
57
|
|
|
|
|
58
|
|
|
/** @var array [div - $htmlOptions[$style]] **/ |
|
59
|
|
|
public $style = []; |
|
60
|
|
|
|
|
61
|
|
|
/** @var array [div - $htmlOptions] **/ |
|
62
|
|
|
public $htmlOptions = []; |
|
63
|
|
|
|
|
64
|
|
|
/** @var string [$map] **/ |
|
65
|
|
|
public $map; |
|
66
|
|
|
|
|
67
|
|
|
/** @var boolean jvdefault js map **/ |
|
68
|
|
|
public $maptype = false; |
|
69
|
|
|
|
|
70
|
|
|
/** @var array [$config function Jquery.JVectorMap] **/ |
|
71
|
|
|
public $config = []; |
|
72
|
|
|
|
|
73
|
|
|
/** @var string [$backgroundColor] **/ |
|
74
|
|
|
public $backgroundColor; |
|
75
|
|
|
|
|
76
|
|
|
/** @var string [$focusOn] **/ |
|
77
|
|
|
public $focusOn = []; |
|
78
|
|
|
|
|
79
|
|
|
/** @var array [$labels] **/ |
|
80
|
|
|
public $labels = []; |
|
81
|
|
|
|
|
82
|
|
|
/** @var array [$markerLabelStyle] **/ |
|
83
|
|
|
public $markerLabelStyle = []; |
|
84
|
|
|
|
|
85
|
|
|
/** @var array [$markers] **/ |
|
86
|
|
|
public $markers = []; |
|
87
|
|
|
|
|
88
|
|
|
/** @var boolean [$markersSelectable] **/ |
|
89
|
|
|
public $markersSelectable = false; |
|
90
|
|
|
|
|
91
|
|
|
/** @var boolean [$markersSelectableOne] **/ |
|
92
|
|
|
public $markersSelectableOne = false; |
|
93
|
|
|
|
|
94
|
|
|
/** @var array [$markerStyle] **/ |
|
95
|
|
|
public $markerStyle = []; |
|
96
|
|
|
|
|
97
|
|
|
/** @var boolean [$panOnDrag] **/ |
|
98
|
|
|
public $panOnDrag = true; |
|
99
|
|
|
|
|
100
|
|
|
/** @var array [$regionLabelStyle] **/ |
|
101
|
|
|
public $regionLabelStyle = []; |
|
102
|
|
|
|
|
103
|
|
|
/** @var boolean [$regionsSelectable] **/ |
|
104
|
|
|
public $regionsSelectable = true; |
|
105
|
|
|
|
|
106
|
|
|
/** @var boolean [$regionsSelectableOne] **/ |
|
107
|
|
|
public $regionsSelectableOne = false; |
|
108
|
|
|
|
|
109
|
|
|
/** @var array [$regionStyle] **/ |
|
110
|
|
|
public $regionStyle = []; |
|
111
|
|
|
|
|
112
|
|
|
/** @var array [$selectedMarkers] **/ |
|
113
|
|
|
public $selectedMarkers = []; |
|
114
|
|
|
|
|
115
|
|
|
/** @var array [$selectedRegions] **/ |
|
116
|
|
|
public $selectedRegions = []; |
|
117
|
|
|
|
|
118
|
|
|
/** @var array [$series] **/ |
|
119
|
|
|
public $series = []; |
|
120
|
|
|
|
|
121
|
|
|
/** @var boolean [$zoomAnimate] **/ |
|
122
|
|
|
public $zoomAnimate = false; |
|
123
|
|
|
|
|
124
|
|
|
/** @var integer [$zoomMax] **/ |
|
125
|
|
|
public $zoomMax; |
|
126
|
|
|
|
|
127
|
|
|
/** @var integer [$zoomMin] **/ |
|
128
|
|
|
public $zoomMin; |
|
129
|
|
|
|
|
130
|
|
|
/** @var boolean [$zoomOnScroll] **/ |
|
131
|
|
|
public $zoomOnScroll = true; |
|
132
|
|
|
|
|
133
|
|
|
public function init() |
|
134
|
|
|
{ |
|
135
|
|
|
parent::init(); |
|
136
|
|
|
if (empty($this->id)) { |
|
137
|
|
|
$this->id = 'vmap'; |
|
138
|
|
|
} |
|
139
|
|
|
$this->htmlOptions['id'] = $this->id; |
|
140
|
|
|
$this->htmlOptions['style'] = $this->style; |
|
141
|
|
|
if (empty($this->map)) { |
|
142
|
|
|
$this->jverror = 1; |
|
143
|
|
|
} else { |
|
144
|
|
|
$this->MapJS(); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function run() |
|
149
|
|
|
{ |
|
150
|
|
|
if ($this->jverror == 0) { |
|
151
|
|
|
$this->config = Json::encode( |
|
|
|
|
|
|
152
|
|
|
[ |
|
153
|
|
|
'map' => str_replace('-', '_', $this->map), |
|
154
|
|
|
!$this->backgroundColor ?: 'backgroundColor' => |
|
155
|
|
|
!$this->backgroundColor ?: $this->backgroundColor, |
|
156
|
|
|
!$this->focusOn ?: 'focusOn' => |
|
157
|
|
|
!$this->focusOn ?: $this->focusOn, |
|
158
|
|
|
!$this->labels ?: 'labels' => |
|
159
|
|
|
!$this->labels ?: $this->labels, |
|
160
|
|
|
!$this->markerLabelStyle ?: 'markerLabelStyle' => |
|
161
|
|
|
!$this->markerLabelStyle ?: $this->markerLabelStyle, |
|
162
|
|
|
!$this->markers ?: 'markers' => |
|
163
|
|
|
!$this->markers ?: $this->markers, |
|
164
|
|
|
'markersSelectable' => $this->markersSelectable, |
|
165
|
|
|
'markersSelectableOne' => $this->markersSelectableOne, |
|
166
|
|
|
!$this->markerStyle ?: 'markerStyle' => |
|
167
|
|
|
!$this->markerStyle ?: $this->markerStyle, |
|
168
|
|
|
'panOnDrag' => $this->panOnDrag, |
|
169
|
|
|
!$this->regionLabelStyle ?: '$regionLabelStyle' => |
|
170
|
|
|
!$this->regionLabelStyle ?: $this->regionLabelStyle, |
|
171
|
|
|
'regionsSelectable' => $this->regionsSelectable, |
|
172
|
|
|
'regionsSelectableOne' => $this->regionsSelectableOne, |
|
173
|
|
|
!$this->selectedMarkers ?: 'selectedMarkers' => |
|
174
|
|
|
!$this->selectedMarkers ?: $this->selectedMarkers, |
|
175
|
|
|
!$this->selectedRegions ?: 'selectedRegions' => |
|
176
|
|
|
!$this->selectedRegions ?: $this->selectedRegions, |
|
177
|
|
|
!$this->regionStyle ?: 'regionStyle' => |
|
178
|
|
|
!$this->regionStyle ?: $this->regionStyle, |
|
179
|
|
|
!$this->series ?: 'series' => |
|
180
|
|
|
!$this->series ?: $this->series, |
|
181
|
|
|
'zoomAnimate' => $this->zoomAnimate, |
|
182
|
|
|
!$this->zoomMax ?: 'zoomMax' => |
|
183
|
|
|
!$this->zoomMax ?: $this->zoomMax, |
|
184
|
|
|
!$this->zoomMin ?: 'zoomMin' => |
|
185
|
|
|
!$this->zoomMin ?: $this->zoomMin, |
|
186
|
|
|
'zoomOnScroll' => $this->zoomOnScroll, |
|
187
|
|
|
] |
|
188
|
|
|
); |
|
189
|
|
|
echo Html::beginTag($this->tag, $this->htmlOptions); |
|
190
|
|
|
echo Html::endTag($this->tag); |
|
191
|
|
|
Yii::$app->view->registerJs("jQuery('#{$this->id}').vectorMap($this->config)"); |
|
192
|
|
|
} else { |
|
193
|
|
|
$this->ErrorMap(); |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function MapJS() { |
|
198
|
|
|
$this->jvname = $this->jvname . str_replace('_', '-', $this->map) . ".js"; |
|
199
|
|
|
if (file_exists(yii::getAlias((!$this->maptype ? $this->jvpath : $this->jvpathcustom) . $this->jvname))) { |
|
200
|
|
|
JvectormapAsset::register(Yii::$app->view); |
|
201
|
|
|
$this->bundle = !$this->maptype ? MapAsset::register(Yii::$app->view) : |
|
|
|
|
|
|
202
|
|
|
MapcustomAsset::register(Yii::$app->view); |
|
203
|
|
|
$this->bundle->js[] = $this->jvname; // dynamic map added |
|
204
|
|
|
$this->bundle->publishOptions[] = [ |
|
205
|
|
|
'only' => [ |
|
206
|
|
|
yii::getalias((!$this->maptype ? $this->jvpath : $this->jvpathcustom) . $this->jvname), |
|
207
|
|
|
] |
|
208
|
|
|
]; |
|
209
|
|
|
} else { |
|
210
|
|
|
$this->jverror = 2; |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
public function ErrorMap() { |
|
215
|
|
|
switch ($this->jverror) { |
|
216
|
|
|
case 1: |
|
217
|
|
|
echo Html::beginTag($this->tag, $this->htmlOptions); |
|
218
|
|
|
echo Html::img($this->jvimage500, $options = ['alt' => '500 - The Map Option is Required.', |
|
219
|
|
|
'style' => 'max-width:100%;width:100%;']); |
|
220
|
|
|
echo Html::endTag($this->tag); |
|
221
|
|
|
break; |
|
222
|
|
|
case 2: |
|
223
|
|
|
echo Html::beginTag($this->tag, $this->htmlOptions); |
|
224
|
|
|
echo Html::img($this->jvimage404, $options = ['alt' => '404 - Map Not Found', |
|
225
|
|
|
'style' => 'max-width:100%;width:100%;']); |
|
226
|
|
|
echo Html::endTag($this->tag); |
|
227
|
|
|
break; |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..