[geotk] Re: Adding GraphicBuilder to its own MapLayer
Thys Meintjes
sthysel at gmail.com
Tue Jul 26 06:28:57 EDT 2011
I seem to be spamming the list today...
Anyway, I resolved some of my issues by doing all of the painting in
the TargetGraphic, this is in line with the demo code and the other custom
maplayer/graphicbuilders that Johan alluded to earlier (For some reason I
wanted to have a targetgraphic per target, don't know why...).
For reference sake and to maybe save somebody else some hassle here's the
combo :
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) {
return Collections.singleton((GraphicJ2D) new
TargetGraphic((J2DCanvas) canvas, targetManager));
}
logger.debug("Canvas not a J2DCanvas");
return Collections.emptyList();
}
@Override
public Class<GraphicJ2D> getGraphicType() {
return GraphicJ2D.class;
}
@Override
public Image getLegend(MapLayer layer) throws PortrayalException {
return null;
}
public String getName() {
return targetManager.getName();
}
}
public class TargetMapLayer extends AbstractMapLayer {
private TargetGraphicBuilder builder;
// full world extend
private static final Envelope MAXEXTEND_ENV = new
Envelope2D(DefaultGeographicCRS.WGS84, -180, -90, 360, 180);
private static final MutableStyleFactory SF = (MutableStyleFactory)
FactoryFinder.getStyleFactory(
new Hints(Hints.STYLE_FACTORY, MutableStyleFactory.class));
public TargetMapLayer(TargetManager manager) {
super(new DefaultStyleFactory().style());
//register the default graphic builder for geotk 2D engine.
builder = new TargetGraphicBuilder(manager);
graphicBuilders().add(builder);
setDescription(SF.description(manager.getName(), manager.getName() +
" Target Manager"));
}
@Override
public Envelope getBounds() {
return MAXEXTEND_ENV;
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geotoolkit/attachments/20110726/b47650ad/attachment-0001.html
More information about the Geotoolkit
mailing list