blob: 0771fa7cd8f1b75267588ec89aad1071e107d101 [file] [log] [blame]
Matteo Scandolobf7c3662016-06-02 20:30:15 -07001/*global google: true */
2(function () {
3 'use strict';
4
5 angular.module('mCord')
Matteo Scandolobe342fa2016-06-08 15:54:55 -07006 .directive('eNodeMap', function ($uibModal) {
Matteo Scandolobf7c3662016-06-02 20:30:15 -07007 return {
8 restrict: 'E',
9 scope: {},
10 controllerAs: 'vm',
11 templateUrl: 'app/view/home/e-node-map.tpl.html',
12 controller: function($log, Enodeb, NgMap){
13
Matteo Scandoloe0e4de42016-06-08 16:15:30 -070014 let bounds;
Matteo Scandolobf7c3662016-06-02 20:30:15 -070015
16 Enodeb.query().$promise
17 .then((enodes) => {
18 this.enodes = enodes;
Matteo Scandoloe0e4de42016-06-08 16:15:30 -070019 bounds = new google.maps.LatLngBounds();
Matteo Scandolobf7c3662016-06-02 20:30:15 -070020 enodes.forEach(node => {
Matteo Scandolof25db3b2016-06-29 17:41:27 -070021 console.log(node.GpsCoordinate);
Matteo Scandolo3b82a592016-06-21 12:10:35 +020022 if(angular.isDefined(node.GpsCoordinate.Latitude) && angular.isDefined(node.GpsCoordinate.Longitude)){
23 const latlng = new google.maps.LatLng(node.GpsCoordinate.Latitude, node.GpsCoordinate.Longitude);
24 bounds.extend(latlng);
25 }
Matteo Scandolobf7c3662016-06-02 20:30:15 -070026 });
27 return NgMap.getMap();
28 })
29 .then((map) => {
30 map.setCenter(bounds.getCenter());
31 map.fitBounds(bounds);
32 });
33
34 this.showEnodeDetails = (marker, enode) => {
35 this.selectedEnode = enode;
36 };
Matteo Scandolobe342fa2016-06-08 15:54:55 -070037 this.addEnode = () => {
38 this.modalInstance = $uibModal.open({
39 animation: true,
40 templateUrl: 'addEnode',
41 controllerAs: 'vm',
42 controller: function($uibModalInstance){
43 this.modal = $uibModalInstance;
44 }
45 });
46 }
Matteo Scandolobf7c3662016-06-02 20:30:15 -070047 }
48 }
49 });
50}());
51/*global google: false */