summaryrefslogtreecommitdiff
path: root/tools/mmd/MmdWidgets.py
diff options
context:
space:
mode:
authorJogi Hofmüller <jogi@mur.at>2011-08-09 19:02:08 +0000
committerJogi Hofmüller <jogi@mur.at>2011-08-09 19:02:08 +0000
commit9ec0b02148363742768cc5cf5698b67a8ea19cfd (patch)
tree1ebbb2c38a26ad74a3a8e842c6e3e4ffe0850906 /tools/mmd/MmdWidgets.py
parent- added file testmap.html (diff)
- we are tracking ARISSAT-1 now ;)
git-svn-id: https://svn.spreadspace.org/mur.sat@106 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'tools/mmd/MmdWidgets.py')
-rw-r--r--tools/mmd/MmdWidgets.py95
1 files changed, 85 insertions, 10 deletions
diff --git a/tools/mmd/MmdWidgets.py b/tools/mmd/MmdWidgets.py
index 4f0d582..accb87e 100644
--- a/tools/mmd/MmdWidgets.py
+++ b/tools/mmd/MmdWidgets.py
@@ -3,8 +3,54 @@ web widgets for MURSAT1 Dashboard
"""
import time
+import ephem
from MmdLocation import Location
+def createJavaArray (jarray, name):
+ astring = '''var {0} = new Array ('''.format (name)
+ for e in jarray:
+ astring = '''{0}\n\t{1}'''.format (astring, e)
+ astring = '''{0}\n);'''.format (astring)
+ return astring
+
+def dms2degdec (lonlat):
+ parts = lonlat.split (':')
+ if len (parts) != 3:
+ return 0.0
+ degrees = float (parts[0])
+ fraction = (float (parts[1]) * 60.0 + float (parts[2])) / 3600
+ if parts[0][0] == '-':
+ return degrees - fraction
+ return degrees + fraction
+
+def computeTrajectory (longitude, latitude, elevation):
+ """
+ test for static TLE to trajectory computation
+ """
+ line0 = "ARISSAT-1/RADIOSCAF-B"
+ line1 = "1 37772U 98067CK 11220.22334818 .00031592 00000-0 37647-3 0 118"
+ line2 = "2 37772 51.6391 258.8215 0013530 58.1430 19.7106 15.60689826 619"
+
+ sat = ephem.readtle (line0, line1, line2)
+ graz = ephem.Observer ()
+ graz.long, graz.lat, graz.elevation = longitude, latitude, elevation
+
+ sat.compute (graz)
+ array_string = 'new OpenLayers.LonLat ({0}, {1}).transform (from, to){2}'
+ longitude = dms2degdec (sat.sublong.__str__ ())
+ latitude = dms2degdec (sat.sublat.__str__ ())
+ java_array = [array_string.format (dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), ',')]
+ for i in range (12 * 24):
+ graz.date += 5 * ephem.minute
+ sat.compute (graz)
+ java_array.append (array_string.format (dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), ','))
+
+ graz.date += 5 * ephem.minute
+ sat.compute (graz)
+ java_array.append (array_string.format (dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), ''))
+
+ return longitude, latitude, createJavaArray (java_array, 'trajectory')
+
def loginFormWidget ():
html = '''
Please enter your email and password in the form below.
@@ -155,30 +201,59 @@ def osmWidget (satellite, user):
user_location = user.getDefaultLocation ()
if not user_location:
user_location = Location ()
+ longitude, latitude, java = computeTrajectory (user_location.longitude, user_location.latitude, 300)
+
+ #
+ # how can we use { and } in javascript that can be ignored by python format ()?
+ #
html = '''
<div id="osm"></div>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script>
+ // satellite and user position
var from = new OpenLayers.Projection ("EPSG:4326");
var to = new OpenLayers.Projection ("EPSG:900913");
- var satellite = new OpenLayers.LonLat ({0}, {1}).transform (from, to);
+ var sat_position = new OpenLayers.LonLat ({0}, {1}).transform (from, to);
var user_location = new OpenLayers.LonLat ({2}, {3}).transform (from, to);
// create a map
- map = new OpenLayers.Map ("osm");
+ var map = new OpenLayers.Map ("osm");
map.addLayer (new OpenLayers.Layer.OSM ());
- // set a marker
- var markers = new OpenLayers.Layer.Markers ("Markers");
- map.addLayer (markers);
- markers.addMarker (new OpenLayers.Marker (satellite));
- markers.addMarker (new OpenLayers.Marker (user_location));
+ // create a markers
+ var markersLayer = new OpenLayers.Layer.Markers ("Markers");
+ var sat = new OpenLayers.Marker (sat_position);
+ var user = new OpenLayers.Marker (user_location);
+ user.setOpacity (0.5);
+ map.addLayer (markersLayer);
+ markersLayer.addMarker (sat);
+ markersLayer.addMarker (user);
+
+ // array build by python ;)
+ {4}
+
+ // points/polygons
+ var lineLayer = new OpenLayers.Layer.Vector ("Polygons");
+ map.addLayer (lineLayer);
+ map.addControl (new OpenLayers.Control.DrawFeature(lineLayer, OpenLayers.Handler.Path));
+
+ var points = new Array (new OpenLayers.Geometry.Point (sat_position.lon, sat_position.lat));
+
+ for (var i = 0; i < trajectory.length; i++)
+ {{
+ points.push (new OpenLayers.Geometry.Point (trajectory[i].lon, trajectory[i].lat));
+ }}
+
+ var polygon = new OpenLayers.Geometry.LineString (points);
+ var lineStyle = {{strokeColor: '#00ff00', strokeOpacity: 1, strokeWidth: 2}};
+ var lineFeature = new OpenLayers.Feature.Vector (polygon, null, lineStyle);
+ lineLayer.addFeatures ([lineFeature]);
// center the map
- map.setCenter (user_location, 2);
+ map.setCenter (sat_position, 2);
+
</script>
- <!-- lon: {2} lat: {3} -->
- '''.format (satellite['longitude'], satellite['latitude'], user_location.longitude, user_location.latitude)
+ '''.format (longitude, latitude, user_location.longitude, user_location.latitude, java)
return html