Hi All,<div><br></div><div>I&#39;m attempting to keep my special target graphics layer sperate from the coverage or shape layers.</div><div>First I just added the builder to a EmptyMapLayer form MapBuilder - but that failed to produce any output - maybe</div>
<div>I should have added a envelope ?</div><div><br></div><div>I then tried adding the GraphicsBuilder to the first map layer in the context:</div><div><br clear="all"><div><div>  public void addTargetGraphicsBuilder(TargetGraphicBuilder builder) {</div>
<div>        MapLayer targetLayer = context.layers().get(0);</div><div>        targetLayer.graphicBuilders().add(builder);</div><div>    }</div></div><div><br></div><div>The first maplayer is a coverage... That didn&#39;t work either. I kind of expected it to...</div>
<div><br></div><div>The demo code uses a FeatureLayer with a GraphicsBuilder. Because I have a bunch of points (targets) </div><div>I could conceivably make a Feature of each of them - add it to a store and create a FeatureLayer from that. </div>
<div>These points are not static and they have a life time of about 10 seconds so the data changes continuously.</div><div>I don&#39;t know if that is the correct approach though.</div><div><br></div><div>I guess my question is how do I use a GraphicsBuilder to build to a dedicated maplayer. And If I can how do I construct</div>
<div>a maplayer with minimal ceremony for use with a GraphicsBuilder.</div><div><br></div><div><br></div><div>Here is my builder - in case I did something stupid:</div><div><br></div><div><div>public class TargetGraphicBuilder implements GraphicBuilder&lt;GraphicJ2D&gt; {</div>
<div><br></div><div>    private final static Logger logger = LoggerFactory.getLogger(TargetGraphicBuilder.class);</div><div>    private TargetManager targetManager;</div><div><br></div><div>    public TargetGraphicBuilder(TargetManager manager) {</div>
<div>        targetManager = manager;</div><div>    }</div><div><br></div><div>    @Override</div><div>    public Collection&lt;GraphicJ2D&gt; createGraphics(MapLayer layer, Canvas canvas) {</div><div><br></div><div>        if (canvas instanceof J2DCanvas) {</div>
<div>            final J2DCanvas j2dcanvas = (J2DCanvas) canvas;</div><div>            return makeTargets(j2dcanvas);</div><div>        }</div><div>        logger.debug(&quot;Canvas not a J2DCanvas&quot;);</div><div>        return Collections.emptyList();</div>
<div>    }</div><div><br></div><div>    private Collection makeTargets(J2DCanvas canvas) {</div><div>        ArrayList&lt;TargetGraphic&gt; targetGraphics = new ArrayList&lt;TargetGraphic&gt;();</div><div>        for (Target t : targetManager.getAllTargets()) {</div>
<div>            targetGraphics.add(new TargetGraphic(canvas, t));</div><div>        }</div><div>        //return Collections.unmodifiableList(targetGraphics);</div><div>        return targetGraphics;</div><div>    }</div>
<div><br></div><div>    @Override</div><div>    public Class&lt;GraphicJ2D&gt; getGraphicType() {</div><div>        return GraphicJ2D.class;</div><div>    }</div><div><br></div><div>    @Override</div><div>    public Image getLegend(MapLayer layer) throws PortrayalException {</div>
<div>        return null;</div><div>    }</div><div><br></div><div>    public String getName() {</div><div>        return targetManager.getName();</div><div>    }</div></div><div><br></div><div>And the graphic:</div><div>
<br></div><div><div>public class TargetGraphic extends AbstractGraphicJ2D {</div><div><br></div><div>    private final static Logger logger = LoggerFactory.getLogger(TargetGraphic.class);</div><div>    private Target target;</div>
<div><br></div><div>    public TargetGraphic(J2DCanvas canvas, Target target) {</div><div>        super(canvas, canvas.getObjectiveCRS2D());</div><div>        this.target = target;</div><div>    }</div><div><br></div><div>
    @Override</div><div>    public void paint(RenderingContext2D context) {</div><div>        final Graphics2D g2d = context.getGraphics();</div><div><br></div><div>        // transform from geographic to screen space</div>
<div>        final AffineTransform2D transformer = context.getObjectiveToDisplay();</div><div>        DirectPosition targetPos = target.getPosition();</div><div>        logger.debug(targetPos.toString());</div><div>        Point2D.Double center = new Point2D.Double(targetPos.getOrdinate(1), targetPos.getOrdinate(0));</div>
<div>        transformer.transform(center, center);</div><div>        logger.debug(&quot;Transformed center: &quot; + center);</div><div><br></div><div>        // paint a simple circle</div><div>        final Shape circle = new Ellipse2D.Double(center.x - 5, center.y - 5, 10, 10);</div>
<div>        g2d.setStroke(new BasicStroke(4));</div><div>        g2d.setColor(Color.WHITE);</div><div>        g2d.draw(circle);</div><div>        g2d.setPaint(Color.RED);</div><div>        g2d.fill(circle);</div><div>        g2d.setStroke(new BasicStroke(2));</div>
<div>        g2d.setColor(Color.BLACK);</div><div>        g2d.draw(circle);</div><div><br></div><div>    }</div><div><br></div><div>    @Override</div><div>    public List&lt;Graphic&gt; getGraphicAt(RenderingContext context, SearchArea mask, VisitFilter filter, List&lt;Graphic&gt; graphics) {</div>
<div>        return graphics;</div><div>    }</div><div>}</div></div><div><br></div><div>Note that the graphic works correctly when I add it to the canvas container directly:</div><div><div><br></div><div>   private void addTarget(Target target) {</div>
<div>        TargetGraphic tg = new TargetGraphic(canvas, target);</div><div>        canvas.getContainer().add(tg);</div><div>    }</div></div><div><br></div><div><br></div>-- <br>Thys Meintjes<br><br><br>
</div>