blob: 423a5c7f346fd45beeac86b026447a5477fc687b [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 Scandolo3b82a592016-06-21 12:10:35 +020021 if(angular.isDefined(node.GpsCoordinate.Latitude) && angular.isDefined(node.GpsCoordinate.Longitude)){
22 const latlng = new google.maps.LatLng(node.GpsCoordinate.Latitude, node.GpsCoordinate.Longitude);
23 bounds.extend(latlng);
24 }
Matteo Scandolobf7c3662016-06-02 20:30:15 -070025 });
26 return NgMap.getMap();
27 })
28 .then((map) => {
29 map.setCenter(bounds.getCenter());
30 map.fitBounds(bounds);
31 });
32
33 this.showEnodeDetails = (marker, enode) => {
34 this.selectedEnode = enode;
35 };
Matteo Scandolobe342fa2016-06-08 15:54:55 -070036 this.addEnode = () => {
37 this.modalInstance = $uibModal.open({
38 animation: true,
39 templateUrl: 'addEnode',
40 controllerAs: 'vm',
41 controller: function($uibModalInstance){
42 this.modal = $uibModalInstance;
43 }
44 });
45 }
Matteo Scandolobf7c3662016-06-02 20:30:15 -070046 }
47 }
48 });
49}());
50/*global google: false */