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.
精彩评论