【问题标题】:Google Earth Plugin: first load static .kmz, then play tour .kmz?谷歌地球插件:先加载静态.kmz,然后玩游.kmz?
【发布时间】:2013-02-25 02:32:19
【问题描述】:

有没有办法让 Google 地球插件在网页加载时执行以下操作?

  1. 显示静态 .kmz 文件,如http://www.ppacg.org/tours/logo.html
  2. 启动巡回播放器.kmz,如http://www.ppacg.org/tours/tabview.html?project=08-37

我可以分别执行上面的 #1 或 #2,但我不知道如何让它们在网页加载时同时发生。

【问题讨论】:

    标签: javascript kml google-earth google-earth-plugin kmz


    【解决方案1】:

    您可以使用google.earth namespace 中的fetchKml 方法简单地加载这两个文件。然后,您可以提供逻辑来处理显示数据并在回调参数中输入游览。

    要玩游览,您必须在 Kml DOM 中寻找KmlTour 对象,以便您可以使用GETourPlayer 打开它。为此,您可以使用earth utility library,或者您也可以使用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>
    

    如果遇到困难,还可以看看这些使用 fetchkmlplaying tours 的示例。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多