Commit 562610b62d8a8348aceda0c25105f9cf2c16fc1a

Authored by Kuldeep Arora
1 parent f9e936a9de
Exists in master

angular interval and state change code

app/partials/flightTracking/flightTracking.controller.js
1 'use strict'; 1 'use strict';
2 2
3 angular.module('acufuel') 3 angular.module('acufuel')
4 4
5 .controller('flightTrackingController', ['$scope','$compile', 'uiCalendarConfig', 'flightTrackingService', function($scope, $compile, uiCalendarConfig, flightTrackingService) { 5 .controller('flightTrackingController', ['$scope','$compile', 'uiCalendarConfig', 'flightTrackingService','$interval', function($scope, $compile, uiCalendarConfig, flightTrackingService,$interval) {
6 $scope.flightInfo = {}; 6 $scope.flightInfo = {};
7 var map; 7 var map;
8 var icon = "https://en.spitogatos.gr/visualCaptcha/images/airplane.png"; 8 var icon = "https://en.spitogatos.gr/visualCaptcha/images/airplane.png";
9 var json = "http://34.214.139.94:8080/ws/liveTracking"; 9 var json = "http://34.214.139.94:8080/ws/liveTracking";
10 var arr = []; 10 var arr = [];
11 var infowindow = new google.maps.InfoWindow(); 11 var infowindow = new google.maps.InfoWindow();
12 12
13 $scope.initialise = function() { 13 $scope.initialise = function() {
14 var mapProp = { 14 var mapProp = {
15 center: new google.maps.LatLng(36.778259, -98.417931), //LLANDRINDOD WELLS 15 center: new google.maps.LatLng(36.778259, -98.417931), //US center
16 zoom: 4, 16 zoom: 4,
17 mapTypeId: google.maps.MapTypeId.ROADMAP 17 mapTypeId: google.maps.MapTypeId.ROADMAP
18 }; 18 };
19 19
20 //getting fligts one time on instant pageload
21 getFlights();
20 map = new google.maps.Map(document.getElementById("map"), mapProp); 22 map = new google.maps.Map(document.getElementById("map"), mapProp);
21 console.log('sssssssss', json); 23 console.log('sssssssss', json);
22 24
23 setInterval(function(){ 25
24 $.get(json, function(json1) { 26
25 $.each(json1, function(key, data) { 27 var stopflight=$interval(function(){
26 var exists = false; 28 console.log('====interval start=======');
27 $.each(arr, function (index, value) { 29 //getting flights on each interval
28 if(value.title === data.id) { 30 getFlights();
29 var latLng = new google.maps.LatLng(data.latitude, data.longitude, data.altitude); 31 },4000);
30 value.link.setPosition(latLng); 32
31 exists = true; 33
32 } 34 /*---Stop flights in case state change---*/
33 }); 35 $scope.$on("$destroy",function(){
34 if(!exists) { 36 console.log('====live data stop-=====');
35 var latLng = new google.maps.LatLng(data.latitude, data.longitude, data.altitude); 37 if (angular.isDefined(stopflight)) {
36 38 $interval.cancel(stopflight);
37 var marker = new google.maps.Marker({ 39 }
38 position: latLng, 40 });
39 map: map, 41
40 icon: icon, 42 }
41 title: data.id 43
42 }); 44 /*---Get live flight data function---- */
43 45
44 var details = "Aircraft :" + " " + data.id + "<br> " + 46 var getFlights=function(){
45 "Path :" + " " + data.departurePoint + " " + "--->" + " " + data.arrivalPoint + "<br>" + 47 $.get(json, function(json1) {
46 "Altitude :" + " " + data.altitude + " " + "ft" + "<br>" + 48 $.each(json1, function(key, data) {
47 "Speed :" + " " + data.speed + " " + "Knots" + "<br>" + 49 var exists = false;
48 "Departure Time :" + " " + data.departureActualTime + " " + "(Actual)" + "<br>" + 50 $.each(arr, function (index, value) {
49 "Arrival Time :" + " " + data.arrivalEstimatedTime + " " + "(Estimated)" + "<br>"; 51 if(value.title === data.id) {
50 52 var latLng = new google.maps.LatLng(data.latitude, data.longitude, data.altitude);
51 arr.push({ 53 value.link.setPosition(latLng);
52 title: data.id, 54 exists = true;
53 link: marker, 55 }
54 details : details 56 });
55 }); 57 if(!exists) {
56 58 var latLng = new google.maps.LatLng(data.latitude, data.longitude, data.altitude);
57 bindInfoWindow(marker, map, infowindow, details, data); 59
58 } 60 var marker = new google.maps.Marker({
59 }); 61 position: latLng,
60 }); 62 map: map,
61 },5000); 63 icon: icon,
62 } 64 title: data.id
65 });
66
67 var details = "Aircraft :" + " " + data.id + "<br> " +
68 "Path :" + " " + data.departurePoint + " " + "--->" + " " + data.arrivalPoint + "<br>" +
69 "Altitude :" + " " + data.altitude + " " + "ft" + "<br>" +
70 "Speed :" + " " + data.speed + " " + "Knots" + "<br>" +
71 "Departure Time :" + " " + data.departureActualTime + " " + "(Actual)" + "<br>" +
72 "Arrival Time :" + " " + data.arrivalEstimatedTime + " " + "(Estimated)" + "<br>";
73
74 arr.push({
75 title: data.id,
76 link: marker,
77 details : details
78 });
79
80 bindInfoWindow(marker, map, infowindow, details, data);
81 }
82 });
83 });
84 }
85
86
63 87
64 function bindInfoWindow(marker, map, infowindow, strDescription, data) { 88 function bindInfoWindow(marker, map, infowindow, strDescription, data) {
65 google.maps.event.addListener(marker, 'click', function() { 89 google.maps.event.addListener(marker, 'click', function() {
66 $scope.flightInfo = data; 90 $scope.flightInfo = data;
67 //infowindow.setContent(strDescription); 91 //infowindow.setContent(strDescription);
68 //infowindow.open(map, marker); 92 //infowindow.open(map, marker);
69 $scope.flightInfo = data; 93 $scope.flightInfo = data;
70 $('#flightid').html($scope.flightInfo.id); 94 $('#flightid').html($scope.flightInfo.id);
71 $('#depid').html($scope.flightInfo.departurePoint); 95 $('#depid').html($scope.flightInfo.departurePoint);
72 $('#arrid').html($scope.flightInfo.arrivalPoint); 96 $('#arrid').html($scope.flightInfo.arrivalPoint);
73 $('#altid').html($scope.flightInfo.altitude); 97 $('#altid').html($scope.flightInfo.altitude);
74 $('#speedid').html($scope.flightInfo.speed); 98 $('#speedid').html($scope.flightInfo.speed);
75 $('#deptimeid').html($scope.flightInfo.departureActualTime); 99 $('#deptimeid').html($scope.flightInfo.departureActualTime);
76 $('#arrtimeid').html($scope.flightInfo.arrivalEstimatedTime); 100 $('#arrtimeid').html($scope.flightInfo.arrivalEstimatedTime);
77 101
78 $('.left-panel').animate({width: '300px', padding: '10px'}); 102 $('.left-panel').animate({width: '300px', padding: '10px'});
79 }); 103 });
80 } 104 }
81 105
82 $('.close-left-panel').click(function(){ 106 $('.close-left-panel').click(function(){
83 $('.left-panel').animate({width: '0', padding: '0'}); 107 $('.left-panel').animate({width: '0', padding: '0'});
84 }) 108 })
85 109
86 google.maps.event.addDomListener(document.getElementById("map"), 'load', $scope.initialise()); 110
111
112
113 google.maps.event.addDomListener(document.getElementById("map"), 'load', $scope.initialise());
87 114
88 115
89 116
90 117
91 118
92 119
93 120
94 121
95 }]); 122 }]);
96 123
97 124