Commit 562610b62d8a8348aceda0c25105f9cf2c16fc1a

Authored by Kuldeep Arora
1 parent f9e936a9de
Exists in master

angular interval and state change code

app/partials/flightTracking/flightTracking.controller.js
... ... @@ -2,7 +2,7 @@
2 2  
3 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 6 $scope.flightInfo = {};
7 7 var map;
8 8 var icon = "https://en.spitogatos.gr/visualCaptcha/images/airplane.png";
... ... @@ -12,54 +12,78 @@ angular.module('acufuel')
12 12  
13 13 $scope.initialise = function() {
14 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 16 zoom: 4,
17 17 mapTypeId: google.maps.MapTypeId.ROADMAP
18 18 };
19 19  
  20 + //getting fligts one time on instant pageload
  21 + getFlights();
20 22 map = new google.maps.Map(document.getElementById("map"), mapProp);
21 23 console.log('sssssssss', json);
22 24  
23   - setInterval(function(){
24   - $.get(json, function(json1) {
25   - $.each(json1, function(key, data) {
26   - var exists = false;
27   - $.each(arr, function (index, value) {
28   - if(value.title === data.id) {
29   - var latLng = new google.maps.LatLng(data.latitude, data.longitude, data.altitude);
30   - value.link.setPosition(latLng);
31   - exists = true;
32   - }
33   - });
34   - if(!exists) {
35   - var latLng = new google.maps.LatLng(data.latitude, data.longitude, data.altitude);
36   -
37   - var marker = new google.maps.Marker({
38   - position: latLng,
39   - map: map,
40   - icon: icon,
41   - title: data.id
42   - });
43   -
44   - var details = "Aircraft :" + " " + data.id + "<br> " +
45   - "Path :" + " " + data.departurePoint + " " + "--->" + " " + data.arrivalPoint + "<br>" +
46   - "Altitude :" + " " + data.altitude + " " + "ft" + "<br>" +
47   - "Speed :" + " " + data.speed + " " + "Knots" + "<br>" +
48   - "Departure Time :" + " " + data.departureActualTime + " " + "(Actual)" + "<br>" +
49   - "Arrival Time :" + " " + data.arrivalEstimatedTime + " " + "(Estimated)" + "<br>";
50   -
51   - arr.push({
52   - title: data.id,
53   - link: marker,
54   - details : details
55   - });
56   -
57   - bindInfoWindow(marker, map, infowindow, details, data);
58   - }
59   - });
60   - });
61   - },5000);
62   - }
  25 +
  26 +
  27 + var stopflight=$interval(function(){
  28 + console.log('====interval start=======');
  29 + //getting flights on each interval
  30 + getFlights();
  31 + },4000);
  32 +
  33 +
  34 + /*---Stop flights in case state change---*/
  35 + $scope.$on("$destroy",function(){
  36 + console.log('====live data stop-=====');
  37 + if (angular.isDefined(stopflight)) {
  38 + $interval.cancel(stopflight);
  39 + }
  40 +});
  41 +
  42 +}
  43 +
  44 + /*---Get live flight data function---- */
  45 +
  46 + var getFlights=function(){
  47 + $.get(json, function(json1) {
  48 + $.each(json1, function(key, data) {
  49 + var exists = false;
  50 + $.each(arr, function (index, value) {
  51 + if(value.title === data.id) {
  52 + var latLng = new google.maps.LatLng(data.latitude, data.longitude, data.altitude);
  53 + value.link.setPosition(latLng);
  54 + exists = true;
  55 + }
  56 + });
  57 + if(!exists) {
  58 + var latLng = new google.maps.LatLng(data.latitude, data.longitude, data.altitude);
  59 +
  60 + var marker = new google.maps.Marker({
  61 + position: latLng,
  62 + map: map,
  63 + icon: icon,
  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 88 function bindInfoWindow(marker, map, infowindow, strDescription, data) {
65 89 google.maps.event.addListener(marker, 'click', function() {
... ... @@ -83,7 +107,10 @@ angular.module(&#39;acufuel&#39;)
83 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  
... ...