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

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

本文关键字:matlab 执行 命令 下一个 然后 Earth Google 加载 等待      更新时间:2023-09-26

我正在通过COM.将Matlab的模拟数据提供给Google Earth插件

我的问题是,该命令本应在Google Earth完成加载后调用,但在此之前却被调用了。这当然会带来错误。

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

我还尝试过使用COM对象的属性。它很近,但没有雪茄。代码看起来像这个

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

或者这个:

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

是否有可以使用的对象属性?谢谢

找到了解决方案!

GoogleEarth插件在加载完成后将调用"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

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