<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hello,<br>
    <br>
    The code looks correct (don't forget to call
    context.switchToDisplayCRS() or switchToDisplayCRS() to set the
    system in which you are painting), if you need more examples you can
    have a look at the<br>
    WMS/WMTS/OSM-TMS/KML Clients modules, they all use custom subclasses
    of MapLayer and GraphicBuilders.<br>
    <br>
    When you say it doesn't work. does it pass in the targetgraphic or
    builder code ? or not at all ?<br>
    - try adding the graphicbuilder before you add it in the map .
    (maybe a cache issue)<br>
    - ensure the layer is visible.<br>
    <br>
    <br>
    johann<br>
    <br>
    <br>
    On 07/25/2011 09:10 AM, Thys Meintjes wrote:
    <blockquote
cite="mid:CAHRf99mEpKgq476BtgQ7tjdg+YqEr-GAGm9KE8MvCx0GemLAxQ@mail.gmail.com"
      type="cite">Hi All,
      <div><br>
      </div>
      <div>I'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>&nbsp; public void
            addTargetGraphicsBuilder(TargetGraphicBuilder builder) {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; MapLayer targetLayer = context.layers().get(0);</div>
          <div>&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;targetLayer.graphicBuilders().add(builder);</div>
          <div>&nbsp; &nbsp; }</div>
        </div>
        <div><br>
        </div>
        <div>The first maplayer is a coverage...&nbsp;That didn'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)&nbsp;</div>
        <div>I could conceivably make a Feature of each of them - add it
          to a store and create a FeatureLayer from that.&nbsp;</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'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>&nbsp; &nbsp; private final static Logger logger =
            LoggerFactory.getLogger(TargetGraphicBuilder.class);</div>
          <div>&nbsp; &nbsp; private TargetManager targetManager;</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; public TargetGraphicBuilder(TargetManager manager) {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; targetManager = manager;</div>
          <div>&nbsp; &nbsp; }</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; @Override</div>
          <div>&nbsp; &nbsp; public Collection&lt;GraphicJ2D&gt;
            createGraphics(MapLayer layer, Canvas canvas) {</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; if (canvas instanceof J2DCanvas) {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; final J2DCanvas j2dcanvas = (J2DCanvas)
            canvas;</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return makeTargets(j2dcanvas);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; }</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; logger.debug("Canvas not a J2DCanvas");</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; return Collections.emptyList();</div>
          <div>&nbsp; &nbsp; }</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; private Collection makeTargets(J2DCanvas canvas) {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; ArrayList&lt;TargetGraphic&gt; targetGraphics =
            new ArrayList&lt;TargetGraphic&gt;();</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; for (Target t : targetManager.getAllTargets()) {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; targetGraphics.add(new TargetGraphic(canvas,
            t));</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; }</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; //return
            Collections.unmodifiableList(targetGraphics);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; return targetGraphics;</div>
          <div>&nbsp; &nbsp; }</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; @Override</div>
          <div>&nbsp; &nbsp; public Class&lt;GraphicJ2D&gt; getGraphicType() {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; return GraphicJ2D.class;</div>
          <div>&nbsp; &nbsp; }</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; @Override</div>
          <div>&nbsp; &nbsp; public Image getLegend(MapLayer layer) throws
            PortrayalException {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; return null;</div>
          <div>&nbsp; &nbsp; }</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; public String getName() {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; return targetManager.getName();</div>
          <div>&nbsp; &nbsp; }</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>&nbsp; &nbsp; private final static Logger logger =
            LoggerFactory.getLogger(TargetGraphic.class);</div>
          <div>&nbsp; &nbsp; private Target target;</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; public TargetGraphic(J2DCanvas canvas, Target target)
            {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; super(canvas, canvas.getObjectiveCRS2D());</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; this.target = target;</div>
          <div>&nbsp; &nbsp; }</div>
          <div><br>
          </div>
          <div>
            &nbsp; &nbsp; @Override</div>
          <div>&nbsp; &nbsp; public void paint(RenderingContext2D context) {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; final Graphics2D g2d = context.getGraphics();</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; // transform from geographic to screen space</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; final AffineTransform2D transformer =
            context.getObjectiveToDisplay();</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; DirectPosition targetPos = target.getPosition();</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; logger.debug(targetPos.toString());</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; Point2D.Double center = new
            Point2D.Double(targetPos.getOrdinate(1),
            targetPos.getOrdinate(0));</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; transformer.transform(center, center);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; logger.debug("Transformed center: " + center);</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; // paint a simple circle</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; final Shape circle = new
            Ellipse2D.Double(center.x - 5, center.y - 5, 10, 10);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; g2d.setStroke(new BasicStroke(4));</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; g2d.setColor(Color.WHITE);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; g2d.draw(circle);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; g2d.setPaint(Color.RED);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; g2d.fill(circle);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; g2d.setStroke(new BasicStroke(2));</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; g2d.setColor(Color.BLACK);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; g2d.draw(circle);</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; }</div>
          <div><br>
          </div>
          <div>&nbsp; &nbsp; @Override</div>
          <div>&nbsp; &nbsp; public List&lt;Graphic&gt;
            getGraphicAt(RenderingContext context, SearchArea mask,
            VisitFilter filter, List&lt;Graphic&gt; graphics) {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; return graphics;</div>
          <div>&nbsp; &nbsp; }</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>&nbsp; &nbsp;private void addTarget(Target target) {</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; TargetGraphic tg = new TargetGraphic(canvas,
            target);</div>
          <div>&nbsp; &nbsp; &nbsp; &nbsp; canvas.getContainer().add(tg);</div>
          <div>&nbsp; &nbsp; }</div>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        -- <br>
        Thys Meintjes<br>
        <br>
        <br>
      </div>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Geotoolkit mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Geotoolkit@lists.osgeo.org">Geotoolkit@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/geotoolkit">http://lists.osgeo.org/mailman/listinfo/geotoolkit</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>