Java Code Examples for org.geotools.styling.TextSymbolizer#setLabel()

The following examples show how to use org.geotools.styling.TextSymbolizer#setLabel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StyleConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
private TextSymbolizer createTextSymbolizer(LabelStyleInfo labelStyle, LayerType layerType) {
	Fill fontFill = styleBuilder.createFill(styleBuilder.literalExpression(labelStyle.getFontStyle().getColor()),
			styleBuilder.literalExpression(labelStyle.getFontStyle().getOpacity()));
	TextSymbolizer symbolizer = styleBuilder.createTextSymbolizer();
	symbolizer.setFill(fontFill);
	FontStyleInfo fontInfo = labelStyle.getFontStyle();
	symbolizer.setFont(styleBuilder.createFont(styleBuilder.literalExpression(fontInfo.getFamily()),
			styleBuilder.literalExpression(fontInfo.getStyle()),
			styleBuilder.literalExpression(fontInfo.getWeight()),
			styleBuilder.literalExpression(fontInfo.getSize())));
	symbolizer.setLabel(styleBuilder.attributeExpression(labelStyle.getLabelAttributeName()));
	Fill haloFill = styleBuilder.createFill(
			styleBuilder.literalExpression(labelStyle.getBackgroundStyle().getFillColor()),
			styleBuilder.literalExpression(labelStyle.getBackgroundStyle().getFillOpacity()));
	symbolizer.setHalo(styleBuilder.createHalo(haloFill, 1));
	// label placement : point at bottom-center of label (same as vectorized)
	switch (layerType) {
		case MULTIPOINT:
		case POINT:
			symbolizer.setLabelPlacement(styleBuilder.createPointPlacement(0.5, 0, 0));
			break;
		default:
			break;
	}
	return symbolizer;
}
 
Example 2
Source File: RuleRenderVisitor.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * (non-Javadoc)
 *
 * @see
 *     org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.TextSymbolizer)
 */
public void visit(TextSymbolizer text) {
    TextSymbolizer copy = sf.createTextSymbolizer();

    copy.setFill(copy(text.getFill()));
    copy.fonts().clear();
    copy.fonts().addAll(copyFonts(text.fonts()));

    // Ignore geometry field so that symbol is rendered
    copy.setGeometry(copy(text.getGeometry()));

    copy.setUnitOfMeasure(text.getUnitOfMeasure());
    copy.setHalo(copy(text.getHalo()));
    copy.setLabel(copy(text.getLabel()));
    copy.setLabelPlacement(copy(text.getLabelPlacement()));
    copy.setPriority(copy(text.getPriority()));
    copy.getOptions().putAll(text.getOptions());

    if (text instanceof TextSymbolizer2) {
        TextSymbolizer2 text2 = (TextSymbolizer2) text;
        TextSymbolizer2 copy2 = (TextSymbolizer2) copy;

        copy2.setGraphic(copy(text2.getGraphic()));
        copy2.setSnippet(copy(text2.getSnippet()));
        copy2.setFeatureDescription(copy(text2.getFeatureDescription()));
        copy2.setOtherText(copyOtherText(text2.getOtherText()));
    }

    if (STRICT && !copy.equals(text)) {
        throw new IllegalStateException(
                "Was unable to duplicate provided TextSymbolizer:" + text);
    }
    pages.push(copy);
}
 
Example 3
Source File: LabelEngineLayerProperties.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void convert(List<Rule> labelRuleList, Rule rule, JsonElement json, int transparency)
{       
    if((json != null) && (rule != null) && (labelRuleList != null))
    {
        JsonObject jsonObj = json.getAsJsonObject();

        TextSymbolizer textSymbolizer = styleFactory.createTextSymbolizer();

        textSymbolizer.setUnitOfMeasure(NonSI.PIXEL);

        textSymbolizer.setLabel(extractExpression(jsonObj));
        JsonElement jsonElement = jsonObj.get(LabelEngineLayerPropertiesKey.SYMBOL);
        SymbolManager.getInstance().convertTextSymbols(textSymbolizer, transparency, jsonElement);

        // Yes, this really is round the wrong way
        double maxScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MINIMUM_SCALE);
        double minScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MAXIMUM_SCALE);
        
        if((minScale > 0.0) || (maxScale > 0.0))
        {
            Rule labelRule = styleFactory.createRule();

            labelRule.setName(extractString(jsonObj, LabelEngineLayerPropertiesKey.CLASS));
            if(minScale > 0.0)
            {
                labelRule.setMinScaleDenominator(minScale);
            }

            if(maxScale > 0.0)
            {
                labelRule.setMaxScaleDenominator(maxScale);
            }
            labelRule.symbolizers().add(textSymbolizer);
            
            labelRuleList.add(labelRule);
        }
        else
        {
            rule.symbolizers().add(textSymbolizer);
        }
    }
}