map.php
3.82 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Created by PhpStorm.
* User: allakuzmenko
* Date: 23.10.17
* Time: 21:02
*/
use yii\helpers\Html;
use frontend\modules\map\Map;
use frontend\themes\defaults\assets\AppAsset;
$urlMapResource = Map::getUrlListByType('resource');
$urlMapProjects = Map::getUrlListByType('project');
$bundle = AppAsset::register($this);
$js_icons = [];
$js_features = [];
function jsString($str = '')
{
return preg_replace("/('|\"|\r?\n)/", '', $str);
}
foreach ($models as $model) {
/* $js_icons[] = '
' . $group['id'] . ': { icon: \'' . addslashes($group->getImageLink()) . '\'}';*/
$content = $this->render('parts/_popup', [
'model' => $model,
'types' => $types,
]);
$position = str_replace('(', '', $model['coordinates']);
$position = str_replace(')', '', $position);
$position = explode(',', $position);
$js_features[] = '{
"id": "' . $model['id'] . '",
"title": "' . addslashes($model['lang']['title']) . '",
"position": {"lat": ' . $position[0] . ', "lng": ' . $position[1] . '},
"type": "' . $model['type_id'] . '",
"direction": "' . $model['area_id'] . '",
"region": "' . $model['region_id'] . '",
"power": "' . $model['electric_power'] . '",
"investment": "' . $model['investment'] . '",
"icon": "' . $bundle->baseUrl . '/img/curent-wind.png",
"infoWindow": {"content": "' . addslashes(jsString($content)) . '"}
}';
}
if (!empty($js_icons)) {
$js_icons = implode(",", $js_icons);
} else {
$js_icons = '';
}
if (!empty($js_features)) {
$js_features = implode(",", $js_features);
} else {
$js_features = '';
}
?>
<div class="inner-map-container">
<div class="static-btn-container">
<?= (Yii::$app->request->get('type') == 'project')
? Html::a(Yii::t('front', 'resource potential'), $urlMapResource, [
'class' => 'static-btn static-btn-resours'
]) : Html::a(Yii::t('front', 'projects'), $urlMapProjects, [
'class' => 'static-btn static-btn-project'
])
?>
</div>
<div class="maps-action-elements">
<?= $this->render('parts/filters', ['types' => $types, 'regions' => $regions]); ?>
<div class="search-block">
<form class="search-form">
<input class="search-input" name="" placeholder="пошук">
<button type="submit" class="search-input-btn"></button>
</form>
</div>
<div class="all-obj">
<a href="<?= Map::getUrlList() ?>" class="link-all-obj"><span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
</div>
</div>
<div class="map" id="map">
</div>
</div>
<?php
$script = <<< JS
var markers = [$js_features];
function initMap() {
var myLatLng = {lat: 48.741280, lng: 30.215513};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
center: myLatLng,
scrollwheel: false
});
for (var i = 0, l = markers.length; i < l; i++) {
var marker = markers[i];
marker.map = map;
markers[i] = new google.maps.Marker(marker);
}
}
JS;
$this->registerJsFile($bundle->baseUrl . '/libs/infoBubble/infobubble.js');
$this->registerJsFile('//developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js');
$this->registerJsFile('//maps.googleapis.com/maps/api/js?key=AIzaSyCRjI5CDX5BPpcmvu6a6bSzDyMXThMaNeo&callback=initMap');
$this->registerJs($script, yii\web\View::POS_HEAD);