Animating a line can add a neat element to your Google Earth Tour. Here is an example of a line animating a path:
Path animating in Google Earth
To animate a line, you should be comfortable with the following things:
1. Opening a KML file, cutting, pasting code, looking for errors
2. Using a text editor like SCiTE (PC) or TextWrangler (MAC), both free
3. Using the 'find and replace' tool
4. If you find any ways to improve this process, please email me at ahecht@google.com and I will incorporate them!
Animating a Path is simply editing feature visibility, except you're turning on a bunch of tiny Path segments sequentially. The process below is the most basic way of creating a line animation, and thus a little more hands on than creating it through the API with Java.
Part 1: Creating a Path that you will use in the animation - the path to be animated needs to be created in a specific way to be used in a tour.
1. Create the Path in segments in Google Earth - Add a folder and create the Path segments you want to animate. Name them numerically.
Folder structure Paths
Considerations:
This is a long process; be sure to save the folder to 'My Places' and 'Save My Places' often.
Try to get the beginning and end of each Path segment close together to create a smooth animation.
Try to keep Path segments similar length for a smooth looking animation.
The smaller the segments, the more detailed the animation will appear.
2. Save the Folder as a KML - You will extract some of the KML out of this file
Saving a KML
3. Open the KML in a text editor - in order to for the Path segments KML to work properly in an animation, it has to be edited a bit
4. Find and Replace the following information:
Find and replace: <Placemark>
With: <Placemark id="-----">
Find and replace: <styleUrl>#m_ylw-pushpin</styleUrl> (#m_ylw-pushpin may vary)
With: <styleUrl>#line-style</styleUrl>
Find and replace: </name>
With: </name><visibility>0</visibility>
The path chunks will look like this:
Before:
<Placemark>
<name>1</name>
<styleUrl>#m_ylw-pushpin</styleUrl>
<LineString>
<tessellate>1</tessellate>
<coordinates>
14.20695788474047,40.8154896676023,0 14.20658768403162,40.81540606262579,0
</coordinates>
</LineString>
</Placemark>
After:
<Placemark id="-----">
<name>1</name> <visibility>0</visibility>
<styleUrl>#line-style</styleUrl>
<LineString>
<tessellate>1</tessellate>
<coordinates>
14.20695788474047,40.8154896676023,0 14.20658768403162,40.81540606262579,0
</coordinates>
</LineString>
</Placemark>
Do this for all Placemarks at once by using "Replace All" or similar with the Find and Replace tool.
5. Name Placemark ID's appropriately - in order for the script to know what Path segment to turn on, they must be named correctly
Match the <Placemark id="-----"> to match the number in the <name>1</name>
<Placemark id="1">
<name>1</name>
....
<Placemark id="2">
<name>2</name>
....
<Placemark id="3">
<name>3</name>
....
etc.
There is a sample KML at the bottom of this page called path-segment-edited.kml that you can take a look at as well.
6. Test the KML Path segment file - To test if everything is correct, Save the new Path segment KML and open it in Google Earth. The Paths should all be white and thin, as we have not identified the <styleUrl>#line-style</styleUrl> yet. If it does not open or something looks wrong, there may be an error in your Path segment KML file.
Part 2: Complete the Template File - The template file has two parts
The top of the KML file controls when the lines come on
Path segments are turned on with the <gx:AnimatedUpdate> tags
The <gx:AnimatedUpdate> tags are separated by the <gx:Wait> tags
All of the <gx:AnimatedUpdate> tags are contained by <Tour> tags at the top and bottom of this part of the KML
The bottom of the KML file holds the Path information
These are the <coordinates> or the LAT,LONG of the points on the Path
Each <Placemark> tag holds the information to one Path segment
Each <Placemark> tags is referenced above by the <gx:AnimatedUpdate> tags
The KML looks roughly like this, notes are in orange:
<(KML stuff that's in every KML file)>
<LookAt>
(lat,long,alt,etc.) - the opening view
</LookAt>
<Tour>
<gx:AnimatedUpdate> - Path segment 1 turn on
<Wait> - pause a fraction of a second
<gx:AnimatedUpdate> - Path segment 2 turn on
<Wait> - pause a fraction of a second
<gx:AnimatedUpdate> - Path segment 3 turn on
<Wait> - pause a fraction of a second
<etc.>
</Tour> - animating over
<Placemark ID="1"> - Path segment 1 information
<Placemark ID="2"> - Path segment 2 information
<Placemark ID="3"> - Path segment 3 information
<etc.>
</(KML stuff that's in every KML file)>
7. Open up the Template File - At the bottom of this page you will find the line-animation-template.KML file that you can put your Path information into to save time.
Notes are added in yellow and look like this: <!-- helpful notes -->
You can also open the line-animation-template-simplified.KML file and see the structure simplified into 3 Path segments.
Be sure not to remove any < or / or your file will not work properly.
8. Insert your Path segment information into the template file - copy all the Path segment Placemark data into the template file. This can be done all at once by coping everything from the first <Placemark id="1"> to the last </Placemark> and paste it into the template.
Open in YouTube, and full screen for full effect.
9. Delete unused AnimatedUpdate tags - The template file has 180 <gx:AnimatedUpdate> tags in the <Tour>. They look like this:
<gx:AnimatedUpdate>
<Update>
<Change><Placemark targetId="50"><visibility>1</visibility></Placemark></Change>
</Update>
</gx:AnimatedUpdate>
<gx:Wait><gx:duration>0.02</gx:duration></gx:Wait>
If your Path segment file has fewer, you can delete the <gx:AnimatedUpdate> tags you don't need. Likewise, if you have more than 180, you can Copy/Paste more.
10. Change the style of the Path - At the top of the template KML, you can change the color and width of the path to suit your needs:
<Style id="Line-style">
<LineStyle>
<color>bf00aaff</color> <!-- this is the color of your path -->
<width>5</width> <!-- this is the width of your path -->
</LineStyle>
</Style>
To get a new color, make a new Path in Google Earth, color it how you'd like, and extract the AA##AAAA from the KML.
11. Speed up or slow down the animation - use Find/Replace All to change the <gx:Wait> to make the tour faster or slower
Fast <gx:Wait><gx:duration>0.02</gx:duration></gx:Wait>
Med <gx:Wait><gx:duration>0.05</gx:duration></gx:Wait>
Slow <gx:Wait><gx:duration>0.10</gx:duration></gx:Wait>
You can experiment with these settings to see what works best for you as Find/Replace is pretty fast and easy.
12. Set the camera view - Just like adding the line style, set a camera view by Copy/Pasting the KML into the Template file.
Put a Placemark at the desired view
Save the Placemark as a KML
Open the KML
Copy the <LookAt> information to the Template file
<LookAt> information includes all this:
<LookAt>
<longitude>14.20830952335358</longitude>
<latitude>40.8143508364044</latitude>
<altitude>0</altitude>
<heading>-12.36466847352015</heading>
<tilt>36.96541540083902</tilt>
<range>5026.432628192288</range>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
Copy the whole thing and paste over the <LookAt> data at the top of the template file.