Browse Source

Reformatted

Stephen Downward 2 years ago
parent
commit
04292d91fe
4 changed files with 302 additions and 302 deletions
  1. 26 26
      css/style.css
  2. 79 79
      index.html
  3. 85 85
      js/calc.js
  4. 112 112
      js/main.js

+ 26 - 26
css/style.css

@ -1,32 +1,32 @@
1 1
html, body {
2
  height: 100%;
3
  width: 100%;
2
    height: 100%;
3
    width: 100%;
4 4
}
5 5
6 6
#container {
7
  display: flex;
8
  height: 100%;
9
  overflow-y: hidden;
7
    display: flex;
8
    height: 100%;
9
    overflow-y: hidden;
10 10
}
11 11
12 12
#controls {
13
  float: left;
14
  overflow-y: scroll;
15
  height: 100%;
13
    float: left;
14
    overflow-y: scroll;
15
    height: 100%;
16 16
}
17 17
18 18
#map {
19
  width: 100%;
20
  min-width: 250px;
21
  height: 100%;
22
  background-color: grey;
23
  flex-grow: 1;
19
    width: 100%;
20
    min-width: 250px;
21
    height: 100%;
22
    background-color: grey;
23
    flex-grow: 1;
24 24
}
25 25
26 26
#rightNav {
27
  width: calc(100% - 450px);
28
  width: -moz-calc(100% - 450px);
29
  width: calc(100% - 450px);
27
    width: calc(100% - 450px);
28
    width: -moz-calc(100% - 450px);
29
    width: calc(100% - 450px);
30 30
}
31 31
32 32
#footer {
@ -36,25 +36,25 @@ html, body {
36 36
}
37 37
38 38
#config {
39
  white-space: normal;
40
  word-break:break-all;
41
  width: 100%;
42
  height: 100%;
43
  overflow-y: auto;
39
    white-space: normal;
40
    word-break:break-all;
41
    width: 100%;
42
    height: 100%;
43
    overflow-y: auto;
44 44
}
45 45
46 46
#satlist {
47
  -webkit-column-width: 210px;
48
  -moz-column-width: 210px;
49
  column-width: 210px;
47
    -webkit-column-width: 210px;
48
    -moz-column-width: 210px;
49
    column-width: 210px;
50 50
}
51 51
52 52
input[type=number] {
53
  width: 40px;
53
    width: 40px;
54 54
}
55 55
56 56
table tr td {
57
  padding: 3px;
57
    padding: 3px;
58 58
}
59 59
60 60
.glyphicon.spinning {

+ 79 - 79
index.html

@ -1,5 +1,5 @@
1 1
<html ng-app="satTrackApp">
2
  <head>
2
<head>
3 3
    <title>Multipoint Satellite Tracker</title>
4 4
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
5 5
    <link rel="stylesheet" type="text/css" href="css/style.css">
@ -12,82 +12,82 @@
12 12
    <script src="js/moment.min.js"></script>
13 13
    <script src="js/satellite.min.js"></script>
14 14
    <script type="text/javascript" src="js/main.js"></script>
15
  </head>
16
  <body>
15
</head>
16
<body>
17 17
    <div id="container" ng-controller="satTrack-ctrl">
18
      <div id="controls">
19
        <center>
20
          <table border="1" ng-show="places.length > 0">
21
            <tr>
22
              <td><b>ID</b></td>
23
              <td><b>Latitude</b></td>
24
              <td><b>Longitude</b></td>
25
              <td><b>Minimum AoA</b></td>
26
              <td></td>
27
            </tr>
28
            <tr ng-repeat="point in places">
29
              <td>{{$index + 1}}</td>
30
              <td>{{point.marker.position.lat().toFixed(6)}}</td>
31
              <td>{{point.marker.position.lng().toFixed(6)}}</td>
32
              <td><input type="number" min="0" max="90" ng-model="point.angle"> deg</td>
33
              <td><button type="button" class="btn btn-danger" ng-click="removePoint($index)">Remove</button></td>
34
            </tr>
35
          </table>
36
          <div style="margin: 6px">
37
            Click on the map to add a point<br>
38
            Time zone: {{getTimezone()}}
39
          </div><BR><BR>
40
          From <input type="text" id="fromDate" style="width: 90px;">
41
          to <input type="text" id="toDate" style="width: 90px;"><br><br>
42
          <button type="button" class="btn btn-success" ng-disabled="places.length == 0" ng-click="getPasses()">Calculate Passes</button>
43
          <span class='glyphicon-left glyphicon glyphicon-refresh spinning' ng-show='isGettingPasses'></span>
44
        </center><BR>
45
        <table border="1">
46
          <tr>
47
            <td><b>Date</b></td>
48
            <td><b>Sat name</b></td>
49
            <td><b>Start time</b></td>
50
            <td><b>Max AoAs</b></td>
51
            <td><b>End time</b></td>
52
            <td><b>Total time of contact</b></td>
53
          </tr>
54
          <tr ng-repeat="pass in passes">
55
            <td>{{getDate(pass.time_start)}}</td>
56
            <td>{{pass.name}}</td>
57
            <td>{{getTime(pass.time_start)}}</td>
58
            <td style="white-space: nowrap;"><div ng-repeat="stat in pass.pointStats">
59
              Point {{$index + 1}}: {{stat.maxElv.toFixed(0)}} deg @ {{getTime(stat.timeMaxElv)}}
60
            </div></td>
61
            <td>{{getTime(pass.time_end)}}</td>
62
            <td>{{getDifferenceInMinutes(pass.time_end, pass.time_start)}}</td>
63
          </tr>
64
        </table><br>
65
        <div id="footer">
66
          <center>
67
            Developed by Stephen Downward, callsign VA1QLE.<br>
68
            <a href="https://git.scd31.com/laptopdude90/multipoint-satellite-tracker">Git repository</a><br><br>
69
          </center>
70
        </div>
71
      </div>
72
      <div id="rightNav">
73
        <div id="tabs">
74
          <ul class="nav nav-tabs">
75
            <li class="{{(selectedTab == 'map') ? 'active':''}}"><a href ng-click="selectedTab = 'map'">Map</a></li>
76
            <li class="{{(selectedTab == 'config') ? 'active':''}}"><a href ng-click="selectedTab = 'config'">Configure satellites</a></li>
77
          </ul>
78
        </div>
79
        <div id="map" ng-show="selectedTab == 'map'">
80
          <ng-map center="39.82, -77.01" zoom="4" style="height:100%"></ng-map>
81
        </div>
82
        <div id="config" ng-show="selectedTab == 'config'">
83
          <center>
84
            Select all/none <input type="checkbox" ng-model="selectAllSats" ng-change="toggleEnabled(selectAllSats)"><br><br>
85
          </center>
86
          <div id="satlist">
87
            <div ng-repeat="sat in satellites" style="white-space: nowrap;"><input type="checkbox" ng-model="sat.enabled">&emsp;{{sat.name}}</div>
88
          </div>
89
        </div>
90
      </div>
91
    </div>
92
  </body>
93
</html>
18
        <div id="controls">
19
            <center>
20
                <table border="1" ng-show="places.length > 0">
21
                    <tr>
22
                        <td><b>ID</b></td>
23
                        <td><b>Latitude</b></td>
24
                        <td><b>Longitude</b></td>
25
                        <td><b>Minimum AoA</b></td>
26
                        <td></td>
27
                    </tr>
28
                    <tr ng-repeat="point in places">
29
                        <td>{{$index + 1}}</td>
30
                        <td>{{point.marker.position.lat().toFixed(6)}}</td>
31
                        <td>{{point.marker.position.lng().toFixed(6)}}</td>
32
                        <td><input type="number" min="0" max="90" ng-model="point.angle"> deg</td>
33
                        <td><button type="button" class="btn btn-danger" ng-click="removePoint($index)">Remove</button></td>
34
                    </tr>
35
                </table>
36
                <div style="margin: 6px">
37
                    Click on the map to add a point<br>
38
                    Time zone: {{getTimezone()}}
39
                </div><BR><BR>
40
                    From <input type="text" id="fromDate" style="width: 90px;">
41
                    to <input type="text" id="toDate" style="width: 90px;"><br><br>
42
                    <button type="button" class="btn btn-success" ng-disabled="places.length == 0" ng-click="getPasses()">Calculate Passes</button>
43
                    <span class='glyphicon-left glyphicon glyphicon-refresh spinning' ng-show='isGettingPasses'></span>
44
                </center><BR>
45
                    <table border="1">
46
                        <tr>
47
                            <td><b>Date</b></td>
48
                            <td><b>Sat name</b></td>
49
                            <td><b>Start time</b></td>
50
                            <td><b>Max AoAs</b></td>
51
                            <td><b>End time</b></td>
52
                            <td><b>Total time of contact</b></td>
53
                        </tr>
54
                        <tr ng-repeat="pass in passes">
55
                            <td>{{getDate(pass.time_start)}}</td>
56
                            <td>{{pass.name}}</td>
57
                            <td>{{getTime(pass.time_start)}}</td>
58
                            <td style="white-space: nowrap;"><div ng-repeat="stat in pass.pointStats">
59
                                Point {{$index + 1}}: {{stat.maxElv.toFixed(0)}} deg @ {{getTime(stat.timeMaxElv)}}
60
                            </div></td>
61
                            <td>{{getTime(pass.time_end)}}</td>
62
                            <td>{{getDifferenceInMinutes(pass.time_end, pass.time_start)}}</td>
63
                        </tr>
64
                    </table><br>
65
                    <div id="footer">
66
                        <center>
67
                            Developed by Stephen Downward, callsign VA1QLE.<br>
68
                            <a href="https://git.scd31.com/laptopdude90/multipoint-satellite-tracker">Git repository</a><br><br>
69
                        </center>
70
                    </div>
71
                </div>
72
                <div id="rightNav">
73
                    <div id="tabs">
74
                        <ul class="nav nav-tabs">
75
                            <li class="{{(selectedTab == 'map') ? 'active':''}}"><a href ng-click="selectedTab = 'map'">Map</a></li>
76
                            <li class="{{(selectedTab == 'config') ? 'active':''}}"><a href ng-click="selectedTab = 'config'">Configure satellites</a></li>
77
                        </ul>
78
                    </div>
79
                    <div id="map" ng-show="selectedTab == 'map'">
80
                        <ng-map center="39.82, -77.01" zoom="4" style="height:100%"></ng-map>
81
                    </div>
82
                    <div id="config" ng-show="selectedTab == 'config'">
83
                        <center>
84
                            Select all/none <input type="checkbox" ng-model="selectAllSats" ng-change="toggleEnabled(selectAllSats)"><br><br>
85
                        </center>
86
                        <div id="satlist">
87
                            <div ng-repeat="sat in satellites" style="white-space: nowrap;"><input type="checkbox" ng-model="sat.enabled">&emsp;{{sat.name}}</div>
88
                        </div>
89
                    </div>
90
                </div>
91
            </div>
92
        </body>
93
        </html>

+ 85 - 85
js/calc.js

@ -1,101 +1,101 @@
1 1
importScripts('satellite.min.js');
2 2
3 3
self.addEventListener('message', function(e) {
4
  //The data returned from calcSats isn't fit for displaying,
5
  //as it is arranged into groups by satallite. Below fixes that
6
7
  //Make new array equal to all the old array.passes
8
  var passes = calcSatellites(e.data.coords, e.data.satellites, e.data.fromDate, e.data.toDuration).map(function(a) {
9
    //Add satellite names to each pass
10
    a.passes.map(function(b) {
11
      b.name = a.name;
12
      return b;
4
    //The data returned from calcSats isn't fit for displaying,
5
    //as it is arranged into groups by satallite. Below fixes that
6
7
    //Make new array equal to all the old array.passes
8
    var passes = calcSatellites(e.data.coords, e.data.satellites, e.data.fromDate, e.data.toDuration).map(function(a) {
9
        //Add satellite names to each pass
10
        a.passes.map(function(b) {
11
            b.name = a.name;
12
            return b;
13
        });
14
        return a.passes;
13 15
    });
14
    return a.passes;
15
  });
16
  passes = flatten(passes);
17
18
  //Sort by time_start
19
  passes.sort(function(a,b) {
20
    return a.time_start - b.time_start;
21
  });
22
  self.postMessage(passes);
16
    passes = flatten(passes);
17
18
    //Sort by time_start
19
    passes.sort(function(a,b) {
20
        return a.time_start - b.time_start;
21
    });
22
    self.postMessage(passes);
23 23
}, false);
24 24
25 25
function flatten(arr) {
26
  return arr.reduce(function (flat, toFlatten) {
27
    return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
28
  }, []);
26
    return arr.reduce(function (flat, toFlatten) {
27
        return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
28
    }, []);
29 29
}
30 30
31 31
function calcSatellites(ground_coords, satellites, from, duration) {
32 32
33
  //Convert coords to radians
34
  var ground_coords_rad = [];
35
  for(var i = 0; i < ground_coords.length; i++) { //Coords
36
    var radian_coords = {
37
      latitude: ground_coords[i].lat * Math.PI / 180,
38
      longitude: ground_coords[i].lng *  Math.PI / 180,
39
      height: ground_coords[i].height};
40
      ground_coords_rad.push(radian_coords);
41
  }
42
43
  var viableSats = [];
44
45
  for(var i = 0; i < satellites.length; i++) { //Satellites
46
    if(satellites[i].enabled && satellites[i].satrec.error === 0) {
47
      var passes = [];
48
49
      var time_start = 0;
50
      var pointStats = [];
51
52
      for(var secondsFrom = 0; secondsFrom < duration; secondsFrom += 30) { //Time incremental
53
        var timeToProgressTo = new Date(from.getTime() + (secondsFrom * 1000));
54
        //console.log(satellites[i].satrec.error);
55
        var viableTime = true;
56
57
        for(var j = 0; j < ground_coords_rad.length; j++) { //Coordinates
58
          var g_coords = ground_coords_rad[j];
59
          var posAndVel = satellite.propagate(satellites[i].satrec, timeToProgressTo);
60
          if(posAndVel.position != false && posAndVel.position != null) {
61
62
            var lookAngles = satellite.ecfToLookAngles(g_coords, satellite.eciToEcf(posAndVel.position, satellite.gstimeFromDate(timeToProgressTo)));
63
            var elevationDeg = lookAngles.elevation * 180 / Math.PI;
64
65
            //Define pointStats[j]
66
            if(!pointStats[j]) pointStats[j] = {maxElv: 0, timeMaxElv: 0};
67
68
            if(elevationDeg > pointStats[j].maxElv && elevationDeg > ground_coords[j].angle) { //Has to be during a pass
69
              pointStats[j].maxElv = elevationDeg;
70
              pointStats[j].timeMaxElv = timeToProgressTo;
71
            }
33
    //Convert coords to radians
34
    var ground_coords_rad = [];
35
    for(var i = 0; i < ground_coords.length; i++) { //Coords
36
        var radian_coords = {
37
            latitude: ground_coords[i].lat * Math.PI / 180,
38
            longitude: ground_coords[i].lng *  Math.PI / 180,
39
            height: ground_coords[i].height};
40
            ground_coords_rad.push(radian_coords);
41
        }
72 42
73
            if(elevationDeg < ground_coords[j].angle) {
74
              viableTime = false;
75
              if(time_start != 0) {
76
                //Push pass to array and reset for next pass
77
                passes.push({
78
                  time_start: time_start,
79
                  pointStats: pointStats,
80
                  time_end: timeToProgressTo
43
        var viableSats = [];
44
45
        for(var i = 0; i < satellites.length; i++) { //Satellites
46
            if(satellites[i].enabled && satellites[i].satrec.error === 0) {
47
                var passes = [];
48
49
                var time_start = 0;
50
                var pointStats = [];
51
52
                for(var secondsFrom = 0; secondsFrom < duration; secondsFrom += 30) { //Time incremental
53
                    var timeToProgressTo = new Date(from.getTime() + (secondsFrom * 1000));
54
                    //console.log(satellites[i].satrec.error);
55
                    var viableTime = true;
56
57
                    for(var j = 0; j < ground_coords_rad.length; j++) { //Coordinates
58
                        var g_coords = ground_coords_rad[j];
59
                        var posAndVel = satellite.propagate(satellites[i].satrec, timeToProgressTo);
60
                        if(posAndVel.position != false && posAndVel.position != null) {
61
62
                            var lookAngles = satellite.ecfToLookAngles(g_coords, satellite.eciToEcf(posAndVel.position, satellite.gstimeFromDate(timeToProgressTo)));
63
                            var elevationDeg = lookAngles.elevation * 180 / Math.PI;
64
65
                            //Define pointStats[j]
66
                            if(!pointStats[j]) pointStats[j] = {maxElv: 0, timeMaxElv: 0};
67
68
                            if(elevationDeg > pointStats[j].maxElv && elevationDeg > ground_coords[j].angle) { //Has to be during a pass
69
                                pointStats[j].maxElv = elevationDeg;
70
                                pointStats[j].timeMaxElv = timeToProgressTo;
71
                            }
72
73
                            if(elevationDeg < ground_coords[j].angle) {
74
                                viableTime = false;
75
                                if(time_start != 0) {
76
                                    //Push pass to array and reset for next pass
77
                                    passes.push({
78
                                        time_start: time_start,
79
                                        pointStats: pointStats,
80
                                        time_end: timeToProgressTo
81
                                    });
82
                                    time_start = 0;
83
                                    pointStats = [];
84
                                }
85
86
                                break;
87
                            }
88
                        }
89
                    }
90
                    if(viableTime) {
91
                        if(time_start == 0) time_start = timeToProgressTo;
92
                    }
93
                }
94
                viableSats.push({
95
                    name: satellites[i].name,
96
                    passes: passes
81 97
                });
82
                time_start = 0;
83
                pointStats = [];
84
              }
85
86
              break;
87 98
            }
88
          }
89
        }
90
        if(viableTime) {
91
          if(time_start == 0) time_start = timeToProgressTo;
92 99
        }
93
      }
94
      viableSats.push({
95
        name: satellites[i].name,
96
        passes: passes
97
      });
100
        return viableSats;
98 101
    }
99
  }
100
  return viableSats;
101
}

+ 112 - 112
js/main.js

@ -1,139 +1,139 @@
1 1
$(function () {
2
  var now = new Date();
3
  var then = new Date();
4
  then.setDate(now.getDate() + 7);
5
  $("#fromDate").datepicker().datepicker("setDate", now);
6
  $("#toDate").datepicker().datepicker("setDate", then);
2
    var now = new Date();
3
    var then = new Date();
4
    then.setDate(now.getDate() + 7);
5
    $("#fromDate").datepicker().datepicker("setDate", now);
6
    $("#toDate").datepicker().datepicker("setDate", then);
7 7
});
8 8
9 9
var app = angular.module('satTrackApp', ['ngMap']);
10 10
11 11
app.controller('satTrack-ctrl', function($scope, NgMap) {
12
  $scope.places = [];
13
  $scope.passes = [];
14
  $scope.isGettingPasses = false;
15
  $scope.selectedTab = 'map';
16
  $scope.satellites = [];
17
  $scope.selectAllSats = true;
18
19
  loadSatelliteData(function(satList) {
20
    $scope.satellites = satList;
21
  });
22
23
  var elevator;
24
25
  $scope.removePoint = function(id) {
26
    $scope.places[id].marker.setMap(null);
27
    $scope.places[id].marker = null;
28
    $scope.places.splice(id, 1);
29
    for(var i = 0; i < $scope.places.length; i++) {
30
      $scope.places[i].marker.setLabel((i + 1).toString());
12
    $scope.places = [];
13
    $scope.passes = [];
14
    $scope.isGettingPasses = false;
15
    $scope.selectedTab = 'map';
16
    $scope.satellites = [];
17
    $scope.selectAllSats = true;
18
19
    loadSatelliteData(function(satList) {
20
        $scope.satellites = satList;
21
    });
22
23
    var elevator;
24
25
    $scope.removePoint = function(id) {
26
        $scope.places[id].marker.setMap(null);
27
        $scope.places[id].marker = null;
28
        $scope.places.splice(id, 1);
29
        for(var i = 0; i < $scope.places.length; i++) {
30
            $scope.places[i].marker.setLabel((i + 1).toString());
31
        }
31 32
    }
32
  }
33 33
34
  NgMap.getMap().then(function(map) {
34
    NgMap.getMap().then(function(map) {
35 35
36
    google.maps.event.addListener(map, 'click', function(event) {
37
      var marker = new google.maps.Marker({
38
          position: event.latLng,
39
          map: map,
40
          label: ($scope.places.length + 1).toString(),
41
          draggable: true
42
      });
36
        google.maps.event.addListener(map, 'click', function(event) {
37
            var marker = new google.maps.Marker({
38
                position: event.latLng,
39
                map: map,
40
                label: ($scope.places.length + 1).toString(),
41
                draggable: true
42
            });
43 43
44
      elevator = new google.maps.ElevationService;
44
            elevator = new google.maps.ElevationService;
45 45
46
      google.maps.event.addListener(marker, 'dragend', function () {
47
        $scope.$apply();
48
      });
46
            google.maps.event.addListener(marker, 'dragend', function () {
47
                $scope.$apply();
48
            });
49 49
50
      $scope.places.push({marker: marker, angle: 10});
51
      $scope.$apply();
50
            $scope.places.push({marker: marker, angle: 10});
51
            $scope.$apply();
52
        });
52 53
    });
53
  });
54
55
  $scope.getPasses = function() {
56
    $scope.isGettingPasses = true;
57
    callsRemaining = $scope.places.length;
58
    for(var i = 0; i < $scope.places.length; i++) {
59
      let place = $scope.places[i];
60
      elevator.getElevationForLocations({locations: [$scope.places[i].marker.position]}, function(results, status) {
61
        if(status === 'OK' && results[0]) {
62
          place.height = Math.max(results[0].elevation / 1000, 0);
63
          callsRemaining--;
64
          if(callsRemaining <= 0) sendCoords();
65
        } else {
66
          alert('Something went very wrong');
54
55
    $scope.getPasses = function() {
56
        $scope.isGettingPasses = true;
57
        callsRemaining = $scope.places.length;
58
        for(var i = 0; i < $scope.places.length; i++) {
59
            let place = $scope.places[i];
60
            elevator.getElevationForLocations({locations: [$scope.places[i].marker.position]}, function(results, status) {
61
                if(status === 'OK' && results[0]) {
62
                    place.height = Math.max(results[0].elevation / 1000, 0);
63
                    callsRemaining--;
64
                    if(callsRemaining <= 0) sendCoords();
65
                } else {
66
                    alert('Something went very wrong');
67
                }
68
            });
69
        }
70
        var sendCoords = function() {
71
            var coords = $scope.places.map(function(a) {
72
                return {
73
                    lat: a.marker.position.lat(),
74
                    lng: a.marker.position.lng(),
75
                    height: a.height,
76
                    angle: a.angle
77
                };
78
            });
79
80
            var worker = new Worker('js/calc.js');
81
            worker.addEventListener('message', function(e) {
82
83
                $scope.passes = e.data;
84
                $scope.isGettingPasses = false;
85
                $scope.$apply();
86
            }, false);
87
            var fromDate = $("#fromDate").datepicker('getDate');
88
            var toDate = $("#toDate").datepicker('getDate');
89
            var duration = Math.abs(moment(toDate).diff(fromDate) / 1000) + 86400;
90
            worker.postMessage({coords: coords, satellites: $scope.satellites, fromDate: minDate(fromDate, toDate), toDuration: duration});
67 91
        }
68
      });
69 92
    }
70
    var sendCoords = function() {
71
      var coords = $scope.places.map(function(a) {
72
        return {
73
          lat: a.marker.position.lat(),
74
          lng: a.marker.position.lng(),
75
          height: a.height,
76
          angle: a.angle
77
        };
78
      });
79
80
      var worker = new Worker('js/calc.js');
81
      worker.addEventListener('message', function(e) {
82
83
        $scope.passes = e.data;
84
        $scope.isGettingPasses = false;
85
        $scope.$apply();
86
      }, false);
87
      var fromDate = $("#fromDate").datepicker('getDate');
88
      var toDate = $("#toDate").datepicker('getDate');
89
      var duration = Math.abs(moment(toDate).diff(fromDate) / 1000) + 86400;
90
      worker.postMessage({coords: coords, satellites: $scope.satellites, fromDate: minDate(fromDate, toDate), toDuration: duration});
93
94
    $scope.getDate = function(date) {
95
        //console.log(date);
96
        return moment(date).format("MMM D");
91 97
    }
92
  }
93
94
  $scope.getDate = function(date) {
95
    //console.log(date);
96
    return moment(date).format("MMM D");
97
  }
98
99
  $scope.getTime = function(date) {
100
    return moment(date).format("HH:mm:ss");
101
  }
102
103
  $scope.getDifferenceInMinutes = function(a, b) {
104
    var d = moment.duration(moment(a).diff(moment(b)));
105
    return (d / 60000) + " minutes";
106
  }
107
108
  $scope.getTimezone = function() {
109
    offset = new Date().getTimezoneOffset();
110
    halfHour = offset % 60;
111
    halfHourStr = halfHour > 9 ? "" + halfHour : "0" + halfHour;
112
    return "GMT" + (offset > 0 ? "-" : "+") + Math.floor(offset / 60) + halfHourStr;
113
  }
114
115
  $scope.toggleEnabled = function(val) {
116
    for(var i = 0; i < $scope.satellites.length; i++) {
117
      $scope.satellites[i].enabled = val;
98
99
    $scope.getTime = function(date) {
100
        return moment(date).format("HH:mm:ss");
101
    }
102
103
    $scope.getDifferenceInMinutes = function(a, b) {
104
        var d = moment.duration(moment(a).diff(moment(b)));
105
        return (d / 60000) + " minutes";
106
    }
107
108
    $scope.getTimezone = function() {
109
        offset = new Date().getTimezoneOffset();
110
        halfHour = offset % 60;
111
        halfHourStr = halfHour > 9 ? "" + halfHour : "0" + halfHour;
112
        return "GMT" + (offset > 0 ? "-" : "+") + Math.floor(offset / 60) + halfHourStr;
113
    }
114
115
    $scope.toggleEnabled = function(val) {
116
        for(var i = 0; i < $scope.satellites.length; i++) {
117
            $scope.satellites[i].enabled = val;
118
        }
118 119
    }
119
  }
120 120
});
121 121
122 122
function loadSatelliteData(callback) {
123 123
    $.get("nasabare.txt", function(data) {
124
      var splitLines = data.split(/\r?\n/);
125
      var satellites = []
126
      for(var i = 0; i < splitLines.length; i += 3) { //3 lines per satellite, so advance by 1 satellite each time
127
        if(splitLines[i] != '') {
128
          var sat = satellite.twoline2satrec(splitLines[i + 1], splitLines[i + 2]);
129
          var name = splitLines[i];
130
          satellites.push({name: name, satrec: sat, enabled: true});
124
        var splitLines = data.split(/\r?\n/);
125
        var satellites = []
126
        for(var i = 0; i < splitLines.length; i += 3) { //3 lines per satellite, so advance by 1 satellite each time
127
            if(splitLines[i] != '') {
128
                var sat = satellite.twoline2satrec(splitLines[i + 1], splitLines[i + 2]);
129
                var name = splitLines[i];
130
                satellites.push({name: name, satrec: sat, enabled: true});
131
            }
131 132
        }
132
      }
133
      callback(satellites);
133
        callback(satellites);
134 134
    });
135 135
}
136 136
137 137
function minDate(date1, date2) {
138
  return date1 < date2 ? date1 : date2;
138
    return date1 < date2 ? date1 : date2;
139 139
}