how to add dynamic kml to google earth?

随声附和 提交于 2020-01-24 19:21:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8500401/how-to-add-dynamic-kml-to-google-earth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!