This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathMapAsset.php
77 lines (70 loc) · 2.27 KB
/
MapAsset.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
<?php
/*
*
* @copyright Copyright (c) 2013-2019 2amigos
* @link http://2amigos.us
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*
*/
namespace dosamigos\google\maps;
use Yii;
use yii\web\AssetBundle;
/**
* MapAsset
*
* Registers the google maps api
*
* To update the key or other options like language, version, or library
* use the Asset Bundle customization.
* http://www.yiiframework.com/doc-2.0/guide-structure-assets.html#customizing-asset-bundles
* To get key, please visit https://code.google.com/apis/console/
*
* 'components' => [
* 'assetManager' => [
* 'bundles' => [
* 'dosamigos\google\maps\MapAsset' => [
* 'options' => [
* 'key' => 'this_is_my_key',
* 'language' => 'id',
* 'version' => '3.1.18'
* ]
* ]
* ]
* ],
* ],
*
* @author Antonio Ramirez <[email protected]>
*
* @link http://www.2amigos.us/
* @package dosamigos\google\maps
*/
class MapAsset extends AssetBundle
{
/**
* Sets options for the google map
* @var array
*/
public $options = [];
/**
* @inheritdoc
*/
public function init()
{
// BACKWARD COMPATIBILITY
// To configure please, add `googleMapsApiKey` parameter to your application configuration
// file with the value of your API key. To get yours, please visit https://code.google.com/apis/console/.
$key = @Yii::$app->params['googleMapsApiKey'];
// To configure please, add `googleMapsLibraries` parameter to your application configuration.
// For example "geometry,places"
$libraries = @Yii::$app->params['googleMapsLibraries'];
// To configure please, add `googleMapsLanguage` parameter to your application configuration
$language = @Yii::$app->params['googleMapsLanguage'];
$this->options = array_merge($this->options, array_filter([
'key' => $key,
'libraries' => $libraries,
'language' => $language,
]));
// BACKWARD COMPATIBILITY
$this->js[] = '//maps.googleapis.com/maps/api/js?' . http_build_query($this->options);
}
}