是否有办法让谷歌地球插件做以下工作时,网页加载?
我可以分别做上面的#1或#2,但是我想不出如何让它们在网页加载时发生。
发布于 2013-02-26 01:19:36
您可以使用fetchKml方法简单地在google.earth命名空间中加载两个文件。然后,您可以提供处理显示数据和在回调参数中输入浏览的逻辑。
要进行巡演,您必须遍历Kml,查找KmlTour对象,以便可以使用GETourPlayer打开它。要做到这一点,您可以使用地球效用库,也可以使用kmldomwalk.js脚本。
类似于下面的java脚本应该可以工作(尽管它是在这里编写的,而且还没有经过测试)。
<script src="//www.google.com/jsapi/"></script>
<script src="//earth-api-samples.googlecode.com/svn/trunk/lib/kmldomwalk.js"></script>
<script>
google.load("earth", "1");
var ge = null;
var kml1= '//www.ppacg.org/tours/logo.html';
var kml2= '//www.ppacg.org/tours/tabview.html?project=08-37';
var tour = null; // so you can call pause, stop, etc globally...
function init() {
// presumes you have a div with the id 'map3d'
google.earth.createInstance("map3d", initCallback, function(e){alert(e);});
}
function initCallback(object) {
ge = object;
ge.getWindow().setVisibility(true);
// load your data
google.earth.fetchKml(ge, kml1, fetchKmlCallback);
google.earth.fetchKml(ge, kml2 , fetchKmlCallback);
}
function fetchKmlCallback(object) {
if (object) {
// add the features to the plugin
ge.getFeatures().appendChild(object);
// Walk the DOM looking for a KmlTour
walkKmlDom(object, function() {
if (this.getType() == 'KmlTour') {
tour = this;
ge.getTourPlayer().setTour(tour); // enter the tour
return false; // stop the DOM walk here.
}
});
} else {
setTimeout(function() {
alert('Bad or null KML.');
}, 0);
}
}
google.setOnLoadCallback(init);
</script>如果您陷入困境,还可以查看这些使用取和游玩的示例。
https://stackoverflow.com/questions/15059231
复制相似问题