简体   繁体   English

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

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

I am working on feeding Matlab's simulation data to Google Earth Plug-in via COM.我正在通过 COM 将 Matlab 的模拟数据提供给 Google 地球插件。

My problem is that the command,which should be invoked after Google Earth finished loading, is invoked before that.我的问题是,应该在谷歌地球加载完成后调用的命令在此之前被调用。 That brings of course error.这当然会带来错误。

I could use the pause command to pause the code waiting the Google Earth to load.我可以使用 pause 命令暂停等待 Google Earth 加载的代码。 But, this solution is not that efficient, as I don't know exactly how fast or how slow Google Earth will load on different machines.但是,这个解决方案效率不高,因为我不知道谷歌地球在不同机器上加载的速度有多快或多慢。

I've also tried using the properties of the COM object.我也尝试过使用 COM object 的属性。 It was close, but no cigar.它很接近,但没有雪茄。 The code looks like this代码看起来像这样

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

or also this one:或者这个:

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

end  

Is there any object properties that could be used?有没有可以使用的 object 属性? Thanks!谢谢!

Found the solution!找到了解决方案!

Google Earth Plug-in will call the "initCallback" method when it finished loading. Google 地球插件在完成加载后会调用“initCallback”方法。

By adding a line on "initCallback" method, I change the title of my html document to other name, which indicates that the plugin is loaded.通过在“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);
    }

At MATLAB's end, I just added the a while loop, comparing the html document title, pausing the executing until the plugin is finished loading.在 MATLAB 的最后,我只是添加了一个 while 循环,比较 html 文档标题,暂停执行直到插件完成加载。

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

Maybe there is other more elegant solution, love to hear your feedbacks也许还有其他更优雅的解决方案,喜欢听到您的反馈

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

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