简体   繁体   English

清除使用JavaScript添加到Google Earth的kml

[英]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. 我通过使用带有javascript的按钮向Google Earth添加了kml。 How can I delete that kml or clear all kml's by use of another button? 如何使用另一个按钮删除该kml或清除所有kml? thanks 谢谢

To remove all the features you can use the following method. 要删除所有功能,可以使用以下方法。 It presumes that 'ge' references your plug-in object. 假定“ ge”引用您的插件对象。

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

Do you mean you added a KML file? 您是说您添加了KML文件吗? 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". 因此,您的“文件”是ID为“ ID_MyNetworkLink”的整个KML树的子级。 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. 尽管不是很可能找到您想要的东西,但是可以让NetworkLink加载带有NetworkLinkController的kml来更改内容。 Check out the docs . 查看文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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