Add gpredict.js for showing satellites orbits
parent
eaa8f5abc1
commit
5dc27ec994
|
@ -14,7 +14,8 @@
|
|||
"moment": "2.10.6",
|
||||
"bootstrap-daterangepicker": "2.1.x",
|
||||
"mapbox.js": "2.2.x",
|
||||
"dnt-helper": "schalkneethling/dnt-helper"
|
||||
"dnt-helper": "schalkneethling/dnt-helper",
|
||||
"gpredict.js": "kerel-fs/gpredict.js"
|
||||
},
|
||||
"overrides": {
|
||||
"jquery": {
|
||||
|
@ -56,6 +57,9 @@
|
|||
},
|
||||
"dnt-helper": {
|
||||
"main": "js/dnt-helper.js"
|
||||
},
|
||||
"gpredict.js": {
|
||||
"main": "dist/gpredict.min.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,9 @@ def satellite_position(request, sat_id):
|
|||
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
satellite.compute(now)
|
||||
data = {
|
||||
'name': str(sat.name),
|
||||
'tle1': str(sat.tle1),
|
||||
'tle2': str(sat.tle2),
|
||||
'lon': '{0}'.format(satellite.sublong),
|
||||
'lat': '{0}'.format(satellite.sublat)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*global L */
|
||||
/*global L Sat_t gtk_sat_data_read_sat predict_calc julian_date Geodetic_t radians xkmper de2ra asin sin cos arccos degrees pio2 pi fabs */
|
||||
|
||||
$(document).ready(function() {
|
||||
'use strict';
|
||||
|
@ -9,6 +9,13 @@ $(document).ready(function() {
|
|||
|
||||
L.mapbox.accessToken = mapboxtoken;
|
||||
L.mapbox.config.FORCE_HTTPS = true;
|
||||
|
||||
// Number of positions to compute
|
||||
var COUNT = 300;
|
||||
|
||||
// Interval in ms between positions to compute
|
||||
var STEP = 60*1000;
|
||||
|
||||
var map = L.mapbox.map('map', mapboxid, {
|
||||
zoomControl: false
|
||||
});
|
||||
|
@ -19,31 +26,140 @@ $(document).ready(function() {
|
|||
iconAnchor: [16, 16]
|
||||
});
|
||||
|
||||
var marker = L.marker([0, 0], {
|
||||
// Create satellite marker
|
||||
var satMarker = L.marker([0, 0], {
|
||||
icon: satIcon,
|
||||
clickable: false
|
||||
});
|
||||
|
||||
marker.addTo(map);
|
||||
// Create satellite footprint
|
||||
var satFootprint = L.polygon(
|
||||
[],
|
||||
{
|
||||
stroke: true,
|
||||
weight: 2,
|
||||
fill: true,
|
||||
}
|
||||
);
|
||||
|
||||
function update_map(lat, lon) {
|
||||
map.setView([lat, lon], 3);
|
||||
// Create satellite orbit
|
||||
var current_orbit = [];
|
||||
var all_orbits = [];
|
||||
|
||||
marker.setLatLng(L.latLng(lat, lon));
|
||||
var satOrbit = L.multiPolyline(
|
||||
all_orbits,
|
||||
{
|
||||
weight: 4
|
||||
}
|
||||
);
|
||||
|
||||
var sat = new Sat_t();
|
||||
|
||||
satMarker.addTo(map);
|
||||
satFootprint.addTo(map);
|
||||
satOrbit.addTo(map);
|
||||
|
||||
function initialize_map(name, tle1, tle2) {
|
||||
// Load satellite orbit data from TLE
|
||||
gtk_sat_data_read_sat([name, tle1, tle2], sat);
|
||||
|
||||
{
|
||||
var t = new Date();
|
||||
|
||||
var previous = 0;
|
||||
for ( var i = 0; i < COUNT; i++) {
|
||||
predict_calc(sat, (0,0), julian_date(t));
|
||||
if (Math.abs(sat.ssplon - previous) > 180) {
|
||||
// orbit crossing -PI, PI
|
||||
all_orbits.push(current_orbit);
|
||||
current_orbit = [];
|
||||
}
|
||||
current_orbit.push([sat.ssplat, sat.ssplon]);
|
||||
previous = sat.ssplon;
|
||||
// Increase time for next point
|
||||
t.setTime(t.getTime() + STEP);
|
||||
}
|
||||
|
||||
satOrbit.setLatLngs(all_orbits);
|
||||
}
|
||||
update_map();
|
||||
}
|
||||
|
||||
(function worker() {
|
||||
function update_map() {
|
||||
// Recalculate satellite location
|
||||
var t = new Date();
|
||||
predict_calc(sat, (0, 0), julian_date(t));
|
||||
|
||||
// Update location on map
|
||||
map.setView([sat.ssplat, sat.ssplon], 3);
|
||||
satMarker.setLatLng(L.latLng(sat.ssplat, sat.ssplon));
|
||||
|
||||
// Refresh satellite footprint
|
||||
{
|
||||
var azi;
|
||||
// var msx, msy, ssx, ssy;
|
||||
var ssplat,
|
||||
ssplon,
|
||||
beta,
|
||||
azimuth,
|
||||
num,
|
||||
dem;
|
||||
// var rangelon, rangelat, mlon;
|
||||
|
||||
var geo = new Geodetic_t();
|
||||
|
||||
/* Range circle calculations.
|
||||
* Borrowed from gsat 0.9.0 by Xavier Crehueras, EB3CZS
|
||||
* who borrowed from John Magliacane, KD2BD.
|
||||
* Optimized by Alexandru Csete and William J Beksi.
|
||||
*/
|
||||
ssplat = radians(sat.ssplat);
|
||||
ssplon = radians(sat.ssplon);
|
||||
beta = (0.5 * sat.footprint) / xkmper;
|
||||
|
||||
var points = [];
|
||||
|
||||
for (azi = 0; azi < 360; azi += 5) {
|
||||
azimuth = de2ra * azi;
|
||||
geo.lat = asin(sin(ssplat) * cos(beta) + cos(azimuth) * sin(beta)
|
||||
* cos(ssplat));
|
||||
num = cos(beta) - (sin(ssplat) * sin(geo.lat));
|
||||
dem = cos(ssplat) * cos(geo.lat);
|
||||
|
||||
if (azi == 0 && (beta > pio2 - ssplat)) {
|
||||
geo.lon = ssplon + pi;
|
||||
}
|
||||
else if (azi == 180 && (beta > pio2 + ssplat)) {
|
||||
geo.lon = ssplon + pi;
|
||||
}
|
||||
else if (fabs(num / dem) > 1.0) {
|
||||
geo.lon = ssplon;
|
||||
} else {
|
||||
if ((180 - azi) >= 0) {
|
||||
geo.lon = ssplon - arccos(num, dem);
|
||||
} else {
|
||||
geo.lon = ssplon + arccos(num, dem);
|
||||
}
|
||||
}
|
||||
|
||||
points.push([degrees(geo.lat), degrees(geo.lon)]);
|
||||
}
|
||||
|
||||
satFootprint.setLatLngs(points);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
(function init_worker() {
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function(data) {
|
||||
if (('lat' in data) && ('lon' in data)) {
|
||||
update_map(data.lat, data.lon);
|
||||
if (('name' in data) && ('tle1' in data) && ('tle2' in data)) {
|
||||
initialize_map(data.name, data.tle1, data.tle2);
|
||||
setInterval(update_map, 5000);
|
||||
} else {
|
||||
$('div#map').hide();
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
setTimeout(worker, 5000);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -431,5 +431,6 @@
|
|||
<script src="{% static 'lib/bootstrap-daterangepicker/daterangepicker.js' %}"></script>
|
||||
<script src="{% static 'lib/mapbox.js/mapbox.js' %}"></script>
|
||||
<script src="{% static 'js/app.backbone.js' %}"></script>
|
||||
<script src="{% static 'lib/gpredict.js/dist/gpredict.min.js' %}"></script>
|
||||
<script src="{% static 'js/map.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue