Where to call doPrepare()

27 views
Skip to first unread message

Stefano Gelli

unread,
Mar 9, 2020, 9:41:51 AM3/9/20
to openmap-users
Hi all, i have an OMGraphicHandlerLayer that has to draw a lot of objects. To make the application more responsive I would like to make the job in a different Thread. In the docs I read that I should call the doPrepare() method to let the layer exexute its prepare() method in another Thread. What I cannot understand is where this should be done, since the prepare() method is automatically called on projection change.

Then the question is: how can I force openmap to use a different Thread on projection change event for the prepare() method of a specific layer?

Thank you
Ciao,
S

Don Dietrick

unread,
Mar 10, 2020, 7:26:51 PM3/10/20
to Stefano Gelli, openmap-users
Hi Stefano,

You can call yourLayer.doPrepare() whenever you want to have the prepare() method called on your layer in a separate thread. You don’t have to call it for layers that create OMGraphics from a static data set. You only need to call it if your layer should display new OMGraphics because its data source has been updated. Calling the doPrepare() method will also call repaint() on your layer with the OMGraphicList returned from the prepare() method, so you don’t have to make that call.

The projection changes are received by the Layer.projectionChanged(ProjectionEvent) method. This method is abstract in Layer.java, but the OMGraphicHandlerLayer implements it and lets the ProjectionChange policy handle it. You can change what your layer does in the projectionChanged() method by using different ProjectionChangedPolicy in your layer. I usually set that object in the constructor, but you can also set it in the properties set on a layer. You can see this being done in the layers in the com.bbn.openmap.layer.learn package.


There are two main ProjectionChangedPolicy objects. The StandardPCPolicy assumes the OMGraphicList gets set once on the layer and doesn’t change. The ListResetPCPolicy will delete the rendered OMGraphicList before replacing it with the list returned from the prepare() method. They both will work if your layer returns a new OMGraphicList from the prepare() method, but the StandardPCPolicy is just a little more efficient if it doesn’t change.

The StandardPCPolicy will kick off a thread for the projectionChange if it starts detecting that there are a large number of OMGraphics on the layer. You can also call layer.setAlwaysSpawnThread(true) to force it to do that.

The ListResetPCPolicy always kicks off a separate thread.

Hope this helps,

Don
> --
> You received this message because you are subscribed to the Google Groups "openmap-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to openmap-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/openmap-users/e172b6aa-bbed-4d7f-b61c-d115ebe357a1%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages