1
votes

In the GE Plugin API GEHelper.cs there is a function FlyToObject. Since I've been unable to get the kml to fly me to a placemark I thought I would use the API call.

The required arguments for FlyToObject are: "dynamic ge," "dynamic feature,"

I'm stuck on what the 'feature' argument is. The description says "the api object". I'm not sure which api object that is referring to or how to create it.

What I'm trying to do is automatically (upon loading the file) "fly to" a placemark in my kml file.

If anyone knows how to do what I'm asking with KML that would be great. Here is the KML file I'm loading that does NOT work. This is one of Google's example files.

<kml xmlns="http://www.opengis.net/kml/2.2">
    <Placemark>
      <name>300m straight down</name>
      <Camera>
        <longitude>-122.4783</longitude>
        <latitude>37.812</latitude>
        <altitude>300</altitude>
        <heading>0</heading>
        <tilt>0</tilt>
        <roll>0</roll>
        <altitudeMode>absolute</altitudeMode>
      </Camera>
    </Placemark>
</kml>

THANKS!

1
how are you loading the kml file? - Matt

1 Answers

0
votes

If you are loading Google Earth into your own webpage, you have access to the GE API via javascript. Therefore if you want to set a certain view, use the following code

      // Create a new LookAt.
      var lookAt = ge.createLookAt('');

      // Set the position values.
      lookAt.setLatitude(36.584207);
      lookAt.setLongitude(-121.754322);
      lookAt.setRange(5000.0); //default is 0.0

      // Update the view in Google Earth.
      ge.getView().setAbstractView(lookAt);

More advanced: If you are loading a custom kml file, with your own Placemarks. Assign them as id as such in your kml file

      <Placemark id="uniqueId">

Then, once loaded, use this code

       placemark = ge.getElementById(uniqueId);
       if (placemark == null) {
            return false;
       } else if (placemark.getAbstractView()) {
            ge.getView().setAbstractView(lastViewLoaded);
      }