[geotk] Re: Adding GraphicBuilder to its own MapLayer

Thys Meintjes sthysel at gmail.com
Tue Jul 26 05:42:50 EDT 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geotoolkit/attachments/20110726/a21b3bba/attachment.html


More information about the Geotoolkit mailing list