// This file contains utilities for rendering files for use with Google Earth
// and Google Maps.
// This class represents a point with a given latitude and longitude.
class GooglePoint
{
var latitude
var longitude
var altitude
var name
var description
new[name1, lat, long, alt = 0 m] :=
{
name = name1
latitude = lat
longitude = long
altitude = alt
}
setDescription[desc] :=
{
description = desc
}
// Render a full KML file for this point as a string and return it.
renderFullKML[] :=
{
renderKMLHeader[] + renderKMLPlacemark[] + renderKMLFooter[]
}
// Render a KML header
renderKMLHeader[] :=
{
"""
"""
}
// Render a KML footer
renderKMLFooter[] :=
{
"\n"
}
// Render a KML Placemark for this point. This is not a complete KML file,
// but only the placemark part.
renderKMLPlacemark[] :=
{
retval = " \n"
if description
retval = retval + " " + renderCDATA["description", description]
retval = retval + " " + renderCDATA["name", name]
retval = retval + """
"""
retval = retval + format[longitude, degrees, 6] + "," +
format[latitude, degrees, 6] + "," +
format[altitude, m, 4]
retval = retval + """
"""
return retval
}
}
// Helper function to render character data.
renderCDATA[tagname, data] :=
{
"<$tagname>$tagname>"
}
// Helper function to format Lat/Long into a format suitable for Google API
formatPoint[lat, long] :=
{
return format[lat, degrees, 6] + ", " + format[long, degrees, 6]
}
// Launch a Google Maps browser with the specific lat,long value
// and an optional label
// The t=h parameter puts it in satellite mode.
browseGoogleMaps[lat, long, label=""] :=
{
if (label != "")
ulabel = "+(" + URLEncode[label, "UTF-8"] + ")";
browse["http://maps.google.com/maps?q=" + format[lat, degrees, 6] + "," + format[long, degrees,6] + "$ulabel&t=h"]
}