Question

In my KML I have an aggregate of placemarks in a table format. When you click the placemark you can see all the placemarks currently being loaded. Each of the placemarks have an id like below

<Placemark id="Location1">

When I add the following below I am able to fly to that balloon and it will open. However in the API this function does not work. It tries to do the following http://www.something.com#ballooonFlyTo is there a way to allow the balloon fly to method in the API?

<a href="#Location1;balloonFlyto>Location 1</a>
Was it helpful?

Solution

Not directly no, but it would be easy to modify your links to call a custom function that will support the behavior you require.

Also, if you are loading your features via kml rather than creating them programmatically then you would need to supply the full path to the kmlFeature - not just its ID. i.e.

http://somesite.com/my.kml#Location1 rather than just #Location1 - where http://somesite.com/my.kml is the file that defines the feature with the id Location1.

If you have something like the following javascript method it should work as expected. That is it will fly to the view and open a feature balloon. (This is presuming ge is the google earth plugin in your application and that the placemarks have abstract views defined).

// Attempts to find and element by ID,
// fly to its abstract view and open a feature balloon for it.
var flyto = function(id) {
  var placemark = ge.getElementByUrl(id);
  if(!placemark) {
    return false;
  }

  if (placemark.getAbstractView()) {
   ge.getView().setAbstractView(placemark.getAbstractView());
  }

  var content = placemark.getBalloonHtmlUnsafe(); // or getDescription()
  var balloon = ge.createHtmlStringBalloon('');
  balloon.setFeature(placemark);
  balloon.setContentString(content);
  ge.setBalloon(balloon);

  return false;
};

Then you can simply modify your links to call the flyto function passing the desired id. e.g.

<a href="javascript:flyto('http://somesite.com/my.kml#Location1');">Location 1</a>

If your placemarks do not have abstract views, then you would have to do something like extracting the point geometry and then create a lookat or camera using the latitude and longitude data to set the view.

EDIT

I decided that this functionality was really cool, so I have put together an example that does not require any special mark up of the links at all. When kml links containing a command are clicked the plugin behaves just like the full Google Earth Client would.

Here is a fully working example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top