如何将动态kml添加到谷歌地球?

发布于 2024-12-21 03:24:40 字数 816 浏览 7 评论 0原文

我们正在尝试向 Google Earth 添加动态 KML。但在一种情况下我们失败了。

代码:

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

当我们点击按钮时,我们正在调用loadkmlGE()函数。我们能够在谷歌地球上第一次获取kml。如果我们第二次点击,那么我们就可以了谷歌地球上没有获取kml。但是test.kml文件正在更新新值。那么,我们如何从谷歌地球中删除kml?

如有帮助,将不胜感激。

We are trying to add dynamic kml to google earth.But we are failing in one situation.

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?

Help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柒夜笙歌凉 2024-12-28 03:24:40

fetchKml 我相信使用浏览器来获取文件。除非另有说明,它通常会缓存文件。

您可以安排服务器使用 HTTP 标头告诉浏览器它无法缓存该文件。取决于您的服务器如何设置。

...或者只是安排每次更改的网址。

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

或类似的。服务器很可能会忽略伪造的参数。但由于 URL 已更改,浏览器将不会有缓存版本。

fetchKml I beleive uses the browser to fetch the file. 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. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文