正在等待第 3 方库 (OpenMap/Java) 的线程完成?

发布于 2024-08-18 08:44:31 字数 462 浏览 7 评论 0原文

我的应用程序目前有一个有趣的问题。此问题与 OpenMap 相关,但可能适用于任何第 3 方库。

在这个特定的示例中,我们的代码需要创建 OpenMap 工具并加载其图层(在后台)并截取特定兴趣点的屏幕截图。

然而,问题是 OpenMap 库会创建自己的线程来加载这些图层,从而立即返回到我们的代码以截取屏幕截图,并且大多数情况下屏幕截图是空的或不完整的。

我们的应用程序的伪代码是这样的:

check database for layers
load layers using OpenMap
take screenshot of map at point of interest

我假设某种线程管理是有序的,但是当库使用我们无法访问的自己的线程时,如何做到这一点?另外,OpenMap 没有返回或标志来指示这些线程已完成(我已经看到)。

有什么建议吗?

谢谢

My application currently has an interesting problem. This problem is with OpenMap but could probably be applied to any 3rd party library.

In this particular example, our code needs to create our OpenMap tool and load its layers (in the background) and take a screenshot of a particular point of interest.

However, the problem is that the OpenMap library creates its own thread(s) to load these layers, thus returning to our code to take a screenshot immediately and most times the screenshot is empty or incomplete.

The pseudo-code of our application is like this:

check database for layers
load layers using OpenMap
take screenshot of map at point of interest

I've assumed that some sort of thread management was in order, but how can this be done when the library is using its own thread(s) that we have no access to? Also, OpenMap has no returns or flags to indicate that these thread are finished (that I've seen).

Any suggestions?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

微暖i 2024-08-25 08:44:31

我不知道 OpenMap,但正常的方法是向第三方库注册一些回调。在 Java 中,这意味着实现一个接口并在调用 API 方法的对象上注册为侦听器。
您(几乎?)永远不必(或应该)了解有关库的内部线程处理的信息!

I don't know OpenMap, but the normal way is to register some callback with the 3rd party library. In Java that means implementing an Interface and registering as a listener at the object on which you call the API method.
You (almost?) never have to (or should) know something about the internal thread handling of a library!

抽个烟儿 2024-08-25 08:44:31

可以为 OpenMap 编写图层,以便它们可以响应投影查询并渲染到 java.awt.Graphics 对象中。扩展 OMGraphicHandler 层,重写prepare() 方法,以便它返回层上投影集的 OMGraphicList。如果调用Layer.renderDataForProjection(),则将渲染prepare中返回的OMGraphicList。

com.bbn.openmap.image.ImageServer 是一个很好的对象,可用于管理图层图像的创建。

Layers can be written for OpenMap so they can respond to projection queries and render into a java.awt.Graphics object. Extend the OMGraphicHandler layer, override the prepare() method so it returns an OMGraphicList for the projection set on the Layer. If you call Layer.renderDataForProjection(), the OMGraphicList returned in prepare will be rendered.

The com.bbn.openmap.image.ImageServer is a good object to use for managing the creation of images for your Layers.

梦回梦里 2024-08-25 08:44:31

在 MapBean 完成生成图像之前,第 3 方 jpeg 提取器提取图像也存在同样的问题。稍后遵循有关调用的提示,并在我的图层处理代码和导出到图形代码之间添加以下代码:


//...OpenMap editing code stops here ...

final Runnable doWaitUntilTheMapBeanIsFinishedRendering = new Runnable() {
   public void run()
   {
       System.out.println("Ding, fries are done!");
   } 
};

try
{
    SwingUtilities.invokeAndWait( doWaitUntilTheMapBeanIsFinishedRendering );
}
catch( Exception e )
{
    e.printStackTrace();
}

byte[] image = JPEGImageFormatter.getImageFromMapBean( mapbean );

Had the same problem with the 3rd party jpeg extractor pulling the image before the MapBean was finished producing the image. Followed the hint about the invoke later and added the following code between my layer handling code and my export to graphic code:


//...OpenMap editing code stops here ...

final Runnable doWaitUntilTheMapBeanIsFinishedRendering = new Runnable() {
   public void run()
   {
       System.out.println("Ding, fries are done!");
   } 
};

try
{
    SwingUtilities.invokeAndWait( doWaitUntilTheMapBeanIsFinishedRendering );
}
catch( Exception e )
{
    e.printStackTrace();
}

byte[] image = JPEGImageFormatter.getImageFromMapBean( mapbean );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文