繁体   English   中英

Google Earth回调未触发

[英]Google Earth Callbacks Not Firing

我正在尝试使Google Earth回调起作用,但是它们似乎并没有激发我的兴趣。 我已使用Google Earth API网站上的“ 查看更改示例 ”作为参考,但发现它与我的代码之间没有区别……但我的代码不起作用!

这是我代码的重要部分:

<script type="text/javascript">
var ge;

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

function init() {
  document.getElementById('map3d').innerHTML = '';
  google.earth.createInstance('map3d', initCallback, failureCallback);
}

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

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

  // Set the FlyTo speed.
  ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);

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

  throw (new Error("InitCallback!"));

  google.earth.addEventListener(ge.getView(), 'viewchange', function () {
      throw (new Error("EVENT!"));
  });

}

function failureCallback(errorCode) {
}
</script>

“ InitCallback!” 错误已正确抛出,但我从未看到“事件!” 引发错误-无论我将地球移动了多少。

有人看到我在做什么错吗? 任何帮助是极大的赞赏!

我不是javascript方面的专家,但是如果您替换:

       throw (new Error("EVENT!"));

而不是警告,例如:

       alert('EVENT!');

我敢打赌,您会发现它会起作用。 即eventListener正在运行,它似乎不喜欢“ throw”命令

lifeIsGood是正确的-当您像上面一样抛出错误时,如果没有try catch块,则会导致抛出错误后的js无法执行。

而是使用console.log('Error'); 如果您只是尝试使用“快速脏手”方式在控制台中打印内容...

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

     //throw (new Error("InitCallback!")); -- change this to 
     console.log('InitCallback!');

     google.earth.addEventListener(ge.getView(), 'viewchange', function () {
         //throw (new Error("EVENT!")); -- change this to
         console.log('EVENT!');
     });

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM