-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSvgMapWidget.php
82 lines (67 loc) · 1.69 KB
/
SvgMapWidget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace ghopper\svgmap;
use yii\base\Widget;
/**
* Class SvgMapWidget
* @package ghopper\svgmap
*/
class SvgMapWidget extends Widget
{
const DATA_SOURCE_ARRAY = 1;
const DATA_SOURCE_JSON_URL = 2;
/**
* @var int Data provider type
*/
public $type;
/**
* @var mixed
*/
public $data;
/**
* @var bool Tooltip show flag
*/
public $showTip;
/**
* @var bool Tools panel show flag
*/
public $showTools;
/**
* @var string Callback functions for events handler
*/
public $onClick;
public $onOver;
public $onOut;
public function init()
{
parent::init();
if ($this->type === self::DATA_SOURCE_ARRAY) {
$this->data = json_encode($this->data);
}
/**
* Show tooltip by default
*/
if (!isset($this->showTip)) {
$this->showTip = true;
}
/**
* Hide tools by default
*/
if (!isset($this->showTools)) {
$this->showTools = true;
}
}
public function run()
{
SvgMapWidgetAsset::register($this->getView());
return $this->render('default', [
'id' => $this->getId(),
'type' => ($this->type === self::DATA_SOURCE_ARRAY) ? 'json' : 'url',
'data' => $this->data,
'showTip' => ($this->showTip) ? 'true' : 'false',
'showTools' => ($this->showTools) ? 'true' : 'false',
'onClick' => ($this->onClick) ? $this->onClick : 'null',
'onOver' => ($this->onOver) ? $this->onOver : 'null',
'onOut' => ($this->onOut) ? $this->onOut : 'null',
]);
}
}