1 |
b88dd6bb
|
Jan Kohlíček
|
angular.module('pvpk')
|
2 |
|
|
.controller('mapController', ['$rootScope', '$scope', 'config', 'Device', function ($rootScope, $scope, config, Device) {
|
3 |
|
|
|
4 |
|
|
this.$onInit = function () {
|
5 |
|
|
$scope.markers = [];
|
6 |
|
|
|
7 |
|
|
$scope.map = new google.maps.Map(document.getElementById('map'), {
|
8 |
|
|
center: config.DEFAULT_POSITION,
|
9 |
|
|
zoom: config.DEFAULT_ZOOM,
|
10 |
|
|
minZoom: config.DEFAULT_ZOOM_MIN,
|
11 |
|
|
zoomControl: true,
|
12 |
|
|
mapTypeControl: false,
|
13 |
|
|
scaleControl: false,
|
14 |
|
|
streetViewControl: false,
|
15 |
|
|
rotateControl: false,
|
16 |
|
|
fullscreenControl: false,
|
17 |
|
|
mapTypeId: google.maps.MapTypeId.ROADMAP
|
18 |
|
|
});
|
19 |
|
|
|
20 |
|
|
Device.query({showDirection: 0}, function (data) {
|
21 |
|
|
for (var i = 0, lctn; lctn = data[i]; i++) {
|
22 |
|
|
$scope.createMarker(lctn);
|
23 |
|
|
}
|
24 |
|
|
}, function (response) {
|
25 |
|
|
console.log('Error api all Devices');
|
26 |
|
|
$rootScope.handleErrorResponse(response);
|
27 |
|
|
});
|
28 |
|
|
};
|
29 |
|
|
|
30 |
|
|
$scope.createMarker = function (lctn) {
|
31 |
|
|
if (lctn.lat && lctn.lng) {
|
32 |
|
|
var marker = new google.maps.Marker({
|
33 |
|
|
map: $scope.map,
|
34 |
|
|
position: {lat: lctn.lat, lng: lctn.lng},
|
35 |
|
|
title: lctn.name,
|
36 |
|
|
infoWindow: new google.maps.InfoWindow({
|
37 |
|
|
content: '<h6 class="mb-1">' + lctn.name + '</h6>'
|
38 |
|
|
+ '<address>' + lctn.street + ', ' + lctn.town + '</address>'
|
39 |
|
|
}),
|
40 |
|
|
id: lctn.id
|
41 |
|
|
});
|
42 |
|
|
|
43 |
|
|
marker.addListener('click', function () {
|
44 |
|
|
$scope.closeInfoWindows();
|
45 |
|
|
marker.infoWindow.open($scope.map, marker);
|
46 |
|
|
$rootScope.$emit('infoLocation', {id: lctn.id});
|
47 |
|
|
});
|
48 |
|
|
|
49 |
|
|
$scope.markers.push(marker);
|
50 |
|
|
}
|
51 |
|
|
};
|
52 |
|
|
|
53 |
|
|
$rootScope.$on('activeMarker', function (event, args) {
|
54 |
|
|
for (var i = 0, marker; marker = $scope.markers[i]; i++) {
|
55 |
|
|
if (marker.id && marker.id === args.id && marker.infoWindow) {
|
56 |
|
|
$scope.map.setCenter(marker.getPosition());
|
57 |
|
|
$scope.map.setZoom(12);
|
58 |
|
|
marker.infoWindow.open($scope.map, marker);
|
59 |
|
|
} else {
|
60 |
|
|
marker.infoWindow.close();
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
});
|
64 |
|
|
|
65 |
|
|
$rootScope.$on('setDefaultMap', function (event, args) {
|
66 |
|
|
$scope.map.setCenter(config.DEFAULT_POSITION);
|
67 |
|
|
$scope.map.setZoom(config.DEFAULT_ZOOM);
|
68 |
|
|
$scope.closeInfoWindows();
|
69 |
|
|
});
|
70 |
|
|
|
71 |
|
|
$scope.closeInfoWindows = function () {
|
72 |
|
|
for (var i = 0, marker; marker = $scope.markers[i]; i++) {
|
73 |
|
|
marker.infoWindow.close();
|
74 |
|
|
}
|
75 |
|
|
};
|
76 |
|
|
}]);
|