javascript - 在 Google 地球中加载/刷新 3d 模型

标签 javascript internet-explorer google-earth

我在 Web 开发 中使用 Google Earth 但我遇到了一个奇怪的情况,这是来自 google code playground 的一个简单代码,它加载了一个3D 模型 到谷歌地球,如果我刷新页面,它不会再次加载模型, http://savedbythegoog.appspot.com/?id=7f8638b214605a2327af223c613a6ae13874416b

有什么办法可以解决吗

我在 32 位 XP 机器的 Internet Explorer 8 中加载 3D 模型时遇到了另一个问题,IE8 不会在 google earth 中加载 3d 模型,您可以查看链接给出。我还在下面发布 js 代码。

请帮忙

<!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">
  function addSampleButton(caption, clickHandler) {
    var btn = document.createElement('input');
    btn.type = 'button';
    btn.value = caption;

    if (btn.attachEvent)
      btn.attachEvent('onclick', clickHandler);
    else
      btn.addEventListener('click', clickHandler, false);

    // add the button to the Sample UI
    document.getElementById('sample-ui').appendChild(btn);
  }

  function addSampleUIHtml(html) {
    document.getElementById('sample-ui').innerHTML += html;
  }
</script>
<script type="text/javascript">
var ge;

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

function init() {
  google.earth.createInstance('map3d', initCallback, failureCallback);

 // addSampleButton('Create a 3D Model!', buttonClick);
}

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

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

  // add some layers
  ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);

  var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
  la.setRange(100000);
  ge.getView().setAbstractView(la);

  create3dModel();

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

function failureCallback(errorCode) {
}

function create3dModel() {
  // Create a 3D model, initialize it from a Collada file, and place it
  // in the world.

  var placemark = ge.createPlacemark('');
  placemark.setName('model');
  var model = ge.createModel('');
  ge.getFeatures().appendChild(placemark);
  var loc = ge.createLocation('');
  model.setLocation(loc);
  var link = ge.createLink('');

  // A textured model created in Sketchup and exported as Collada.
  link.setHref('http://earth-api-samples.googlecode.com/svn/trunk/examples/' +
               'static/splotchy_box.dae');
  model.setLink(link);

  var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
  loc.setLatitude(la.getLatitude());
  loc.setLongitude(la.getLongitude());

  placemark.setGeometry(model);

  la.setRange(300);
  la.setTilt(45);
  ge.getView().setAbstractView(la);
}

function buttonClick() {
  create3dModel();
}

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

如果该链接不起作用,请复制代码并将其粘贴到文本文件中并将其重命名为 .html,然后执行。

最佳答案

即使我在使用 collada 模型和 Internet Explorer 时遇到过同样的问题,您提供的代码在 chrome 和 mozilla 等其他浏览器中也能正常工作。

查看 this link ,但在这种情况下,他们正在加载一个 kml 文件,而不是使用 javascript 直接将 collada 模型加载到浏览器中。

关于javascript - 在 Google 地球中加载/刷新 3d 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14683040/

相关文章:

javascript - 如何计算Google Earth Engine中分类图像(Landsat)中每个类别的像素总和?

javascript - Eclipse 不断跳转到文档的开头

python-2.7 - 如何使用python将kml文件加载到谷歌地球

javascript - 第二次加载后运行函数

html - 在 IE 中单击选择标签时选择突出显示

javascript - YouTube 播放器 Internet Explorer 故障

html - 如何防止在 IE 中出现而在 Firefox 中不出现的页面闪烁?

KML 网络链接 - 飞到

javascript - div 中的 slider 类不显示图像,但它在元素中

javascript - Semmle CodeQL CLI : "QL dataset is not compatible with the QL"