use of org.opengis.style.Halo in project geotoolkit by Geomatys.
the class TextSymbolizerTest method pointLabelTest.
/**
* Render a label at check it is correctly located in the image.
*/
@Test
public void pointLabelTest() throws Exception {
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.setName("test");
ftb.addAttribute(Point.class).setName("geom").setCRS(CommonCRS.defaultGeographic()).addRole(AttributeRole.DEFAULT_GEOMETRY);
final FeatureType type = ftb.build();
final Feature feature = type.newInstance();
feature.setPropertyValue("geom", GF.createPoint(new Coordinate(0, 0)));
final FeatureSet collection = new InMemoryFeatureSet(type, Arrays.asList(feature));
// text symbolizer style
final String name = "mySymbol";
final Description desc = DEFAULT_DESCRIPTION;
// use the default geometry of the feature
final String geometry = null;
final Unit unit = Units.POINT;
final Expression label = FF.literal("LABEL");
final Font font = SF.font(FF.literal("Arial"), FONT_STYLE_ITALIC, FONT_WEIGHT_BOLD, FF.literal(14));
final LabelPlacement placement = SF.pointPlacement();
final Halo halo = SF.halo(Color.WHITE, 0);
final Fill fill = SF.fill(Color.BLUE);
final TextSymbolizer symbol = SF.textSymbolizer(name, geometry, desc, unit, label, font, placement, halo, fill);
final MutableStyle style = SF.style(symbol);
final MapLayer layer = MapBuilder.createLayer(collection);
layer.setStyle(style);
final MapLayers context = MapBuilder.createContext();
context.getComponents().add(layer);
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.defaultGeographic());
env.setRange(0, -180, +180);
env.setRange(1, -90, +90);
final Hints hints = new Hints();
hints.put(GO2Hints.KEY_COLOR_MODEL, ColorModel.getRGBdefault());
final SceneDef scenedef = new SceneDef(context, hints);
final CanvasDef canvasdef = new CanvasDef(new Dimension(360, 180), env);
canvasdef.setBackground(Color.WHITE);
final BufferedImage buffer = DefaultPortrayalService.portray(canvasdef, scenedef);
// ImageIO.write(buffer, "PNG", new File("test.png"));
// we expect to have a blue label at the center of the image
final int[] pixel = new int[4];
final int[] blue = new int[] { 0, 0, 255, 255 };
final Raster raster = buffer.getData();
boolean found = false;
for (int x = 160; x < 200; x++) {
// should be exactly at the center
raster.getPixel(x, 90, pixel);
if (Arrays.equals(blue, pixel)) {
found = true;
}
}
assertTrue("label not found", found);
}
use of org.opengis.style.Halo in project geotoolkit by Geomatys.
the class Tester method createTextSymbolizer.
private static TextSymbolizer createTextSymbolizer() {
String name = "Text symbolizer name";
Description desc = STYLE_FACTORY.description("Text symbolizer title", "Text symbolizer description");
Unit uom = Units.FOOT;
String geom = "geom";
Fill fill = STYLE_FACTORY.fill(Color.ORANGE);
Halo halo = STYLE_FACTORY.halo(Color.PINK, 12);
PointPlacement placement = STYLE_FACTORY.pointPlacement();
Font font = STYLE_FACTORY.font();
Expression label = FILTER_FACTORY.literal("the feature field name");
return STYLE_FACTORY.textSymbolizer(name, geom, desc, uom, label, font, placement, halo, fill);
}
use of org.opengis.style.Halo in project geotoolkit by Geomatys.
the class XMLUtilitiesTest method createTextSymbolizer.
private static TextSymbolizer createTextSymbolizer() {
String name = "Text symbolizer name";
Description desc = STYLE_FACTORY.description("Text symbolizer title", "Text symbolizer description");
Unit uom = Units.FOOT;
String geom = "geom";
Fill fill = STYLE_FACTORY.fill(Color.ORANGE);
Halo halo = STYLE_FACTORY.halo(Color.PINK, 12);
PointPlacement placement = STYLE_FACTORY.pointPlacement();
Font font = STYLE_FACTORY.font();
Expression label = FILTER_FACTORY.literal("the feature field name");
return STYLE_FACTORY.textSymbolizer(name, geom, desc, uom, label, font, placement, halo, fill);
}
use of org.opengis.style.Halo in project geotoolkit by Geomatys.
the class PrepareStyleVisitor method visit.
@Override
public Object visit(TextSymbolizer ts, Object o) {
Fill fill = ts.getFill();
Font font = ts.getFont();
Halo halo = ts.getHalo();
Expression label = ts.getLabel();
LabelPlacement place = ts.getLabelPlacement();
if (fill != null) {
fill = (Fill) fill.accept(this, o);
}
if (font != null) {
font = (Font) font.accept(this, o);
}
if (halo != null) {
halo = (Halo) halo.accept(this, o);
}
if (label != null) {
label = (Expression) visit(label);
}
if (place != null) {
place = (LabelPlacement) place.accept(this, o);
}
// recreate symbolizer
return SF.textSymbolizer(ts.getName(), visitGeometryExpression(ts, o), ts.getDescription(), ts.getUnitOfMeasure(), label, font, place, halo, fill);
}
use of org.opengis.style.Halo in project geotoolkit by Geomatys.
the class Styles method centeredText.
public static MutableStyle centeredText() {
// general informations
final String name = "mySymbol";
final Description desc = DEFAULT_DESCRIPTION;
// use the default geometry of the feature
final String geometry = null;
final Unit unit = Units.POINT;
final Expression label = FF.property("CNTRY_NAME");
final Font font = SF.font(FF.literal("Arial"), FONT_STYLE_ITALIC, FONT_WEIGHT_BOLD, FF.literal(14));
final LabelPlacement placement = SF.pointPlacement();
final Halo halo = SF.halo(Color.WHITE, 1);
final Fill fill = SF.fill(Color.BLUE);
final TextSymbolizer symbol = SF.textSymbolizer(name, geometry, desc, unit, label, font, placement, halo, fill);
final MutableStyle style = SF.style(DEFAULT_POLYGON_SYMBOLIZER, symbol);
return style;
}
Aggregations