I have a KML file with a few different placemarks all around the globe. I would like to flyto the first placemark and display it's balloon, wait a minute or two, then flyto the next placemark, and repeat this process until all of the placemarks have been shown.
I think I might be able to achieve this by putting all the placemarks into a tour but this doesn't seem like the right approach. I'm going to be refreshing the KML from a server and I'm not sure how a tour would react to that (e.g., I think you have to always click play before starting a tour).
If this isn't possible I may have to place just a single placemark in the KML file and then keep refreshing the file with a different placemark. I think that approach might be bad though because it will be refreshing a lot more.
I ended up putting one placemark per KML file. I wrote a program in Java that uses the Saxon processor and an XSLT stylesheet to create multiple KML files with just a single placemark per file then using this tutorial I was able to cycle through the KML files one-by-one.
When doing this locally on my machine I created two folders. Folder A housed all the KML files. Folder B would house only one KML file which would be the file expected from the KML NetworkLink tag. In the Java program I had a timer thread that sequentially deletes the single file in Folder B, cuts a file out of Folder A, moves it into Folder B, then renames the newly placed file the common name which the KML NetworkLink tag expects. I hope this helps and the link will help this to make more sense.
(Base KML file which is loaded into Google Earth - Basically tells Google Earth to look for the file called every10.kml every 10 seconds. If we swap that file out, say, every 9 seconds, then once it's refreshed by Google Earth it will be a new KML file thus showing the new placemark)
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<NetworkLink>
<Link>
<href>every10.kml</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>10</refreshInterval>
</Link>
</NetworkLink>
</Document>
</kml>
Related
I have an app that over time writes Placemarks to a kml file, slowly building up a route over time.
When I open the file in Google Earth, I can see the Placemarks already in the file, but any new ones added to the doc aren't shown on the map, until I reopen the document again.
Is there any way of getting the document to auto refresh in Google earth?
I've tried putting a NetworkLink into the document whose href points itself (the file) with a refreshMode of onChange, and that works, but the whole document is reloaded on each change and each point is displayed again, which is messy.
NOTE: I can't change the apps code, to generate single Placemark updates, which I believe is the proper way of using NetworkLinks.
The only way to perform incremental updates in KML is using the NetworkLinkControl element in conjunction with a NetworkLink.
NetworkLinkControl controls the behavior of files fetched by a <NetworkLink> in which you can change, add, or delete elements that you already fetched.
<NetworkLinkControl>
<cookie>cookie=sometext</cookie>
<linkName>link name</linkName>
<Update>
<targetHref>same-targethref-for-networklink</targetHref>
<Create>
<Document targetId="targetdoc">
<Placemark>
<name>Created place1</name>
</Placemark>
<Placemark>
<name>Created place2</name>
</Placemark>
</Document>
</Create>
...
</Update>
</NetworkLinkControl>
The NetworkLinkControl is tricky to get working such as the URLs in the NetworkLink and NetworkLinkControl must match exactly.
You can find a tutorial with an example to get started.
https://developers.google.com/kml/documentation/updates
So I guess you can't. I thought there might be some kind of structure within kml to achieve this, nut it would appear not.
KML newb here. First post.
Using GE client application, v7.12. Have fairly simple KML doc containing placemarks to several GPS time-based breadcrumb points. Wrote a simple C# app to generate the kml doc. Expect to have several more like files for additional tracked entities. I get this working and decide to fancy up the placemark balloons via HTML. Ultimately decide I'd like to have links in the balloon to move to the previous or next placemark. Find advice on this site and make it happen.
Since my app may update(by rewriting) the doc at times it would be nice to not have to manually reload it. Plus there will ultimately be other docs for other tracked entities, all controlled/updated by my app. OK - NetworkLink to the rescue. Cool feature and gives me the option of dynamically modifying the networklinks file to only include the entity doc files that have changed. Plus big bonus -- turning 'flyToView' off so that when networklinks file is reloaded or refresh fires, I'm not pulled away from whatever I'm currently viewing by the default 'LookAt' that normally seems to happen when a doc is loaded directly (anyone know a way around this?)
Very happy, until I discover that when I click one of my balloon links to move to the next or previous point, GE decides to create a new copy of the entire containing document under Temporary Places and now I have two entire sets of points displayed, one hiding the other. On the surface, my next/prev links appear to be working, but they are actually only working with the newly created doc. To test, I alter the original doc with an entirely different set of locations. Reload the networklinks doc to bring in the new point-laden doc and see the new set of points. But when I use any balloon links on the new, they jump to points on the older doc that GE had created on its own. Delete the GE-created version, click balloon and viola, GE creates a new copy of it and were back where we started. Frustrating.
As placemark IDs, I'm using strings like "TPn", where n increments. In my balloon links, I'm linking to the fragment URLs such as href="#TPn-1" and href="TPn+1", ie TP2 links to TP1 and TP3, etc, and I account for both placemarks on the end so they don't have bad links to non-existent IDs. BTW, I've found when you do activate a link to a non-existent fragment URL, GE also decides to create a copy of the file, even if the file was loaded directly and not via a networklink, so you again have one point set laying on top of the other. However, I'm confident I have no bad links in this case.
Any light that can be shed would be appreciated. Or alternate ways of achieving my goals. I'm a KML newb after all and maybe there's something I'm doing wrong.
I suppose if I have to, I will sacrifice the balloon links. Being able to reload only one networklinks document for a collection of files + timed refresh + turning off flyToView are too desirable to lose now.
Thanks!
EDIT: Additional info - The duplicate document is created only when using balloon links. Clicking a link in the treeview under the placemark does not cause this anomaly. (In the code sample, remove the null Snippet element for each Placemark to see this effect.) Furthermore, it appears that a balloon link to ANY fragment URL causes the anomaly, such as a link back to a containing folder or document.
EDIT: Added 2 code samples. These are pared down to my essential needs, but still demonstrate the problem. Interesting to note the difference in the GE tree view when the data file 'document' element has an 'id' defined vs not, but it has no bearing on the problem. I prefer the look when the id is omitted.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- File is: C:\myTwoDataPoints.kml -->
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="myDoc">
<name>Two Points Doc Name Here</name>
<description>Doc Description Here</description>
<visibility>0</visibility>
<Snippet>Contains Two Data Points</Snippet>
<Style id="myStyle">
<BalloonStyle >
<text><![CDATA[Link To: $[description] ]]></text>
</BalloonStyle>
</Style>
<Folder>
<name>Points Folder</name>
<open>1</open>
<Placemark id="TP1">
<name>Miami, FL, USA</name>
<Snippet />
<description><![CDATA[New York]]></description>
<styleUrl>#myStyle</styleUrl>
<Point>
<coordinates>-80.226439,25.788969,0</coordinates>
</Point>
</Placemark>
<Placemark id="TP2">
<name>New York, NY, USA</name>
<Snippet />
<description><![CDATA[Miami]]></description>
<styleUrl>#myStyle</styleUrl>
<Point>
<coordinates>-74.005973,40.714353,0</coordinates>
</Point>
</Placemark>
</Folder>
</Document>
</kml>
and...
<?xml version="1.0" encoding="UTF-8"?>
<!-- File is: C:\myNetworkLink.kml -->
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>NetworkLink Document Name Here</name>
<visibility>0</visibility>
<open>1</open>
<NetworkLink>
<name>NetworkLink Name Here</name>
<refreshVisibility>1</refreshVisibility>
<flyToView>0</flyToView>
<Link><href>file:///C:/myTwoDataPoints.kml</href></Link>
</NetworkLink>
</Document>
</kml>
I have a program that is constantly writing/updating a KML file, and I have a network link that points to this file. Under heavy load, if the Network Link attempts to access the KML file at the same time as my program is writing to the KML file, Google Earth stops any further auto-refreshing of that Network Link, assuming it to be broken. At this point, I then have to right-click the network link in the Places pane of Google Earth, and hit refresh, for the auto-updating to begin again.
My question is, is there any way to force Google Earth to keep reading from network links, even after a "no file detected" error? Because it is a real hassle having to manually hit refresh for the network link to become active again, when it seems that task could be easily automated.
I have made countless optimizations on my program's part to minimize the time period it spends writing to the KML file, however I have reached a practical limit, and must now figure out a way to fix this network link issue from within Google Earth.
Any replies, comments, or discussions would be greatly appreciated!
We had a similar problem a while ago. In searching the google-earth kml developers forums, a few people recommended using a network-link to a network-link approach like so:
KML file 1 that links to the updating kml file:
<Document>
<NetworkLink>
<Link> my_URL_to_the_updating_kml
<refreshMode>onInterval</refreshMode>
<refreshInterval>my_Inteval</refreshInterval>
</Link>
<name>My_Name</name>
<visibility>1</visibility>
</NetworkLink>
</Document>
KML file 2 that links to the network link file above:
<Document>
<NetworkLink>
<Link>
my_URL_to_the_first_network_link_file
<refreshMode>onInterval</refreshMode>
<refreshInterval>3600</refreshInterval>
</Link>
<name>My_Name</name>
<visibility>1</visibility>
</NetworkLink>
</Document>
If you're writing to a file on the server a simple trick is write to a temp file then swap with the target file like this:
write temp file temp.kml
delete target.kml
rename temp.kml target.kml
The renaming of the files will be nearly instantenous so very unlikely the Google Earth client will fetch it the momemt it's being swapped out. Depending on the OS of the server you could also use symbolic links to change the file reference in one operation.
UPDATE: in whatever is writing the file can you set the filename in a shared variable and serve that file via a "servlet" that opens a stream to the current file. The networklink can point to the servlet rather than the static KML file.
I generate KML files which may have 50,000 placemarks or more, arranged in Folders based on a domain-specific grouping. The KML file uses custom images which are packed in to a KMZ file.
I'm looking to breakup the single KML file in to multiple files, partitioned based on the grouping, so rather than having 1 large document with folders, i'd have a root/index KML file with folders linking to the smaller KML files.
Is this possible though? I think that a KMZ file can contain only 1 KML file, regardless of where it's located or its name, in the zip. Furthermore, I'm not exactly sure how a KML file can link to another KML file. Is the only way to have it as a <NetworkLink> to a local file? Can a <NetworkLink> work to link to a file local in the same KMZ?
By design you can have multiple KML files within a single KMZ file. That way you can bundle many KML files in a single KMZ file that is downloaded, sent via e-mail or accessed offline.
Google Earth can scale to a large number of features (50,000 or much larger) in a single KMZ file if the features are split into multiple KML files and the KML is defined such that all the sub-KML files are not displayed at once. KML provides mechanisms to control which features or sub-KML files are displayed using time, region, or altitude level filtering.
Large KML files can scale using any of the following techniques:
NetworkLinks
Regions
Folder Radio style or explicit visiblity=0
Number of Points per feature and geometry simplification
NetworkLinks
You can have any level of NetworkLinks from within your root KML file from flat (single KML file with Networklinks to all other KML files within the KMZ) to deep (with each KML file with a NetworkLink to other KML files each with its own NetworkLink). Depends on how you need to structure your KML and how large the data is.
The key is that Google Earth chooses the first KML as the root KML file so you must ensure that the first file (typically named doc.kml) is the root KML file that loads the other KML files via network links. A common structure is to include additional KML files in a "kml" sub-folder to differentiate it from the root KML file.
Here's a KMZ example with 4 file entries: root KML file (doc.kml) that contains a NetworkLink to "kml/sub1.kml" and another to "kml/sub2.kml", which in turn has a NetworkLink to "sub3.kml" also in "kml" sub-folder.
== test.kmz ==
+doc.kml
NetworkLink > kml/sub1.kml
NetworkLink > kml/sub2.kml
+kml/sub1.kml
+kml/sub2.kml
NetworkLink > sub3.kml
+kml/sub3.kml
Here is the structure of such a doc.kml file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<NetworkLink>
<name>NetworkLinked sub-item</name>
<Link>
<href> kml/sub1.kml </href>
</Link>
</NetworkLink>
<NetworkLink>
<name>NetworkLinked sub-item</name>
<Link>
<href> kml/sub2.kml </href>
</Link>
</NetworkLink>
...
</Document>
</kml>
As a best practice if you include more than one NetworkLink with time-based features in a parent KML file then add a <TimeSpan> element to the NetworkLinks including the full range of time for that collection of features otherwise Google Earth will automatically load the entire file at startup.
<NetworkLink>
<TimeSpan>
<begin>2007-01-14T01:00:00Z</begin>
<end>2007-01-14T02:00:00Z</end>
</TimeSpan>
<Link>
<href>...</href>
</Link>
</NetworkLink>
Regions
A Region
affects visibility of a Placemark's geometry or an Overlay's image. Regions combined with NetworkLinks enable access to massive amounts of data in KML files. A region can optionally have a min and max altitude for altitude level filtering.
For more details, here's a tutorial on Regions in KML
https://developers.google.com/kml/documentation/regions
Radio Folders
You can further restrict what is displayed at a given time using radio folders.
Here's a radio folder example allowing the user to only choose one of the NetworkLinks at a time.
This is used when the content is mutually exclusive and only one set of features should appear at any given time.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="rf">
<ListStyle>
<listItemType>radioFolder</listItemType>
</ListStyle>
</Style>
<Folder>
<name>One at a time example</name>
<open>1</open>
<description>Link 1 visible by default</description>
<styleUrl>#rf</styleUrl>
<NetworkLink>
<name>NetworkLinked sub-item-1</name>
<Link>
<href> kml/sub1.kml </href>
</Link>
</NetworkLink>
<NetworkLink>
<name>NetworkLinked sub-item-2</name>
<visibility>0</visibility>
<Link>
<href> kml/sub2.kml </href>
</Link>
</NetworkLink>
</Folder>
</Document>
</kml>
Number of Points per feature and geometry simplification
Size of the KML file and number of features is not the only issue to consider. A KML file with a single hi-res polygon having 350K points and 7000 inner holes can cause Google Earth performance issues. Such geometries would need to be simplified and the number of points reduced. You can use QGIS to open a KML file then apply a simplify algorithm on the polygon. In QGIS, select Vector menu -> Geometry tools -> Simplify then save the result.
Yes you can use a networklink to accomplish this and as far as I know it's the only way to do what you ask. And yes you can reference local files in Network links
See: http://code.google.com/intl/nl-NL/apis/kml/documentation/kml_tut.html (search for "Network Links") where it says:
A network link contains a element with an (a hypertext
reference) that loads a file. The can be a local file
specification or an absolute URL. Despite the name, a <NetworkLink>
does not necessarily load files from the network. The <href> in a
link specifies the location of any of the following:
• An image file used by icons in icon styles, ground overlays, and screen overlays
• A model file used in the element
• A KML or KMZ file loaded by a Network Link
No you can't reference to another file inside a kmz. A kmz can only contain 1 kml file (it can contain other type of files though) You can find the layout of kmz files and what may be put in them here Specifically note the following section:
2.Put the default KML file (doc.kml, or whatever name you want to give
it) at the top level within this folder. Include only one .kml file.
(When Google Earth opens a KMZ file, it scans the file, looking for
the first .kml file in this list. It ignores all subsequent .kml
files, if any, in the archive. If the archive contains multiple .kml
files, you cannot be sure which one will be found first, so you need
to include only one.)
One final remark is that your question doesn't tell anything if you need these 50.000 placemarks as offline files or not. If you could serve them dynamically you could use the region based links where GE will tell you the viewing region of the client so you can return a small subset of the waypoints (only the ones that are inside the users view) For more info this is the link to click on.
I am new to the KML format and try to figure out how to display a boat (a png), moving from a place to another along a path (a simple line drawn composed of several lines).
I can see how to display a Placemark, even with an icon, and a Path, separately.
What I would like to see when I click on the KML file is :
the boat appearing at the departure point;
the path drawing itself until the arrival;
the boat icon moving at a comfortable speed (bonus point it I can set a ration time / progress, extra bonus if I can click on start, pause or rewind) from departure to arrival along the path.
Is that even possible ? I know it is with Google Map, but you can program it with Javascript, which eases things a lot.
This is an old question, and there is now a better way to move a placemark (or even better a model) along a pre-determined linestring. Look into using this feature:
http://code.google.com/apis/kml/documentation/kmlreference.html#gxtrack
Sample code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2">
<Folder>
<Placemark>
<gx:Track>
<when>2010-05-28T02:02:09Z</when>
<when>2010-05-28T02:02:35Z</when>
<when>2010-05-28T02:02:44Z</when>
<when>2010-05-28T02:02:53Z</when>
<when>2010-05-28T02:02:54Z</when>
<when>2010-05-28T02:02:55Z</when>
<when>2010-05-28T02:02:56Z</when>
<gx:coord>-122.207881 37.371915 156.000000</gx:coord>
<gx:coord>-122.205712 37.373288 152.000000</gx:coord>
<gx:coord>-122.204678 37.373939 147.000000</gx:coord>
<gx:coord>-122.203572 37.374630 142.199997</gx:coord>
<gx:coord>-122.203451 37.374706 141.800003</gx:coord>
<gx:coord>-122.203329 37.374780 141.199997</gx:coord>
<gx:coord>-122.203207 37.374857 140.199997</gx:coord>
</gx:Track>
</Placemark>
</Folder>
</kml>
The only way I've been able to make this work in static KML is to interpolate between the start and stop points and add placemarks for each frame I want to animate. So, from t=0 to t=1, draw a placemark at the start point. From t=1 to t=2, draw a placemark at the next point, etc.
This gives you the temporal player bar in Google Earth and you can rewind or advance the animation. However it is a little annoying because you wind up with every interpolation point in your placemark tree. Putting the placemarks in their own folder keeps them out of the way, but there's no way to hide them from the user.
Take a look at http://code.google.com/apis/kml/documentation/time.html#animating
The whale shark example does more or less what you want for the placemark. (The URL for the marker icon is broken). Animating the progress along the track can be done using the same trick.
If you want to try something much more difficult, you can try serving dynamic KML. Have Google Earth load a network link to your initial data. Then load another network link with an that sends an update for your placemark at every time tick.
http://code.google.com/apis/kml/documentation/kmlreference.html#link
http://code.google.com/apis/kml/documentation/updates.html
This approach has some serious disadvantages because it requires an external program to drive Google Earth and it does not give the user access to the built-in Google Earth temporal player bar. It also requires that all the data be loaded over a network link -- KML data from a file cannot be updated. That means your driver program needs to act as a http server. Also, in this model it is very hard to know exactly when Google Earth has finished loading and drawing the update. Really I don't recommend doing this; you can make it work using the Google Earth COM API, but it will always be a fragile solution.
There's a browser plug-in that lets you embed Google Earth into a browser page. From there you can use JavaScript to animate your placemark, change your paths, etc. Check out the Google Earth API Developer's Guide.
If you are going to display a boat on Google Earth, a 3D model would be a better approach then an image, since the users can change the viewing angle.
You might want to look into tours: http://code.google.com/apis/kml/documentation/touring.html
I've seen something like this done using a combination of (a number of) <gx:AnimatedUpdate> tags to move a previously created placemark representing your boat and <gx:FlyTo> tags to move the view (I think) all within a <gx:Playlist>.
Hope this helps.
I'm presuming this functionality did not exist when originally answered, but you can achieve the effect using a tour. The following shows a placemark moving in this fashion.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document>
<Placemark id="boat">
<Point>
<coordinates>0,0</coordinates>
</Point>
</Placemark>
<gx:Tour>
<name>Play me!</name>
<gx:Playlist>
<gx:FlyTo>
<gx:duration>5.0</gx:duration>
<LookAt>
<longitude>0</longitude>
<latitude>0</latitude>
<altitude>0</altitude>
<heading>-95</heading>
<tilt>65</tilt>
<range>250000</range>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
</gx:FlyTo>
<gx:AnimatedUpdate>
<gx:duration>5.0</gx:duration>
<Update>
<targetHref/>
<Change>
<Placemark targetId="boat">
<Point>
<coordinates>1,1</coordinates>
</Point>
</Placemark>
</Change>
</Update>
</gx:AnimatedUpdate>
<gx:Wait>
<gx:duration>6.0</gx:duration>
</gx:Wait>
</gx:Playlist>
</gx:Tour>
</Document>
</kml>
The path could be marked with points whose visibility is altered by the tour at the appropriate time.
I have following sample in Google site. Hope this help.
(details inside : https://sites.google.com/site/canadadennischen888/home/kml/auto-refresh-3d-tracking)
prepare a RestFul service to generate KML file from DB
(sample as in https://sites.google.com/site/canadadennischen888/home/kml/3d-tracking)
My other code will generate a KMZ file which has a link to my Restful service
(sample as in this page)
KMZ file has onInterval
Web page allow user to download KMZ file which has URL that link to my Restful service
When Google Earth open KMZ file, Google Earth will auto refresh to get new data from that Restful service
Just google for "kml time animation"
KML: Time and Animation
KML: Animation
Animation and Dynamic Updates with KML