简体   繁体   English

如何将动态kml添加到Google Earth?

[英]how to add dynamic kml to google earth?

We are trying to add dynamic kml to google earth.But we are failing in one situation. 我们正在尝试向Google Earth添加动态kml。但是在一种情况下我们失败了。

CODE: 码:

var currentKmlObject = null;
function loadkmlGE(){
     if (currentKmlObject != null) {
            ge.getFeatures().removeChild(currentKmlObject);
            currentKmlObject = null;
          }

    var url = 'test.kml';
    google.earth.fetchKml(ge, url, finished);
    }

function finished(kmlObject) {
      if (kmlObject) {
        currentKmlObject = kmlObject;
        ge.getFeatures().appendChild(currentKmlObject);
      } else {
        setTimeout(function() {
          alert('Bad or null KML.');
        }, 0);
      }
    }

When we click on button we are calling loadkmlGE() function.We are able to get the kml first time on google earth.If we click second time then we are not getting kml on google earth.But test.kml file is updating new values.So, how we can remove the kml from google earth? 当我们点击按钮时,我们调用loadkmlGE()函数。我们能够在Google Earth上第一次获取kml。如果我们第二次单击,那么我们就不在Google Earth上获取kml。但是test.kml文件正在更新新值.so,我们如何从Google Earth中删除kml?

Help would be appreciated. 帮助将不胜感激。

fetchKml I beleive uses the browser to fetch the file. fetchKml我beleive使用浏览器来获取文件。 It will generally cache the file unless told otherwise. 除非另有说明,否则它将通常缓存文件。

You could arrange for the server to tell the browser it cant cache the file - using HTTP headers. 您可以安排服务器告诉浏览器它无法缓存文件 - 使用HTTP标头。 depends on your server how to set that up. 取决于您的服务器如何设置。

... or just arrange the url to change each time. ...或者只是安排每次更改的网址。

var url = 'test.kml?rnd='+Math.random();

or similar. 或类似的。 The server will likly ignore the bogus param. 服务器可能会忽略伪造的参数。 But as the URL has changed the browser wont have a cached version. 但是,由于URL已更改,浏览器将不会有缓存版本。

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

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