MapInputAsset.php
1.05 KB
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
<?php
namespace backend\themes\defaults\widgets\mapInputWidget\assets;
class MapInputAsset extends \yii\web\AssetBundle
{
public static $key;
public $sourcePath = '@backend/themes/defaults/widgets/mapInputWidget/web';
public $depends =
[
'yii\web\JqueryAsset',
];
public $jsOptions =
[
'position' => \yii\web\View::POS_END,
];
public function __construct($config = [])
{
$this->js[] = $this->getGoogleMapScriptUrl();
if (YII_DEBUG) {
$this->js[] = 'js/map-input-widget.js';
$this->css[] = 'css/map-input-widget.css';
} else {
$this->js[] = 'js/map-input-widget.js';
$this->css[] = 'css/map-input-widget.min.css';
}
parent::__construct($config);
}
private function getGoogleMapScriptUrl()
{
$scriptUrl = "//maps.googleapis.com/maps/api/js?";
$scriptUrl .= http_build_query([
'key' => self::$key,
'libraries' => 'places',
]);
return $scriptUrl;
}
}