在matlab中执行下一个命令之前等待Google Earth完成加载

时间:2011-06-09 12:19:06

标签: javascript matlab google-earth google-earth-plugin

我正在努力通过COM将Matlab的模拟数据提供给Google Earth Plug-in。

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

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

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

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

或者也是这个:

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

end  

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

1 个答案:

答案 0 :(得分:1)

找到了解决方案!

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

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

相关问题