Search in sources :

Example 36 with GraphicalSymbol

use of org.opengis.style.GraphicalSymbol in project polymap4-core by Polymap4.

the class PointStyleSerializer method serialize.

@Override
public void serialize(PointStyle style, Style result) {
    // default symbolizer
    Graphic gr = sf.createGraphic(null, new Mark[] {}, null, null, null, null);
    PointSymbolizer point = sf.createPointSymbolizer(gr, null);
    // basics / init symbolizer
    FeatureTypeStyle fts = defaultFeatureTypeStyle(result, style, point);
    fts.setName(style.title.opt().orElse("PointStyle"));
    fts.getDescription().setTitle(style.title.opt().orElse("PointStyle"));
    accessor.set(rule -> (PointSymbolizer) rule.symbolizers().get(0));
    serialize(style, fts);
    // fill
    style.fill.opt().ifPresent(fill -> {
        // color
        set(fts, style.fill.get().color, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            // Mark
            if (symbol instanceof Mark) {
                ((Mark) symbol).getFill().setColor(value);
            } else // ExternalGraphic
            if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "fill", SLDSerializer2.toHexString(literalValue(value)));
                addParam((ExternalGraphic) symbol, "fill-color", SLDSerializer2.toHexString(literalValue(value)));
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
        // opacity
        set(fts, style.fill.get().opacity, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            // Mark
            if (symbol instanceof Mark) {
                ((Mark) symbol).getFill().setOpacity(value);
            } else // ExternalGraphic
            if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "fill-opacity", literalValue(value).toString());
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
    });
    // stroke
    style.stroke.opt().ifPresent(stroke -> {
        // color
        set(fts, style.stroke.get().color, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            if (symbol instanceof Mark) {
                ((Mark) symbol).getStroke().setColor(value);
            } else if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "stroke-color", SLDSerializer2.toHexString(literalValue(value)));
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
        // opacity
        set(fts, style.stroke.get().opacity, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            if (symbol instanceof Mark) {
                ((Mark) symbol).getStroke().setOpacity(value);
            } else if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "stroke-opacity", literalValue(value).toString());
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
        // width
        set(fts, style.stroke.get().width, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            if (symbol instanceof Mark) {
                ((Mark) symbol).getStroke().setWidth(value);
            } else if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "stroke-width", literalValue(value).toString() + "px");
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
    });
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.geotools.styling.Mark) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) ExternalGraphic(org.geotools.styling.ExternalGraphic)

Aggregations

GraphicalSymbol (org.opengis.style.GraphicalSymbol)36 Expression (org.opengis.filter.expression.Expression)23 Graphic (org.geotools.styling.Graphic)16 Fill (org.geotools.styling.Fill)14 Mark (org.geotools.styling.Mark)14 Stroke (org.geotools.styling.Stroke)12 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)11 AnchorPoint (org.geotools.styling.AnchorPoint)11 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)10 Test (org.junit.Test)10 Displacement (org.geotools.styling.Displacement)9 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 GraphicFill (org.opengis.style.GraphicFill)9 ArrayList (java.util.ArrayList)8 ExternalGraphic (org.geotools.styling.ExternalGraphic)7 MarkImpl (org.geotools.styling.MarkImpl)7 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)6 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)6 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)5 ColourFieldConfig (com.sldeditor.ui.detail.ColourFieldConfig)5