简体   繁体   English

加载/卸载onClick Javascript

[英]Load/Unload onClick Javascript

I have a code that was answered for me in another post which is below. 我在下面的另一篇文章中回答了我的代码。 However I have since ran into a new problem that I can't solve easily. 但是从那以后,我遇到了一个我不容易解决的新问题。 I added additional LoadKML functions eg Function LoadKML1(), function LoadKML2(). 我添加了其他LoadKML函数,例如Function LoadKML1(),LoadKML2()函数。 The problem is now I need to click the killKML button to clear LoadKML1 before I can click LoadKML2. 现在的问题是,我需要先单击killKML按钮以清除LoadKML1,然后才能单击LoadKML2。 I would like to have the LoadKML1 clicked to load the KML and if clicked again LoadKML1 to run the killKML code. 我想单击LoadKML1以加载KML,如果再次单击LoadKML1以运行killKML代码。 basically an on and off button in essence. 本质上基本上是一个开和关按钮。

Any help is appreciated. 任何帮助表示赞赏。

var kmlLoaded = false;

function LoadKML() {
    alert('Kill KML');
        if (kmlLoaded) {
        return
            killKML();
        }else{
            alert('Creating KML');
            var nwlink = "http://kml-samples.googlecode.com/svn/trunk/kml/NetworkLink/placemark.kml"
            createNetworkLink(nwlink);
            kmlLoaded=true;
        }
}

function killKML(source) {
    ge.getGlobe().getFeatures().removeChild(networkLink);

you could change your code and call the killKML() in the kmlLoaded check like this: 您可以更改代码并在kmlLoaded检查中调用killKML(),如下所示:

function LoadKML() {
    if (kmlLoaded) {
        //return
        killKML();
    }else{
        var newlink = "http://www.something.com/test.kml";
        createNetworkLink(newlink);
        kmlLoaded=true;
    }
}

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

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