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.
flyto
is enabled so the view moves the first first placemark, etc, in MyFlyTo.kmlUpdate
in TurnOffFlyTo.kml three disables flyto
in MyFlyToRequest.kml.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With