[geotk] Re: Adding GraphicBuilder to its own MapLayer

Sorel johann.sorel at geomatys.fr
Tue Jul 26 06:28:36 EDT 2011


Hello,

Like you noticed, the graphic objects are cached, (the createGraphics is 
only called once).
You must see the rendering engine very much like a 3D scene graph.
There is a root node which contains other graphics and so on, so the 
createGraphics can return a single Graphic which contain several 
children graphics for each radar.
The graphic builder takes the MapLayer and the J2DCanvas in parameter, 
this allow the graphic to attach a listener on the MapLayer and update 
his graphic children when needed or recreate it's children each time.

The canvas can be repaint at any time using :
getCanvas().getController().repaint();

You can choose to repaint only on events or use an external thread to 
repaint at regular interval.

johann


On 07/26/2011 11:42 AM, Thys Meintjes wrote:
> After adding some logs I noticed the following:
>
> The TargetGraphicBuilder's  createGraphics() is only called when 
> loaded or when the state changed. It seems that the underlying
> assumption for the builder is that it will only be called once or 
> twice to create a set of static graphics.... This does not fit with my
> use case where the targetmanager manages a list of dynamically 
> changing targets. I assumed createGraphics will be called every time
> a repaint is needed - but this is not the case it seems.
>
> Is there anything I can do about this ? Is there a way of adding a 
> graphic directly to a map layer ?
>
> public class TargetGraphicBuilder implements GraphicBuilder<GraphicJ2D> {
>
>     private final static Logger logger = 
> LoggerFactory.getLogger(TargetGraphicBuilder.class);
>     private TargetManager targetManager;
>
>     public TargetGraphicBuilder(TargetManager manager) {
>         targetManager = manager;
>     }
>
>     @Override
>     public Collection<GraphicJ2D> createGraphics(MapLayer layer, 
> Canvas canvas) {
>         logger.debug("Creating Graphics");
>         if (canvas instanceof J2DCanvas) {
>             final J2DCanvas j2dcanvas = (J2DCanvas) canvas;
>             return makeTargets(j2dcanvas);
>         }
>         logger.debug("Canvas not a J2DCanvas");
>         return Collections.emptyList();
>     }
>
>     private Collection makeTargets(J2DCanvas canvas) {
>         ArrayList<TargetGraphic> targetGraphics = new 
> ArrayList<TargetGraphic>();
>         for (Target t : targetManager.getAllTargets()) {
>             targetGraphics.add(new TargetGraphic(canvas, t));
>         }
>         return Collections.unmodifiableList(targetGraphics);
>     }
>
>     @Override
>     public Class<GraphicJ2D> getGraphicType() {
>         return GraphicJ2D.class;
>     }
>
>     @Override
>     public Image getLegend(MapLayer layer) throws PortrayalException {
>         return null;
>     }
>
>     public String getName() {
>         return targetManager.getName();
>     }
> }
>
> -- 
> Thys Meintjes
>
>
>
> _______________________________________________
> Geotoolkit mailing list
> Geotoolkit at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geotoolkit

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geotoolkit/attachments/20110726/457704f1/attachment.html


More information about the Geotoolkit mailing list