If you are using the OmGraphicHandlerLayer is should handle the threading with no problem.
If your derived OmGraphicHandlerLayer updates your OmGraphics dynamically, make sure that you override the OmGraphicHandlerLayer.prepare() method and perform all of your Layer and OmGraphic manipulation in prepare() (i.e. updating locations, adding new graphics, etc.).
If your derived OmGraphicHandlerLayer does not update dynamically, simply add your graphics to the graphic list of the OmGraphicHandlerLayer. OmGraphicHandlerLayer's prepare() method will generate() the list. See the code below for a static example.
Attaching your Layer code to your post would be helpful.
Cheers,
David
/* **********************************************************************
*
* ROLANDS & ASSOCIATES Corporation
* 500 Sloat Avenue
* Monterey, CA 93940
* (831) 373-2025
*
* Copyright (C) 2002, 2003 ROLANDS & ASSOCIATES Corporation. All rights reserved.
* Openmap is a trademark of BBN Technologies, A Verizon Company
*
*
* **********************************************************************
* $Id: ClassificationLayer.java 177 2007-06-18 15:09:12Z ward $
*
* $Revision:: 177 $: Revision of last commit
* $Author:: ward $: Author of last commit
*
* $HeadURL: svn+ssh://jtlsdev_at_radio/svn/jtls/trunk/jtls/src/whip/src/com/rolands/whip/map/layer/ClassificationLayer.java $
* **********************************************************************
*/
package com.rolands.whip.map.layer;
import com.bbn.openmap.event.ProjectionEvent;
import com.bbn.openmap.layer.OMGraphicHandlerLayer;
import com.bbn.openmap.omGraphics.OMGraphicList;
import com.bbn.openmap.omGraphics.OMText;
import com.rolands.jtls.scenario.Colors;
import java.awt.Font;
/**
* The Classification layer displays a classification banner on the map.
* The text is centered at the top of the display.
* <p>The projection changed method is overridden to ensure the
* classification text is centered on the mapBean.
* <p>Everything else is managed by the OMGraphicHandlerLayer.
* <br>
*/
public class ClassificationLayer extends OMGraphicHandlerLayer {
protected OMText text;
public ClassificationLayer(String classification) {
super();
text = new OMText(0, 30, classification, OMText.JUSTIFY_CENTER);
text.setFont(new Font("Monospaced", Font.BOLD, 36));
text.setLinePaint(Colors.get("classification"));
setList(new OMGraphicList());
getList().add(text);
}
/**
* From the ProjectionListener interface. The method gets called
* when the layer is part of the map, and whenever the map
* projection changes. Will trigger a repaint().
* <p>
*
* The ProjectionEvent is passed to the current
* ProjectionChangePolicy object, which determines what will
* happen on the layer and how. By default, a StandardPCPolicy is
* notified with the projection change, and it will test the
* projection for changes and make sure prepare() is called. It
* will make the decision whether doPrepare() is called, based on
* the number of OMGraphics on the list, which may launch a swing
* worker thread to call prepare(). The StandardPCPolicy does not
* do anything to the OMGraphicList when the projection changes.
* <p>
*
* If you need the OMGraphicList cleared out with a new
* projection, you can substitute a ListRestPCPolicy for the
* StandardPCPolicy. You would want to do this if your
* OMGraphicList changes for different projections - The reason
* the OMGraphicList is nulled out is so if another layer finishes
* before yours does and gets repainted, your old OMGraphics don't
* get painted along side their new ones - it's a mismatched
* situation. You can set the ProjectionChangePolicy directly with
* the setProjectionChangePolicy, or by overriding the
* getProjectionChangePolicy method and returning the type you
* want by default if it is null.
*
* _at_see com.bbn.openmap.layer.policy.ProjectionChangePolicy
* @see com.bbn.openmap.layer.policy.StandardPCPolicy
* @see com.bbn.openmap.layer.policy.ListResetPCPolicy
*/
public void projectionChanged(ProjectionEvent pe) {
super.projectionChanged(pe);
text.setX(pe.getProjection().getWidth()/2);
}
}
----- Original Message ----
From: Carsten Ø. Madsen <
com_at_navicon.dk>
To: Davidian <
kroberts_at_syrres.com>
Cc:
openmap-users_at_bbn.com
Sent: Thursday, January 31, 2008 6:03:39 AM
Subject: Re: [OpenMap Users] Layer dosen't "update" after call to MapBean.setCenter(lat, lon)
Sounds
like
a
threading
problem
then.
Each
of
the
projection
change
events
triggers
doPrepare
that
launches
a
new
thread
that
calls
prepare
so
it
is
very
likely
that
your
prepare
method
etc
could
be
run
simultaneously
(e.g.,
multi
core
box).
Try
putting
in
a
small
sleep
between
setCenter
&
setScale
to
verify
this.
If
that
works
fix
the
threading
problem
in
your
layer.
BR
Carsten
Davidian
wrote:
>
Carsten,
>
>
Yes,
I've
confirmed
that
the
layer
is
getting
a
ProjectionChanged
event
>
every
time
I
call
setCenter.
As
a
matter
of
fact,
it
looks
like
it
is
>
getting
two
such
events.
I'm
sure
that
is
because
I
am
calling
setCenter()
>
on
the
MapBean,
and
then
following
that
with
setScale().
>
>
Also,
I
am
extending
OMGraphicHandlerLayer.
I
checked
the
code
in
that
>
class,
and
generate()
is
getting
called
for
sure
in
the
prepare()
method.
>
>
Thanks
for
your
help
so
far.
>
>
-Kennedy
>
>
>
>
oland
wrote:
>
>>
Hi
>>
>>
Does
the
layer
receive
a
projection
change
event
after
the
call
to
>>
setCenter?
>>
>>
Override
prepare
and
check
that
generate
is
called
on
the
list
returned
>>
by
getList()
and
that
the
list
is
not
empty
when
this
is
done.
>>
>>
BR
>>
Carsten
>>
>>
>>
>
>
--
[To
unsubscribe
to
this
list
send
an
email
to
"
majdart_at_bbn.com"
with
the
following
text
in
the
BODY
of
the
message
"unsubscribe
openmap-users"]
--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu Jan 31 2008 - 10:38:09 EST