简体   繁体   中英

Clear a kml that was added to google earth using javascript

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

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());
  }
}

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM