views:

148

answers:

3

I have added a kml to google earth by use of button with javascript. How can I delete that kml or clear all kml's by use of another button? thanks

+1  A: 

Do you mean you added a KML file? I guess you did this by adding a "network link" using functions like

var networkLink = ge.createNetworkLink('ID_MyNetworkLink');
var link = ge.createLink('MyHREF');
link.setHref('http://bla.bla.bla.kml');
networkLink.setLink(link);
ge.getFeatures().appendChild(networkLink);

So your "file" is a child of the whole KML tree with id "ID_MyNetworkLink". You can remove it by

ge.getFeatures().removeChild(ge.getElementById('ID_MyNetworkLink'));

Hope that helps

MikeD
A: 

Though not quite what you are likely looking for you can have a NetworkLink that loads kml with a NetworkLinkController change things. Check out the docs.

Adam
A: 

To remove all the features you can use the following method. It presumes that 'ge' references your plug-in object.

function RemoveAllFeatures()
{
  var features = ge.getFeatures();
  while (features.getLastChild() != null)
  {
    features.removeChild(features.getLastChild());
  }
}
Fraser