spacer1
spacer2 1_1 1_2
2_1
 Subscribe
 The MP2K Update!
 
 
 
 Magazine
Front Cover
What's New
Articles
Toolbar
News
Sample Data
Gallery
Advertise
About
 Features
MapPoint 2006
Press Releases
MapPoint Forums
Companies
Link to MP2Kmag
Wish List
MapPoint Trial
Authors
 Sponsors
 Order

MapPoint 2006

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
ViaVirtualEarth
SVG Tutorials
MapPoint

Map Visitors

 Direct Media

Computer support
Get pro-active monitoring software that identifies problems before they happen and fixes them before you even know they exist!

print cartridges
Need ink cartridges for your printer? With us you can print away without worrying. Ring our freephone before 4pm for same day dispatch!

Cheap flights to Majorca
Majorca has got a little something for everyone. As well as the legendary nightlife there are historical areas to explore. Check it out!

Holidays to Tenerife
When you book with On The Beach, holidays to Tenerife are value for money. We won't be beaten on price! Check us out online.

bulgaria Property
Visit us online for details on how to buy picturesque Bulgarian property in mountain ski resorts or seaside beach resorts.

Goa Flights
Are you searching for flights to Goa? Use dealchecker.co.uk to compare airfare prices and find the best deal available! See online!

Rhodes
Rhodes is one of the most visited of the choice of Greek islands. Why not take your next vacation to this warm and welcoming destination.

  ARTICLES  


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).

Download code for this article.

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:

ISS
1 25544U 98067A   07055.29853167  .00017324  00000-0  99505-4 0  7052
2 25544 051.6356 327.3797 0020641 244.1596 211.2169 15.78603656472945

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:

Most of these are probably self explanatory. "map" refers to the Virtual Earth Control. "TLE_Line1" and "TLE_Line2" are used to pass the TLE orbital parameters to the orbit calculation code. "pinSet" is a flag used to monitor whether we already have a pushpin for the ISS. We need to know this when moving the pushpin to a new location.

"UpdatePeriod" is a parameter that defines the time (in milliseconds) between map updates. It is currently set to 500ms (half a second). "url" specifies the URL of the TLE data file. You can change this to a different data provider if you wish. "sSatellite" specifies the name of the required satellite in the TLE data file. Note that the same satellite might have different names in different files. For example, the ISS is still occasionally referred to as "Zarya".

Unfortunately JavaScript has very limited number formatting abilities. Hence we need to define a simple utility to convert floating point numbers into fixed strings with 4 decimal places. This is used when displaying the ISS’s coordinates. Here is the utility:

We fetch the TLE data using the Microsoft.XMLHTTP ActiveX object. This is asynchronous, so we have to define a callback that handles the data when it has been received. This is called stateChange() and is defined as follows:

This function checks to see if the callback represents a successful data fetch. If successful, it then scans through the data looking for a line that matches “sSatellite”. When found, the two lines of the TLE are extracted. The map is then created or refreshed.

The start-up process is controlled by the following two functions:

onPageLoad() is a callback that is called when the gadget is created. Here we simply call getOrbitalElements(). This creates the Microsoft.XMLHTTP ActiveX object to fetch the orbital data. When the data is fetched, the stateChange() callback is called. This then calculates the orbital data and creates the map.

The map is created using the function createMap():

This loads the orbital data into the MovingSatellites.com code, gets the time, and calculates an initial orbital position. The position is stored in m_SatelliteData for convenience. The gadget body tag contains a span tag called “gadgetContent”. This is positioned between the buttons and the map, and displays the ISS’s coordinate position as a line of text. The “gadgetContent.innerText=” performs this display.

We then create a new Virtual Earth Map object (VEMap), and center the map on the ISS’s current position. A pushpin is also created at this position using the ISS_pin.gif image.

The final "setTimeout" line sets a call-back to the ReDisplay() function for a map update. The update interval is set by the UpdatePeriod parameter.

The implementation of ReDisplay() is actually very similar to createMap(). The orbital data does not have to be loaded, and the map does not have to be created. However, the old ISS pushpin does have to be deleted, and the map has to be panned to the new position.

The JavaScript finishes with the three button callbacks. The "+" and "-" zoom buttons are identical in action and implementation as before. However, the new "Refresh" button requires a new call back. This is just as simple, and calls getOrbitalElements() to re-fetch the orbital 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.

Further Information

The TLE Orbital Parameters: http://en.wikipedia.org/wiki/TLE
AMSAT: http://www.amsat.org/amsat-new/index.php
NASA’s ISS Homepage: http://www.nasa.gov/mission_pages/station/main/index.html
Developing Vista Gadgets: http://microsoftgadgets.com/Sidebar/DevelopmentOverview.aspx

Discuss this story in the forum.

Author: Richard Marsden
Email: enquiries(AT)winwaed.com
URL: http://www.winwaed.com
Richard Marsden is the proprietor of Winwaed Software Technology LLC which provides software consulting and development services, specialising in geographic, graphical, and scientific applications. He is currently able to offer mapping solutions using MapPoint and/or the Gistix Toolkit; and operates the Mapping-Tools.Com Website for MapPoint Tools and Utilities.

Previous to Winwaed, Richard has worked as a software developer in the seismic exploration business.

Richard holds geology and geophysics degrees from the University of Cambridge (Churchill College), and the University of Durham.



Google
 
MP2Kmag Internet


 Recent Discussion
-An invalid argument was encountered.
-Navman Wireless Oem Solutions Enhances Leading Line Of Gps Receiver Modules
-T-mobile UK
-Virtual Earth and OpenLayers
-Reminder: Microsoft Virtual Earth Partner Webinar and Offer for Free Training
-Virtual Earth Quarterly Technical Briefing
-Customize User Page
-Information about area
-Territory information
-Gps task pane in ActiveX
-Worldwide Telescope Now Available!
-c++ - setting the color of a line
-Initial Costa Rica MapServer map is up & running!
-Satellite Images of Myanmar Cyclone Damage
-Virtual Earth Loyalist: Aerial View
-Leaving messages on the Virtual Earth for Government blog site
-Virtual Earth Webcast: Adding Mapping Capabilities to your Applications with Virtual Earth
-Get new Lat & Lon from speed
-Integrating Virtual Earth Maps and Excel 2007
-Zillow.com
-ADODB Recordset to MapPoint.DataSet
-Why my new phone isn't an iPhone
-Version 6.0 to 6.1 Auto-Upgrade Alert & V 3-5 Deprecation Reminder
-Accessing MultiMap in the UK. Plus a comparison of UK mapping sites.
-Duplicate double-clicking State name in code?
 Resources
Browse GIS books and periodicals
Best Car Contract Hire Lease Save
Find a MapPoint Partner or Consultant
Real Estate Columbia For Sale By Owner


Want Your Site To Appear Here?

   © 1999-2008 MP2K. Questions and comments to: website@mp2kmag.com
  Microsoft and MapPoint 2002/2004/2006 are either trademarks or registered trademarks of Microsoft.

• Replacement Cordless Phone Batteries from DSMiller
Improve your career with a computer degree LocalEDU.com
• Tim Cohn's Marketing Strategy Consultancy
• Buy Toner, Ink Cartridges & Drums at Marquee Office Solutions
• Looking for Dry Erase Boards? See Dry Erase Boards
• 5339 - We Know Bikes: Road Bikes / Triathlon Bikes / Mountain Bikes / BMX Bikes
• Buy Your Car Used Cars, Car Lease and Contract Hire