Search in sources :

Example 11 with TextSymbolizer

use of org.opengis.style.TextSymbolizer in project geotoolkit by Geomatys.

the class GTtoSE110Transformer method visit.

/**
 * Transform a GT rule in jaxb rule or OnlineResource
 */
@Override
public Object visit(final Rule rule, final Object data) {
    if (rule.getOnlineResource() != null) {
        // we store only the online resource
        return visit(rule.getOnlineResource(), null);
    }
    final RuleType rt = se_factory.createRuleType();
    rt.setName(rule.getName());
    rt.setDescription(visit(rule.getDescription(), null));
    if (rule.isElseFilter()) {
        rt.setElseFilter(se_factory.createElseFilterType());
    } else if (rule.getFilter() != null) {
        rt.setFilter(apply(rule.getFilter()));
    }
    if (rule.getLegend() != null) {
        rt.setLegendGraphic(visit(rule.getLegend(), null));
    }
    rt.setMaxScaleDenominator(rule.getMaxScaleDenominator());
    rt.setMinScaleDenominator(rule.getMinScaleDenominator());
    for (final Symbolizer symbol : rule.symbolizers()) {
        if (symbol instanceof LineSymbolizer) {
            rt.getSymbolizer().add(visit((LineSymbolizer) symbol, null));
        } else if (symbol instanceof PolygonSymbolizer) {
            rt.getSymbolizer().add(visit((PolygonSymbolizer) symbol, null));
        } else if (symbol instanceof PointSymbolizer) {
            rt.getSymbolizer().add(visit((PointSymbolizer) symbol, null));
        } else if (symbol instanceof RasterSymbolizer) {
            rt.getSymbolizer().add(visit((RasterSymbolizer) symbol, null));
        } else if (symbol instanceof TextSymbolizer) {
            rt.getSymbolizer().add(visit((TextSymbolizer) symbol, null));
        } else if (symbol instanceof ExtensionSymbolizer) {
            ((List) rt.getSymbolizer()).add(visit((ExtensionSymbolizer) symbol, null));
        }
    }
    return rt;
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) RuleType(org.geotoolkit.se.xml.v110.RuleType) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) Symbolizer(org.opengis.style.Symbolizer)

Example 12 with TextSymbolizer

use of org.opengis.style.TextSymbolizer in project geotoolkit by Geomatys.

the class MapfileToSLDProcess method createTextSymbolizer.

private List<Symbolizer> createTextSymbolizer(final Expression label, final Feature lblStyle) {
    Expression expLabelColor = (Expression) lblStyle.getPropertyValue(LABEL_COLOR.toString());
    Expression expLabelSize = (Expression) lblStyle.getPropertyValue(LABEL_SIZE.toString());
    Expression expHaloColor = (Expression) lblStyle.getPropertyValue(LABEL_OUTLINECOLOR.toString());
    Integer valHaloWidth = (Integer) lblStyle.getPropertyValue(LABEL_OUTLINEWIDTH.toString());
    String valAngle = (String) lblStyle.getPropertyValue(LABEL_ANGLE.toString());
    if (expLabelColor == null) {
        expLabelColor = SF.literal(Color.BLACK);
    }
    if (expLabelSize == null) {
        expLabelSize = DEFAULT_FONT_SIZE;
    }
    if (expHaloColor == null) {
        expHaloColor = SF.literal(Color.WHITE);
    }
    if (valHaloWidth == null) {
        valHaloWidth = 0;
    }
    Expression expHaloWidth = FF.literal(valHaloWidth);
    final List<Symbolizer> symbolizers = new ArrayList<Symbolizer>();
    LabelPlacement placement = SF.pointPlacement();
    if (valAngle != null) {
        if ("FOLLOW".equalsIgnoreCase(valAngle) || "AUTO".equalsIgnoreCase(valAngle)) {
            final Expression offset = FF.divide(expLabelSize, FF.literal(-2));
            final Expression initial = FF.literal(20);
            Expression gap = LITERAL_ZERO_FLOAT;
            boolean repeated = false;
            final boolean aligned = false;
            final boolean generalize = false;
            Integer minDistance = (Integer) lblStyle.getPropertyValue(LABEL_MINDISTANCE.toString());
            if (minDistance != null) {
                repeated = true;
                gap = FF.literal(minDistance);
            }
            placement = SF.linePlacement(offset, initial, gap, repeated, aligned, generalize);
        } else {
            Expression rotation = LITERAL_ZERO_FLOAT;
            // try if it's a number
            try {
                double d = Double.valueOf(valAngle);
                rotation = FF.literal(d);
            } catch (Exception ex) {
            }
            placement = SF.pointPlacement(DEFAULT_ANCHOR_POINT, DEFAULT_DISPLACEMENT, rotation);
        }
    }
    // general informations
    final String name = "";
    final Description desc = DEFAULT_DESCRIPTION;
    // use the default geometry of the feature
    final String geometry = null;
    final Unit unit = Units.POINT;
    final Font font = SF.font(FF.literal("Arial"), FONT_STYLE_NORMAL, FONT_WEIGHT_NORMAL, expLabelSize);
    final Halo halo = SF.halo(SF.fill(expHaloColor), expHaloWidth);
    final Fill fill = SF.fill(expLabelColor);
    final TextSymbolizer symbol = SF.textSymbolizer(name, geometry, desc, unit, label, font, placement, halo, fill);
    symbolizers.add(symbol);
    return symbolizers;
}
Also used : Fill(org.opengis.style.Fill) Description(org.opengis.style.Description) ArrayList(java.util.ArrayList) Unit(javax.measure.Unit) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) Symbolizer(org.opengis.style.Symbolizer) JAXBException(javax.xml.bind.JAXBException) ProcessException(org.geotoolkit.process.ProcessException) IOException(java.io.IOException) Font(org.opengis.style.Font) LabelPlacement(org.opengis.style.LabelPlacement) Expression(org.opengis.filter.Expression) TextSymbolizer(org.opengis.style.TextSymbolizer) Halo(org.opengis.style.Halo)

Example 13 with TextSymbolizer

use of org.opengis.style.TextSymbolizer in project geotoolkit by Geomatys.

the class Styles method defaultText.

// ////////////////////////////////////////////////////////////////////
// TEXT SYMBOLIZER ///////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
public static MutableStyle defaultText() {
    final TextSymbolizer symbol = DEFAULT_TEXT_SYMBOLIZER;
    final MutableStyle style = SF.style(DEFAULT_POLYGON_SYMBOLIZER, symbol);
    return style;
}
Also used : MutableStyle(org.geotoolkit.style.MutableStyle) TextSymbolizer(org.opengis.style.TextSymbolizer)

Example 14 with TextSymbolizer

use of org.opengis.style.TextSymbolizer in project geotoolkit by Geomatys.

the class Styles method linedText.

public static MutableStyle linedText() {
    // 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.linePlacement(FF.literal(0));
    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

TextSymbolizer (org.opengis.style.TextSymbolizer)14 LineSymbolizer (org.opengis.style.LineSymbolizer)7 PointSymbolizer (org.opengis.style.PointSymbolizer)6 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)6 MutableStyle (org.geotoolkit.style.MutableStyle)5 Expression (org.opengis.filter.Expression)5 RasterSymbolizer (org.opengis.style.RasterSymbolizer)5 Unit (javax.measure.Unit)4 Test (org.junit.Test)4 Description (org.opengis.style.Description)4 ExtensionSymbolizer (org.opengis.style.ExtensionSymbolizer)4 Fill (org.opengis.style.Fill)4 Font (org.opengis.style.Font)4 Halo (org.opengis.style.Halo)4 LabelPlacement (org.opengis.style.LabelPlacement)4 Symbolizer (org.opengis.style.Symbolizer)4 Color (java.awt.Color)2 JAXBElement (javax.xml.bind.JAXBElement)2 Marshaller (javax.xml.bind.Marshaller)2 Unmarshaller (javax.xml.bind.Unmarshaller)2