5

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!

user1710277
  • 61
  • 2
  • 3

2 Answers2

3

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>
John Horstkamp
  • 87
  • 1
  • 1
  • 10
  • I never thought of this approach, can you explain the benefits of using two daisy-chained links instead of just one? – user1710277 Jun 27 '13 at 17:53
  • The "inner link" (network link file that points to your updating kml file) refresh interval is set to a shorter interval than the "outer link" (network link file that points to the inner link kml file). – John Horstkamp Jul 02 '13 at 14:00
  • If the inner link stalls (presumably while trying to refresh when your data kml file updates), the outer link will (eventually) trigger a refresh via the inner link. – John Horstkamp Jul 02 '13 at 14:05
  • Currently I would *like* for my KMLs to update every 1 second, but for this method, would I need to change my outer network link to say 5-10 seconds, and the inner one remains 1 second? In the end, this would drop down my refresh rate to once every 5-10 seconds right? – user1710277 Jul 12 '13 at 00:54
  • As I understand - and have seen work with our stuff - your inner link will still refresh at the original interval -one second in your case - and the outer link will (re)trigger the inner link at whatever rate you set it to. I don't know the size of your data set, but a 1 second refresh period coupled with a 5-10 second refresh period seem a bit close together to me. – John Horstkamp Jul 15 '13 at 15:29
  • Oh okay, if it works like that then that would be perfect. Our data set is pretty huge and we receive a real-time update every second. I envisioned having an outer refresh period that would be similar to the time it would take for us to right click the network link in Google Earth and hit "refresh now". Do you think this is not really feasible? Thanks for your replies, I really appreciate your expertise and the time you're taking to help me out! – user1710277 Jul 16 '13 at 01:01
  • No problem - hopefully all this is useful or helpful. Google doesn't seem to be too forthcoming for developers who need a deeper understanding of how their stuff works...although these sites can be helpful https://groups.google.com/forum/#!forum/kml-support note that a recent post states that they've moved support forums for KML to Stack Overflow... As far as your refresh rates are concerned, since I don't know the real details of your system, what you propose sounds reasonable, although experimentation will yield a better answer... – John Horstkamp Jul 23 '13 at 14:17
  • I can't get this to work. I'm finding that the "KML File 2", the outer KML file that is a link to another network link, doesn't actually refresh the "inner link" because file 1 never changes. – Stealth Rabbi Aug 09 '13 at 12:43
0

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:

  1. write temp file temp.kml
  2. delete target.kml
  3. 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.

CodeMonkey
  • 22,825
  • 4
  • 35
  • 75
  • I already implemented that system, and while it reduced the probability of fetching during swap, it still happens... – user1710277 Mar 03 '13 at 22:03