|
|
@ -1,139 +1,171 @@ |
|
|
|
$(function () { |
|
|
|
var now = new Date(); |
|
|
|
var then = new Date(); |
|
|
|
then.setDate(now.getDate() + 7); |
|
|
|
$("#fromDate").datepicker().datepicker("setDate", now); |
|
|
|
$("#toDate").datepicker().datepicker("setDate", then); |
|
|
|
var now = new Date(); |
|
|
|
var then = new Date(); |
|
|
|
then.setDate(now.getDate() + 7); |
|
|
|
$("#fromDate").datepicker().datepicker("setDate", now); |
|
|
|
$("#toDate").datepicker().datepicker("setDate", then); |
|
|
|
}); |
|
|
|
|
|
|
|
var app = angular.module('satTrackApp', ['ngMap']); |
|
|
|
|
|
|
|
app.controller('satTrack-ctrl', function($scope, NgMap) { |
|
|
|
$scope.places = []; |
|
|
|
$scope.passes = []; |
|
|
|
$scope.isGettingPasses = false; |
|
|
|
$scope.selectedTab = 'map'; |
|
|
|
$scope.satellites = []; |
|
|
|
$scope.selectAllSats = true; |
|
|
|
|
|
|
|
loadSatelliteData(function(satList) { |
|
|
|
$scope.satellites = satList; |
|
|
|
}); |
|
|
|
|
|
|
|
var elevator; |
|
|
|
|
|
|
|
$scope.removePoint = function(id) { |
|
|
|
$scope.places[id].marker.setMap(null); |
|
|
|
$scope.places[id].marker = null; |
|
|
|
$scope.places.splice(id, 1); |
|
|
|
for(var i = 0; i < $scope.places.length; i++) { |
|
|
|
$scope.places[i].marker.setLabel((i + 1).toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
NgMap.getMap().then(function(map) { |
|
|
|
|
|
|
|
google.maps.event.addListener(map, 'click', function(event) { |
|
|
|
var marker = new google.maps.Marker({ |
|
|
|
position: event.latLng, |
|
|
|
map: map, |
|
|
|
label: ($scope.places.length + 1).toString(), |
|
|
|
draggable: true |
|
|
|
}); |
|
|
|
|
|
|
|
elevator = new google.maps.ElevationService; |
|
|
|
|
|
|
|
google.maps.event.addListener(marker, 'dragend', function () { |
|
|
|
$scope.$apply(); |
|
|
|
}); |
|
|
|
|
|
|
|
$scope.places.push({marker: marker, angle: 10}); |
|
|
|
$scope.$apply(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
$scope.getPasses = function() { |
|
|
|
$scope.isGettingPasses = true; |
|
|
|
callsRemaining = $scope.places.length; |
|
|
|
for(var i = 0; i < $scope.places.length; i++) { |
|
|
|
let place = $scope.places[i]; |
|
|
|
elevator.getElevationForLocations({locations: [$scope.places[i].marker.position]}, function(results, status) { |
|
|
|
if(status === 'OK' && results[0]) { |
|
|
|
place.height = Math.max(results[0].elevation / 1000, 0); |
|
|
|
callsRemaining--; |
|
|
|
if(callsRemaining <= 0) sendCoords(); |
|
|
|
} else { |
|
|
|
alert('Something went very wrong'); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
var sendCoords = function() { |
|
|
|
var coords = $scope.places.map(function(a) { |
|
|
|
return { |
|
|
|
lat: a.marker.position.lat(), |
|
|
|
lng: a.marker.position.lng(), |
|
|
|
height: a.height, |
|
|
|
angle: a.angle |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
var worker = new Worker('js/calc.js'); |
|
|
|
worker.addEventListener('message', function(e) { |
|
|
|
|
|
|
|
$scope.passes = e.data; |
|
|
|
$scope.isGettingPasses = false; |
|
|
|
$scope.$apply(); |
|
|
|
}, false); |
|
|
|
var fromDate = $("#fromDate").datepicker('getDate'); |
|
|
|
var toDate = $("#toDate").datepicker('getDate'); |
|
|
|
var duration = Math.abs(moment(toDate).diff(fromDate) / 1000) + 86400; |
|
|
|
worker.postMessage({coords: coords, satellites: $scope.satellites, fromDate: minDate(fromDate, toDate), toDuration: duration}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$scope.getDate = function(date) { |
|
|
|
//console.log(date);
|
|
|
|
return moment(date).format("MMM D"); |
|
|
|
} |
|
|
|
|
|
|
|
$scope.getTime = function(date) { |
|
|
|
return moment(date).format("HH:mm:ss"); |
|
|
|
} |
|
|
|
|
|
|
|
$scope.getDifferenceInMinutes = function(a, b) { |
|
|
|
var d = moment.duration(moment(a).diff(moment(b))); |
|
|
|
return (d / 60000) + " minutes"; |
|
|
|
} |
|
|
|
|
|
|
|
$scope.getTimezone = function() { |
|
|
|
offset = new Date().getTimezoneOffset(); |
|
|
|
halfHour = offset % 60; |
|
|
|
halfHourStr = halfHour > 9 ? "" + halfHour : "0" + halfHour; |
|
|
|
return "GMT" + (offset > 0 ? "-" : "+") + Math.floor(offset / 60) + halfHourStr; |
|
|
|
} |
|
|
|
|
|
|
|
$scope.toggleEnabled = function(val) { |
|
|
|
for(var i = 0; i < $scope.satellites.length; i++) { |
|
|
|
$scope.satellites[i].enabled = val; |
|
|
|
} |
|
|
|
} |
|
|
|
var app = angular.module('satTrackApp',[] /*, ['ngMap']*/); |
|
|
|
|
|
|
|
app.controller('satTrack-ctrl', function($scope) { |
|
|
|
$scope.places = []; |
|
|
|
$scope.passes = []; |
|
|
|
$scope.isGettingPasses = false; |
|
|
|
$scope.selectedTab = 'map'; |
|
|
|
$scope.satellites = []; |
|
|
|
$scope.selectAllSats = true; |
|
|
|
|
|
|
|
loadSatelliteData(function(satList) { |
|
|
|
$scope.satellites = satList; |
|
|
|
}); |
|
|
|
|
|
|
|
//Init leaflet map
|
|
|
|
var lmap = L.map('lmap').setView([39.82, -77.01], 4); |
|
|
|
|
|
|
|
L.tileLayer('https://a.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
|
|
|
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>', |
|
|
|
maxZoom: 20, |
|
|
|
//id: 'mapbox.streets',
|
|
|
|
//accessToken: 'your.mapbox.access.token'
|
|
|
|
}).addTo(lmap); |
|
|
|
|
|
|
|
//var elevator;
|
|
|
|
|
|
|
|
$scope.removePoint = function(id) { |
|
|
|
lmap.removeLayer($scope.places[id].marker); |
|
|
|
$scope.places[id].marker = null; |
|
|
|
$scope.places.splice(id, 1); |
|
|
|
for(var i = 0; i < $scope.places.length; i++) { |
|
|
|
$scope.places[i].marker.setLabel((i + 1).toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function onMapClick(map) |
|
|
|
{ |
|
|
|
var marker = new L.marker(map.latlng, {draggable: 'true'}).addTo(lmap); |
|
|
|
|
|
|
|
marker.on('dragend', function(e) { |
|
|
|
$scope.$apply(); |
|
|
|
}); |
|
|
|
marker.bindTooltip(($scope.places.length + 1).toString()).openTooltip(); |
|
|
|
$scope.places.push({marker: marker, angle:10}); |
|
|
|
$scope.$apply(); |
|
|
|
} |
|
|
|
|
|
|
|
lmap.on('click', onMapClick); |
|
|
|
/*NgMap.getMap().then(function(map) { |
|
|
|
|
|
|
|
google.maps.event.addListener(map, 'click', function(event) { |
|
|
|
var marker = new google.maps.Marker({ |
|
|
|
position: event.latLng, |
|
|
|
map: map, |
|
|
|
label: ($scope.places.length + 1).toString(), |
|
|
|
draggable: true |
|
|
|
}); |
|
|
|
|
|
|
|
elevator = new google.maps.ElevationService; |
|
|
|
|
|
|
|
google.maps.event.addListener(marker, 'dragend', function () { |
|
|
|
$scope.$apply(); |
|
|
|
}); |
|
|
|
|
|
|
|
$scope.places.push({marker: marker, angle: 10}); |
|
|
|
$scope.$apply(); |
|
|
|
}); |
|
|
|
});*/ |
|
|
|
|
|
|
|
$scope.getPasses = function() { |
|
|
|
$scope.isGettingPasses = true; |
|
|
|
//callsRemaining = $scope.places.length;
|
|
|
|
|
|
|
|
//Get elevations
|
|
|
|
for(var i = 0; i < $scope.places.length; i++) { |
|
|
|
let place = $scope.places[i]; |
|
|
|
place.height = 10; /* ------------TODO-------------- */ |
|
|
|
/*elevator.getElevationForLocations({locations: [$scope.places[i].marker.position]}, function(results, status) { |
|
|
|
if(status === 'OK' && results[0]) { |
|
|
|
place.height = Math.max(results[0].elevation / 1000, 0); |
|
|
|
callsRemaining--; |
|
|
|
if(callsRemaining <= 0) sendCoords(); |
|
|
|
} else { |
|
|
|
alert('Something went very wrong'); |
|
|
|
} |
|
|
|
});*/ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var coords = $scope.places.map(function(a) { |
|
|
|
return { |
|
|
|
lat: a.marker.getLatLng().lat, |
|
|
|
lng: a.marker.getLatLng().lng, |
|
|
|
height: a.height, |
|
|
|
angle: a.angle |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
var worker = new Worker('js/calc.js'); |
|
|
|
worker.addEventListener('message', function(e) { |
|
|
|
|
|
|
|
$scope.passes = e.data; |
|
|
|
$scope.isGettingPasses = false; |
|
|
|
$scope.$apply(); |
|
|
|
}, false); |
|
|
|
var fromDate = $("#fromDate").datepicker('getDate'); |
|
|
|
var toDate = $("#toDate").datepicker('getDate'); |
|
|
|
var duration = Math.abs(moment(toDate).diff(fromDate) / 1000) + 86400; |
|
|
|
worker.postMessage({coords: coords, satellites: $scope.satellites, fromDate: minDate(fromDate, toDate), toDuration: duration}); |
|
|
|
} |
|
|
|
|
|
|
|
$scope.getDate = function(date) { |
|
|
|
//console.log(date);
|
|
|
|
return moment(date).format("MMM D"); |
|
|
|
} |
|
|
|
|
|
|
|
$scope.getTime = function(date) { |
|
|
|
return moment(date).format("HH:mm:ss"); |
|
|
|
} |
|
|
|
|
|
|
|
$scope.getDifferenceInMinutes = function(a, b) { |
|
|
|
var d = moment.duration(moment(a).diff(moment(b))); |
|
|
|
return (d / 60000) + " minutes"; |
|
|
|
} |
|
|
|
|
|
|
|
$scope.getTimezone = function() { |
|
|
|
offset = new Date().getTimezoneOffset(); |
|
|
|
halfHour = offset % 60; |
|
|
|
halfHourStr = halfHour > 9 ? "" + halfHour : "0" + halfHour; |
|
|
|
return "GMT" + (offset > 0 ? "-" : "+") + Math.floor(offset / 60) + halfHourStr; |
|
|
|
} |
|
|
|
|
|
|
|
$scope.toggleEnabled = function(val) { |
|
|
|
for(var i = 0; i < $scope.satellites.length; i++) { |
|
|
|
$scope.satellites[i].enabled = val; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
function loadSatelliteData(callback) { |
|
|
|
$.get("nasabare.txt", function(data) { |
|
|
|
var splitLines = data.split(/\r?\n/); |
|
|
|
var satellites = [] |
|
|
|
for(var i = 0; i < splitLines.length; i += 3) { //3 lines per satellite, so advance by 1 satellite each time
|
|
|
|
if(splitLines[i] != '') { |
|
|
|
var sat = satellite.twoline2satrec(splitLines[i + 1], splitLines[i + 2]); |
|
|
|
var name = splitLines[i]; |
|
|
|
satellites.push({name: name, satrec: sat, enabled: true}); |
|
|
|
} |
|
|
|
} |
|
|
|
callback(satellites); |
|
|
|
}); |
|
|
|
$.get("nasabare.txt", function(data) { |
|
|
|
var splitLines = data.split(/\r?\n/); |
|
|
|
var satellites = [] |
|
|
|
for(var i = 0; i < splitLines.length; i += 3) { //3 lines per satellite, so advance by 1 satellite each time
|
|
|
|
if(splitLines[i] != '') { |
|
|
|
var sat = satellite.twoline2satrec(splitLines[i + 1], splitLines[i + 2]); |
|
|
|
var name = splitLines[i]; |
|
|
|
satellites.push({name: name, satrec: sat, enabled: true}); |
|
|
|
} |
|
|
|
} |
|
|
|
//sort satellites by name
|
|
|
|
satellites.sort(function(a, b) { |
|
|
|
return a.name.localeCompare(b.name); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
callback(satellites); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function minDate(date1, date2) { |
|
|
|
return date1 < date2 ? date1 : date2; |
|
|
|
return date1 < date2 ? date1 : date2; |
|
|
|
} |