Search in sources :

Example 1 with Halo

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);
}
Also used : FeatureType(org.opengis.feature.FeatureType) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) Fill(org.opengis.style.Fill) Description(org.opengis.style.Description) Hints(org.geotoolkit.factory.Hints) GO2Hints(org.geotoolkit.display2d.GO2Hints) MapLayer(org.apache.sis.portrayal.MapLayer) Unit(javax.measure.Unit) Feature(org.opengis.feature.Feature) Font(org.opengis.style.Font) BufferedImage(java.awt.image.BufferedImage) MutableStyle(org.geotoolkit.style.MutableStyle) SceneDef(org.geotoolkit.display2d.service.SceneDef) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) Raster(java.awt.image.Raster) Point(org.locationtech.jts.geom.Point) Dimension(java.awt.Dimension) Point(org.locationtech.jts.geom.Point) LabelPlacement(org.opengis.style.LabelPlacement) Coordinate(org.locationtech.jts.geom.Coordinate) Expression(org.opengis.filter.Expression) TextSymbolizer(org.opengis.style.TextSymbolizer) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) FeatureSet(org.apache.sis.storage.FeatureSet) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) Halo(org.opengis.style.Halo) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Example 2 with Halo

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);
}
Also used : Fill(org.opengis.style.Fill) PointPlacement(org.opengis.style.PointPlacement) Description(org.opengis.style.Description) Expression(org.opengis.filter.Expression) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) Unit(javax.measure.Unit) Halo(org.opengis.style.Halo) Font(org.opengis.style.Font)

Example 3 with Halo

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);
}
Also used : Fill(org.opengis.style.Fill) PointPlacement(org.opengis.style.PointPlacement) Description(org.opengis.style.Description) Expression(org.opengis.filter.Expression) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) Unit(javax.measure.Unit) Halo(org.opengis.style.Halo) Font(org.opengis.style.Font)

Example 4 with Halo

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);
}
Also used : GraphicFill(org.opengis.style.GraphicFill) Fill(org.opengis.style.Fill) LabelPlacement(org.opengis.style.LabelPlacement) Expression(org.opengis.filter.Expression) Font(org.opengis.style.Font) Halo(org.opengis.style.Halo)

Example 5 with Halo

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;
}
Also used : Fill(org.opengis.style.Fill) GraphicFill(org.opengis.style.GraphicFill) Description(org.opengis.style.Description) LabelPlacement(org.opengis.style.LabelPlacement) MutableStyle(org.geotoolkit.style.MutableStyle) Expression(org.opengis.filter.Expression) TextSymbolizer(org.opengis.style.TextSymbolizer) Unit(javax.measure.Unit) Font(org.opengis.style.Font) Halo(org.opengis.style.Halo)

Aggregations

Expression (org.opengis.filter.Expression)11 Fill (org.opengis.style.Fill)11 Font (org.opengis.style.Font)11 Halo (org.opengis.style.Halo)11 LabelPlacement (org.opengis.style.LabelPlacement)9 Unit (javax.measure.Unit)8 Description (org.opengis.style.Description)8 GraphicFill (org.opengis.style.GraphicFill)7 TextSymbolizer (org.opengis.style.TextSymbolizer)4 SimpleInternationalString (org.apache.sis.util.SimpleInternationalString)3 MutableStyle (org.geotoolkit.style.MutableStyle)3 PointPlacement (org.opengis.style.PointPlacement)2 Dimension (java.awt.Dimension)1 BufferedImage (java.awt.image.BufferedImage)1 Raster (java.awt.image.Raster)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 JAXBException (javax.xml.bind.JAXBException)1 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)1 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)1