views:

38

answers:

2

Hi everyone,

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

+1  A: 

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!

FRotthowe
+1  A: 

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.

DDietrick