KML Network Link - Fly To - kml

I am developing an application that launches Google Earth with a KML file that links to other local files via <NetworkLink>, which does Time Interval refreshing. I'm trying to define a KML file that will center the map (fly to) a specific location.
Network Link has a tag which flies to the first placemark or FlyTo within the file. However, this would execute the fly to whenever the file is refreshed, which in my case, is when the Time Interval expires. Is there some way that I can have the fly-to command execute only when the linked network file changes, rather than every time? Is there any way to have the Fly To process only once until the linked file is changed somehow? My NetworkLink file is defined as follows:
<NetworkLink>
<name>My Fly To Request</name>
<Link>
<href>MyFlyTo.kmz</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>2</refreshInterval>
</Link>
</NetworkLink>
The application will frequently update the the specific placemark to be centered on when the user requests. It is not a static placemark that needs to be centered on, but one that will change frequently.

I believe you could achieve this by using a combination of ID attributes and the NetworkLinkControl and Update element in Kml.
The MyFlyToRequest.kml file contains the NetworkLink that loads the data file, which contains your data, it has the flyToView element set to true. Notice too the network link also has an id of request
MyFlyToRequest.kml
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLink id="request">
<name>My Fly To Request</name>
<Link>
<href>http://www.yourserver.com/MyFlyTo.kmz</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>2</refreshInterval>
</Link>
<flyToView>1</flyToView>
</NetworkLink>
</kml>
The second file, MyFlyTo.kmz, is the one loaded. It has your current data as is..,However, it would also have an additional NetworkLink that loads a new third file.
MyFlyTo.kmz - Edited
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="data">
<visibility>1</visibility>
<NetworkLink>
<name>Update MyFlyToRequest</name>
<Link>
<href>http://www.yourserver.com/TurnOffFlyTo.kml</href>
</Link>
</NetworkLink>
<Placemark>
<name>This is flown to once (hopefully)</name>
<Point>
<coordinates>52,0,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
The new third file TurnOffFlyTo.kml is part of the key to the set up, it contains a NetworkLinkControl that targets the request NetworkLink in the first MyFlyToRequest.kml file. It simply sets flyToView element to 0.
TurnOffFlyTo.kml
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLinkControl>
<Update>
<targetHref>http://www.yourserver.com/MyFlyToRequest.kml#request</targetHref>
<Change>
<NetworkLink id="request">
<!-- turn off the flyto behaviour -->
<flyToView>0</flyToView>
</NetworkLink>
</Change>
</Update>
</NetworkLinkControl>
</kml>
The final file TurnOnFlyTo.kml simply retoggles the flyto behaviour again.
TurnOnFlyTo.kml
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLinkControl>
<Update>
<targetHref>http://www.yourserver.com/MyFlyToRequest.kml#request</targetHref>
<Change>
<NetworkLink id="request">
<!-- turn off the flyto behaviour -->
<flyToView>1</flyToView>
</NetworkLink>
</Change>
</Update>
</NetworkLinkControl>
</kml>
The logic is as follows.
MyFlyToRequest.kml loads MyFlyTo.kml
flyto is enabled so the view moves the first first placemark, etc, in MyFlyTo.kml
The link in MyFlyTo.kml loads TurnOffFlyTo.kml.
The Update in TurnOffFlyTo.kml three disables flyto in MyFlyToRequest.kml.
File one, refreshes, loads file two...
If you need to re-enable the flyto, you would simply load File four. If the data in MyFlyTo.kmz is being generated by you it would be a simple case of loading TurnOnFlyTo.kml right where TurnOffFlyTo.kml was called.
All that said, this is not tested and as such might not work as is, although in principal I don't see why it wouldn't.
If it sounds like something you might try here are a few resources that should help.
NetworkLinkControl Reference
http://code.google.com/apis/kml/documentation/kmlreference.html#networklinkcontrol
Using Updates
http://code.google.com/apis/kml/documentation/updates.html

Related

Network Linked KML to a Folder of KMLs

Using the below format as starting point I would like to know how to solve the following problem. This is an example for a Root KML file that links to other KMLs. My problem is that people modifying sub1.kml might change the name from sub1.kml to sub1-05-OCT-16.kml or want to add another KML called sub1-a.kml. Once this occurs the network link is no longer valid. I can't link to a folder from what I have seen and I do not want o have to change this file everytime. Is there an esiaer solution I'm overlooking?
<?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>
A network link must point at a specific KML (or KMZ) file. Unfortunately there's no way to point it at a folder or directory and somehow get the list of files and pick out all the KML/KMZs. So you'll need to either make sure that the target file names stay the same, or update your NetworkLinks when they change.

Placemarks lookat range ignored

I'm using this KML file (lets call it load.kml)
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<NetworkLink>
<refreshVisibility>1</refreshVisibility>
<flyToView>1</flyToView>
<Link> <href>C:\\Users\\bridenstinek\\workspace\\AlertServlet\\resources\\outboundKML\\test.kml</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>20</refreshInterval>
</Link>
</NetworkLink>
</Document>
</kml>
To point Google Earth to a kml file (lets call it test.kml). When I load test.kml regularly (without using load.kml) the range I set works correctly (the zoom level is how I set it).
But when test.kml gets loaded using load.kml the range is incorrect. The placemark zooms in really far and ignores the range I set in the test.kml file.
Is there something overriding the range inside load.kml?
Example of test.kml:
<?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" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:location="http://example.com">
<Document>
<name>Example</name>
<Style id="alertKMLStyle">
<BalloonStyle>
<text><![CDATA[<center>
<b><font color="#CC0000" size="+8">$[name]</font></b>
<br/></center><br/>
<font size="+2">$[description]</font>
<br/><br/>
]]></text>
</BalloonStyle>
</Style>
<Placemark>
<name>Example Name</name>
<description>Example Description</description>
<LookAt>
<location:coordinates>800</location:coordinates>
<longitude>2.294</longitude>
<latitude>48.858</latitude>
<altitude>0.5</altitude>
<heading>12.23742976490019</heading>
<tilt>0</tilt>
<range>115718.4889366544</range>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#alertKMLStyle</styleUrl>
<gx:balloonVisibility>1</gx:balloonVisibility>
<Point>
<gx:drawOrder>1</gx:drawOrder>
<coordinates>2.294,48.858,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
There are a few undocumented differences when you load KML directly as opposed to via a NetworkLink.
When you load the KML via the NetworLink it looks for a LookAt or Camera in the outermost element which is the Document in test.kml file.
You can either 1) copy/move the <LookAt> from the Placemark to the parent Document element in test.kml or 2) copy the <LookAt> and insert into the NetworkLink in load.kml and make flyToView=0.
If the target KML has timestamps then the behavior via Networklinks is different then loading it directly. See related issue.

kml gx track dynamic update from real time data

I want to get coordinates every second and update the track on google earth in the kml file
I know i need a network link with an update that is added coordinates with the time and refresh it every second but i couldn't find any complete examples that show this and the update part is confusing me. I was wondering if someone could write out a simple example?
If you want to generate KML and update on a regular interval then you create a root KML such as this:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLink>
<name>NetworkLink example</name>
<Link>
<href>http://...</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>5</refreshInterval>
</Link>
</NetworkLink>
</kml>
If your area of interest is a "small" or locallized then you may want to add a Region to the NetworkLink and viewRefreshMode element with onRegion value to only refresh when the region is active (e.g., within the current view).
<NetworkLink>
<name>NetworkLink example with Region</name>
<Region>
</Region>
...
<Link>
<href>http://...</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>5</refreshInterval>
<viewRefreshMode>onRegion</viewRefreshMode>
</Link>
</NetworkLink>
For NetworkLinkControl a tutorial can be found here with a working example.
https://developers.google.com/kml/documentation/updates

How to create Google Earth KML network link that does not allow folder to be expanded

I have created a network link that references another KML file with actual data to be loaded into Google Earth. My issue is that the number of points in the referenced KML file is so large that it crashes Google Earth if the KML file folder underneath the Places tab in Google Earth is set to "Allow this folder to be expanded" (right-click KML, properties). By default, this checkbox is checked. I want to make it so that for every network link I create the folder by default will not be expandable.
I have looked up checkHideChildren in Google Earth KML tutorials, but that line provides no results, and I am not entirely sure where I am supposed to place the line in the Network Link KML.
Here is example code, if you could point me in the direction where to place this line of code, or an entirely different approach, it would be greatly appreciated!
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<NetworkLink>
<name>
CPU
</name>
<refreshVisibility>1</refreshVisibility>
<Link id="GPS_Plotter Updater">
<href>CPU.kml</href>
<Style id="style1"><ListStyle>
<listItemType>checkHideChildren</listItemType> <-- this is the line that should be hiding the children points of the KML!
</ListStyle>
</Style>
<styleUrl>#style1</styleUrl>
<refreshMode>onInterval</refreshMode>
<refreshInterval>1</refreshInterval>
<viewRefreshMode>onRegion</viewRefreshMode>
<viewRefreshTime>1</viewRefreshTime>
</Link>
</NetworkLink>
</kml>
Try putting the Style element in the NetworkLink, not the Link element. Link doesn't take a style selector, but NetworkLink does. If that doesn't work, try a listItemType of radioFolder instead.
In addition to Mano Marks' suggestions you also need to move the styleUrl element to the NetworkLink otherwise it won't apply. Note in your example you have viewRefreshMode=onRegion but don't have a region defined for it.
Here's the complete working example to suppress the NetworkLink contents.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLink>
<name>CPU</name>
<styleUrl>#style1</styleUrl>
<Style id="style1">
<ListStyle>
<listItemType>checkHideChildren</listItemType>
</ListStyle>
</Style>
<Region>
<!-- define region here -->
</Region>
<refreshVisibility>1</refreshVisibility>
<Link id="GPS_Plotter_Updater">
<href>CPU.kml</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>1</refreshInterval>
<viewRefreshMode>onRegion</viewRefreshMode>
<viewRefreshTime>1</viewRefreshTime>
</Link>
</NetworkLink>
</kml>
You can catch errors like this by validating your KML. Try using the Galdos KML Validator.

Load a kml file periodically to update position in google earth

I want to load a kml file every 10 seconds with google earth, I found this example http://ukhas.org.uk/code:kml_live_update but it seems it does not work.
<?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>
It does not load every10.kml, even I tried a kml file over internet (http://code.google.com/apis/kml/documentation/Point.kml )
The code you provided from the example is valid, but the link reference (href) is incorrect. You should try inserting a full URL, and it will work. Using the Point.kml file you provided, the working code should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<NetworkLink>
<Link>
<href>http://code.google.com/apis/kml/documentation/Point.kml</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>10</refreshInterval>
</Link>
</NetworkLink>
</Document>
</kml>
First - it is working example.
You must specify full link to your kml file.
In my version GE this NetworkLink update every 10 sec. In your case, for refresh view (and new update kml), you may try to setup settings in Google Earth. On context menu on subelement of kml file (NetFolder icon), you may choose Refresh tab (maybe other name - i have language differen from English) and choose 10 sec interval.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<NetworkLink>
<Link>
<href>every10.kml</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>10</refreshInterval>
</Link>
</NetworkLink>
</kml>
Worked for me:
load.kml
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<NetworkLink>
<Link>
<href>C:\Users\loran\kml\every10.kml</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>10</refreshInterval>
</Link>
</NetworkLink>
</Document>
</kml>
Just make sure you have a full path in your href
It is loading but doesn't zoom in where the point is so it looks like its not working. The real problem is loading point continuoulsy with zoom to that particular region

Resources