javascript - 如何加载放大而不是从太空开始的谷歌地球 map ?

标签 javascript geospatial google-earth-plugin

从我的网站加载 Google Earth API 时,我有一个设置 View 开始,但它从空间开始然后放大,而不是从这个放大的 View 开始。这对观众来说很奇怪,特别是因为我的视角是从北向南看,所以地球在途中旋转: http://www.colorado.edu/geography/cartpro/cartography2/fall2011/bartel/projects/project3_tungurahua/tungurahua_hazards.html

map 加载到 iframe 中。我也想在不更改缩放 View 的情况下在各种 kmls 之间切换,但我会单独发布该问题。我四处寻找答案,但没有找到任何具体的答案——如果我错过了关于此的帖子,我很乐意查看是否有人可以为我指明正确的方向。

代码如下:

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

function init() {
   google.earth.createInstance('map3d', initCB, failureCB);
}

function initCB(instance) {
   ge = instance;
   ge.getWindow().setVisibility(true);
   // set navigation controls
   ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
   // to fetch a  KML file and show it
function finished(object) {
  if (!object) {
    // wrap alerts in API callbacks and event handlers
    // in a setTimeout to prevent deadlock in some browsers
    setTimeout(function() {
      alert('Bad or null KML.');
    }, 0);
    return;
  }
  ge.getFeatures().appendChild(object);
  var la = ge.createLookAt('');
  la.set(-1.251336, -78.443817, 7000, ge.ALTITUDE_RELATIVE_TO_GROUND, 
         177, 65, 500);
  ge.getView().setAbstractView(la);         
}

//var marker = new GMarker(new GLatLng(-1.402002,-78.409471)); // latitude, longitude 
//   map.addOverlay(marker); 

function failureCB(errorCode) {
}

google.setOnLoadCallback(init);

谢谢!!

最佳答案

您可以 set the fly to speed在加载抽象 View 之前到 SPEED_TELEPORT

此设置将使地球立即飞到所需位置,而不是“俯冲”。如果应恢复正常运动,那么在您获得初始 View 后,您可以将速度设置回默认设置。

例如,以下函数可用于瞬间飞到所需位置。 该方法接受任何 KmlAbstractView ,即 KmlCameraKmlLookAt作为它的单一参数。

// fly-to a view using SPEED_TELEPORT
function teleport(abstractView) {
  var oldSpeed = ge.getOptions().getFlyToSpeed(); .
  ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT); 
  ge.getView().setAbstractView(abstractView);  // Wooosh!
  ge.getOptions().setFlyToSpeed(oldSpeed); 
}

此外,为了确保初始位置的过渡完全不显示,您可以在将 GEWindow 可见性设置为 True 之前让传送移动。例如。

function initCB(instance) {
   ge = instance;
   var la = ge.createLookAt('');
   la.set(-1.251336, -78.443817, 7000, ge.ALTITUDE_RELATIVE_TO_GROUND, 177, 65, 500);
   teleport(la); // set the position
   ge.getWindow().setVisibility(true); // now display the window
   //etc..

关于javascript - 如何加载放大而不是从太空开始的谷歌地球 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13325285/

相关文章:

javascript - 从Google Earth插件中的kmlObject获取kml字符串

c# - 当 TreeView 失去焦点时,如何保留 KMLTreeView 项目 'selected'?

javascript - 谷歌地球中的 localOrientationMatrixToHeadingTiltRoll 功能无法正常工作

elasticsearch - Elasticsearch 未生成Geohash

javascript - 如何更改 Material ui 自动完成中选项的字体大小?

javascript - 如何使用javascript填写网页表单

javascript - 如果属性是否在 DOM 中,则选择选项是否被选中

javascript - 默认情况下使用 rowexpander 展开所有网格行 - EXTJS 5

使用 haversine 公式查找附近位置的 MySql 空间数据查询

node.js - mongodb $text 与 $near