繁体   English   中英

等待 Google 地球完成加载,然后在 matlab 中执行下一个命令

[英]wait for Google Earth to finish loading before executing next command in matlab

我正在通过 COM 将 Matlab 的模拟数据提供给 Google 地球插件。

我的问题是,应该在谷歌地球加载完成后调用的命令在此之前被调用。 这当然会带来错误。

我可以使用 pause 命令暂停等待 Google Earth 加载的代码。 但是,这个解决方案效率不高,因为我不知道谷歌地球在不同机器上加载的速度有多快或多慢。

我也尝试过使用 COM object 的属性。 它很接近,但没有雪茄。 代码看起来像这样

waitfor(h.Document.parentWindow.document,'readyState','complete')

或者这个:

while strcmp(h.Document.parentWindow.document.readyState,'complete')== 0
    pause(1);

end  

有没有可以使用的 object 属性? 谢谢!

找到了解决方案!

Google 地球插件在完成加载后会调用“initCallback”方法。

通过在“initCallback”方法上添加一行,我将我的 html 文档的标题更改为其他名称,这表明插件已加载。

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

      // tell the application the plugin is ready
      //(window.external.JSInitSuccessCallback_(pluginInstance);
      document.title = "Google Earth Plugin - Ready";

      // prevent mouse navigation in the plugin
      ge.getOptions().setMouseNavigationEnabled(false);
    }

在 MATLAB 的最后,我只是添加了一个 while 循环,比较 html 文档标题,暂停执行直到插件完成加载。

while strcmp(h.Document.title,'Google Earth Plugin - Ready')~=1
    pause(0.01)
end

也许还有其他更优雅的解决方案,喜欢听到您的反馈

暂无
暂无

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

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