-
Notifications
You must be signed in to change notification settings - Fork 0
/
RGmapPicker.php
76 lines (56 loc) · 1.93 KB
/
RGmapPicker.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
<?php
class RGmapPicker extends CInputWidget
{
private $assetsDir;
public $title = 'Pick Location';
public $element_id = null;
public $value = null;
public $name = null;
# GMAP size
public $map_width = '100';
public $map_height = '100';
# GMAP init location
public $map_latitude = '-6.2';
public $map_longitude = '106.8';
public $map_location_name = '';
public $htmlOptions = array();
protected $htmlopt = null;
public function init()
{
if (empty($this->element_id)) {
try {
list($name, $id) = $this->resolveNameID();
$this->element_id = $id;
} catch (Exception $e) {}
}
if (!empty($this->htmlOptions)) {
$opt = '';
foreach ($this->htmlOptions as $key => $value) {
$opt .= $key . '="' . $value . '" ';
}
$this->htmlopt = $opt;
}
if (empty($this->name)) {
$this->name = $this->element_id;
}
$dir = dirname(__FILE__) . '/assets';
$this->assetsDir = Yii::app()->assetManager->publish($dir);
}
public function run()
{
$this->registerScripts();
if (!empty($this->element_id)) {
$id = $this->htmlOptions['id'] = $this->element_id;
}
$this->render('gmap_picker');
}
private function registerScripts()
{
$mapSize = '.gllpMap { width: ' . $this->map_width . 'px; height: ' . $this->map_height . 'px; }';
Yii::app()->clientScript
->registerCssFile($this->assetsDir . '/css/jquery-gmaps-latlon-picker.css')
->registerCss('gllMap', $mapSize)
->registerScriptFile('http://maps.googleapis.com/maps/api/js?sensor=false', CClientScript::POS_END)
->registerScriptFile($this->assetsDir . '/js/jquery-gmaps-latlon-picker.js', CClientScript::POS_END);
}
}