-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGoogleMap.php
61 lines (54 loc) · 1.89 KB
/
GoogleMap.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
<?php
/**
* Google map extension for Yii 1.x
*
* @author [email protected]
* @site: diz-blog.com.ua
* @ license: GPL
*
*/
class GoogleMap extends CWidget
{
public $visible=0;
public $markers = array();
public $params = array();
public $default_params = array('visible'=>true,'zoom'=>13,'minzoom'=>8,'width'=>'420px','height'=>'210px','lat' => 45.300, 'lng' => 34.400,);
// этот метод будет вызван внутри CBaseController::beginWidget()
public function init()
{
//Дополним значениями по умолч.
foreach ($this->default_params as $k=>$v)
{
if ( !isset($this->params[$k]) )
{
$this->params[$k] = $v;
}
}
Yii::app()->clientScript->registerScript(0,
'google_maps_markers='.CJSON::encode($this->markers).';'.
'google_maps_params='.CJSON::encode($this->params).';',
CClientScript::POS_READY
);
$this->publishAssets();
parent::init();
}
// этот метод будет вызван внутри CBaseController::endWidget()
public function run()
{
$this->render( 'googlemap',array('params'=>$this->params) );
}
public function publishAssets()
{
$assets = dirname(__FILE__).'/assets';
$baseUrl = Yii::app()->assetManager->publish($assets);
if(is_dir($assets))
{
Yii::app()->clientScript->registerScriptFile('https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false');
Yii::app()->clientScript->registerScriptFile($baseUrl . '/googlemap.js', CClientScript::POS_HEAD);
}
else
{
throw new Exception('Google map - Error: Couldn\'t find assets to publish.');
}
}
}