Matteo Scandolo | bf7c366 | 2016-06-02 20:30:15 -0700 | [diff] [blame] | 1 | /*global google: true */ |
| 2 | (function () { |
| 3 | 'use strict'; |
| 4 | |
| 5 | angular.module('mCord') |
Matteo Scandolo | be342fa | 2016-06-08 15:54:55 -0700 | [diff] [blame] | 6 | .directive('eNodeMap', function ($uibModal) { |
Matteo Scandolo | bf7c366 | 2016-06-02 20:30:15 -0700 | [diff] [blame] | 7 | 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 Scandolo | e0e4de4 | 2016-06-08 16:15:30 -0700 | [diff] [blame] | 14 | let bounds; |
Matteo Scandolo | bf7c366 | 2016-06-02 20:30:15 -0700 | [diff] [blame] | 15 | |
| 16 | Enodeb.query().$promise |
| 17 | .then((enodes) => { |
| 18 | this.enodes = enodes; |
Matteo Scandolo | e0e4de4 | 2016-06-08 16:15:30 -0700 | [diff] [blame] | 19 | bounds = new google.maps.LatLngBounds(); |
Matteo Scandolo | bf7c366 | 2016-06-02 20:30:15 -0700 | [diff] [blame] | 20 | enodes.forEach(node => { |
Matteo Scandolo | f25db3b | 2016-06-29 17:41:27 -0700 | [diff] [blame^] | 21 | console.log(node.GpsCoordinate); |
Matteo Scandolo | 3b82a59 | 2016-06-21 12:10:35 +0200 | [diff] [blame] | 22 | 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 Scandolo | bf7c366 | 2016-06-02 20:30:15 -0700 | [diff] [blame] | 26 | }); |
| 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 Scandolo | be342fa | 2016-06-08 15:54:55 -0700 | [diff] [blame] | 37 | 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 Scandolo | bf7c366 | 2016-06-02 20:30:15 -0700 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | }); |
| 50 | }()); |
| 51 | /*global google: false */ |