Using Virtual Earth to Write a Vista Gadget That Tracks the International Space Station
This is the second part of two articles about writing Vista Gadgets that use Virtual Earth. The first part ("Using Virtual Earth in a Vista Gadget") showed you how to write a Vista Gadget that showed a simple interactive map using Virtual Earth. This second part extends the gadget into something more useful: A Tracker for the International Space Station (ISS).
At start up, the gadget automatically downloads the latest orbital parameters from the AmSat website.
The map is updated every half second with the ISS’s latest position. The position is tracked with a
pushpin shaped like the ISS. The map automatically pans to keep the ISS centered in the map. The user
may zoom in or out using "+" and "-" buttons. A "Refresh" button allows the orbital parameters to be
refreshed from AmSat. These orbital parameters should only be refreshed every few days -- you do not
need to do this if you restart Vista (and hence the gadget) on a daily basis.
Instead of two files, the gadget now contains ten files. One of these
is an image: ISS_pin.gif stores the image of the ISS pushpin. The remaining extra files (global.js,
graphic_clock.js, math.js, sgp4sdp4.js, time.js, utils.js, view.js ) are all JavaScript files used to
calculate the orbit of the ISS. These are based on the orbit calculation routines available from http://www.movingsatellites.com.
This gadget might seem quite a bit more complicated than the previous gadget. In reality it has the same overall structure. For example, here is our new manifest file:
The only change of consequence is that the main HTML source filename has been changed to "ISS_Tracker.html".
In turn, ISS_Tracker.html is based on the HTML file in our previous gadget. However, we need to add code to download the latest orbital data, make calls to the MovingSatellites.com code to calculate new positions, and to automatically update the map.
The gadget uses NORAD "TLE" (Two Line Element) Keplerian orbital parameters. This is a standard way of defining a satellite in Earth orbit in machine readable text form. A typical set of TLE parameters look like this:
The first line specifies the satellite name. The next two lines specify the parameters in a fixed format reminiscent of Fortran. These parameters can be obtained from a number of websites, including NORAD’s, but we shall get ours from the AmSat site. The URL for the file is: http://www.amsat.org/amsat/ftp/keps/current/nasa.all . We fetch this file using the ActiveX Microsoft.XMLHTTP object. Note that this is specific to Microsoft JScript. All Vista gadgets will use Jscript, but the ActiveX control will not necessarily be available in a traditional web browser environment (eg. Mozilla).
So let’s get to ISS_Tracker.html. Here is the beginning. As well as including the Virtual Earth control, we include the orbit calculation JScript files:
Next we get into our main JavaScript code with some global definitions and parameters:
The body section of the gadget is very similar to the previous Virtual Earth example. The body tag itself defines a call-back to onPageLoad(). We also have the two zoom buttons, and an empty div tag to hold the Virtual Earth map. New additions are a third button (“Refresh”) and a span tag to display the ISS’s coordinate position as a line of text.
And that is it! A few simple steps make the Virtual Earth gadget into a useful little tracking tool.
Prior to Winwaed, Richard worked as a software developer working on
seismic processing algorithms for the oil exploration industry. He holds
geology and geophysics degrees from the University of Cambridge
(Churchill College), and the University of Durham; and an
interdisciplinary MBA from the University of Dallas.