2

所以我想要做的是替换加载到 Web 浏览器中的 Google Earth GEPlugin 实例中的主数据库。如果我去代码游乐场:这里 http://code.google.com/apis/ajax/playground/#mars/alternate_server_connectivity

然后我得到一个加载新数据库的例子。但是,如果我尝试多次调用 CreateInstance,我会一直获取相同的数据库(我猜这是由于在后台运行的 GEPlugin.exe 仍在使用第一个数据库。如果我通过杀死 geplugin 来删除该实例.exe 进程然后加载工作)

在该示例代码页上编辑 HTML,我使用了以下 html/script 组合

    <!--
You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Earth API Sample</title>
    <script src="http://www.google.com/jsapi?key=ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG7Djw" type="text/javascript"></script>
    <script type="text/javascript">
    var ge;

    google.load("earth", "1");

    function init() {
      google.earth.createInstance('map3d', initCallback, failureCallback,
        { database: 'http://khmdb.google.com/?db=mars' });

    }

    function initCallback(instance) {
      ge = instance;
      ge.getWindow().setVisibility(true);

      // add a navigation control
      ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

      document.getElementById('installed-plugin-version').innerHTML =
        ge.getPluginVersion().toString();
    }

    function failureCallback(errorCode) {
    }
     function loadmoon()
      {
        delete ge;
        google.earth.createInstance('map3d', initCallback, failureCallback, { database: 'http://khmdb.google.com/?db=moon' });
        //http://khmdb.google.com/?db=moon
      }

    </script>
  </head>
  <body onload="init()" style="font-family: arial, sans-serif; font-size: 13px; border: 0;">
    <div id="map3d" style="width: 500px; height: 380px;"></div>
    <br>
    <a href="" onclick="loadmoon()">LOAD THE MOON</a>
    <div>Installed Plugin Version: <span id="installed-plugin-version" style="font-weight: bold;">Loading...</span></div>

  </body>
</html>

这样做的原因是它重新加载了实例,但它不会更改数据库。

我应该说我知道添加辅助数据库的选项,但是如果我尝试加载辅助数据库,地形仍然映射到第一个数据库的地形。对我来说这是不可接受的。

4

1 回答 1

1

在再次创建实例之前,将 'map3d' 的 innerHTML 设置为空字符串。

function loadmoon(){
    document.getElementById('map3d').innerHTML = '';
    google.earth.createInstance('map3d', initCallback, failureCallback, { database: 'http://khmdb.google.com/?db=moon' });
}

看看这个例子,应该正是你所需要的。http://earth-api-samples.googlecode.com/svn/trunk/examples/alternate-spheres.html

于 2012-08-03T16:29:39.620 回答