Search in sources :

Example 31 with Graphic

use of org.geotools.styling.Graphic in project sldeditor by robward-scisys.

the class PointFillDetails method getGraphic.

/**
 * Gets the graphic.
 *
 * @return the graphic
 */
private Graphic getGraphic() {
    AnchorPoint anchor = null;
    Displacement displacement = null;
    Expression symbolType = fieldConfigVisitor.getExpression(FieldIdEnum.SYMBOL_TYPE);
    GroupConfigInterface fillGroup = getGroup(GroupIdEnum.FILL);
    boolean hasFill = fillGroup.isPanelEnabled();
    GroupConfigInterface strokeGroup = getGroup(GroupIdEnum.STROKE);
    boolean hasStroke = (strokeGroup == null) ? false : strokeGroup.isPanelEnabled();
    Expression opacity = fieldConfigVisitor.getExpression(FieldIdEnum.OVERALL_OPACITY);
    Expression size = fieldConfigVisitor.getExpression(FieldIdEnum.SIZE);
    Expression rotation = fieldConfigVisitor.getExpression(FieldIdEnum.ANGLE);
    // 
    // Anchor point
    // 
    GroupConfigInterface anchorPointPanel = getGroup(GroupIdEnum.ANCHORPOINT);
    if (anchorPointPanel.isPanelEnabled()) {
        anchor = (AnchorPoint) getStyleFactory().anchorPoint(fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_H), fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_V));
        // so it doesn't appear in the SLD
        if (DetailsUtilities.isSame(AnchorPoint.DEFAULT, anchor)) {
            anchor = null;
        }
    }
    // 
    // Displacement
    // 
    GroupConfigInterface displacementPanel = getGroup(GroupIdEnum.DISPLACEMENT);
    if (displacementPanel.isPanelEnabled()) {
        displacement = getStyleFactory().displacement(fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_X), fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_Y));
        // it doesn't appear in the SLD
        if (DetailsUtilities.isSame(Displacement.DEFAULT, displacement)) {
            displacement = null;
        }
    }
    List<GraphicalSymbol> symbols = symbolTypeFactory.getValue(fieldConfigManager, symbolType, hasFill, hasStroke, selectedFillPanelId);
    boolean overallOpacity = symbolTypeFactory.isOverallOpacity(PointSymbolizer.class, selectedFillPanelId);
    Graphic graphic = getStyleFactory().graphic(symbols, null, size, rotation, anchor, displacement);
    Expression gap = fieldConfigVisitor.getExpression(FieldIdEnum.GAP);
    Expression initialGap = fieldConfigVisitor.getExpression(FieldIdEnum.INITIAL_GAP);
    graphic.setInitialGap(initialGap);
    graphic.setGap(gap);
    if (overallOpacity) {
        graphic.setOpacity(opacity);
    }
    return graphic;
}
Also used : AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) Displacement(org.geotools.styling.Displacement)

Example 32 with Graphic

use of org.geotools.styling.Graphic in project sldeditor by robward-scisys.

the class PointFillDetails method populate.

/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    Expression expSize = null;
    Expression expRotation = null;
    Expression expAnchorPointX = null;
    Expression expAnchorPointY = null;
    Expression expDisplacementX = null;
    Expression expDisplacementY = null;
    Expression expGap = null;
    Expression expInitialGap = null;
    PointSymbolizer pointSymbolizer = null;
    if (selectedSymbol != null) {
        Symbolizer symbolizer = selectedSymbol.getSymbolizer();
        if (symbolizer instanceof PointSymbolizerImpl) {
            pointSymbolizer = (PointSymbolizer) symbolizer;
            Graphic graphic = pointSymbolizer.getGraphic();
            if (graphic != null) {
                expSize = graphic.getSize();
                expRotation = graphic.getRotation();
                // Anchor point
                AnchorPoint anchorPoint = graphic.getAnchorPoint();
                if (anchorPoint != null) {
                    expAnchorPointX = anchorPoint.getAnchorPointX();
                    expAnchorPointY = anchorPoint.getAnchorPointY();
                } else {
                    expAnchorPointX = AnchorPoint.DEFAULT.getAnchorPointX();
                    expAnchorPointY = AnchorPoint.DEFAULT.getAnchorPointY();
                }
                // Offset
                Displacement displacement = graphic.getDisplacement();
                if (displacement != null) {
                    expDisplacementX = displacement.getDisplacementX();
                    expDisplacementY = displacement.getDisplacementY();
                } else {
                    expDisplacementX = Displacement.DEFAULT.getDisplacementX();
                    expDisplacementY = Displacement.DEFAULT.getDisplacementY();
                }
                expGap = graphic.getGap();
                expInitialGap = graphic.getInitialGap();
                List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
                if (!graphicalSymbolList.isEmpty()) {
                    GraphicalSymbol symbol = graphicalSymbolList.get(0);
                    symbolTypeFactory.setValue(PointSymbolizer.class, this.fieldConfigManager, graphic, symbol);
                }
            }
        }
    }
    fieldConfigVisitor.populateField(FieldIdEnum.SIZE, expSize);
    fieldConfigVisitor.populateField(FieldIdEnum.ANGLE, expRotation);
    fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_H, expAnchorPointX);
    fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_V, expAnchorPointY);
    fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_X, expDisplacementX);
    fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_Y, expDisplacementY);
    fieldConfigVisitor.populateField(FieldIdEnum.GAP, expGap);
    fieldConfigVisitor.populateField(FieldIdEnum.INITIAL_GAP, expInitialGap);
    if (vendorOptionFillFactory != null) {
        vendorOptionFillFactory.populate(pointSymbolizer);
    }
    updateSymbol();
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) PointSymbolizer(org.geotools.styling.PointSymbolizer) Symbolizer(org.opengis.style.Symbolizer) PointSymbolizerImpl(org.geotools.styling.PointSymbolizerImpl) Displacement(org.geotools.styling.Displacement)

Example 33 with Graphic

use of org.geotools.styling.Graphic 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)

Example 34 with Graphic

use of org.geotools.styling.Graphic in project polymap4-core by Polymap4.

the class DefaultStyles method createPointStyle.

/**
 * Create a Style to draw point features as circles with blue outlines
 * and cyan fill
 */
public static Style createPointStyle(Style style) {
    Graphic gr = sf.createDefaultGraphic();
    Mark mark = sf.getCircleMark();
    mark.setStroke(sf.createStroke(ff.literal(Color.RED), ff.literal(1.5)));
    mark.setFill(sf.createFill(ff.literal(Color.YELLOW)));
    gr.graphicalSymbols().clear();
    gr.graphicalSymbols().add(mark);
    gr.setSize(ff.literal(8));
    /*
         * Setting the geometryPropertyName arg to null signals that we want to draw
         * the default geometry of features
         */
    PointSymbolizer sym = sf.createPointSymbolizer(gr, null);
    Rule rule = sf.createRule();
    rule.symbolizers().add(sym);
    rule.setName("Rule for PointSymbolizer");
    style.featureTypeStyles().get(0).rules().add(rule);
    return style;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Graphic(org.geotools.styling.Graphic) Mark(org.geotools.styling.Mark) Rule(org.geotools.styling.Rule)

Aggregations

Graphic (org.geotools.styling.Graphic)34 PointSymbolizer (org.geotools.styling.PointSymbolizer)17 GraphicalSymbol (org.opengis.style.GraphicalSymbol)16 Fill (org.geotools.styling.Fill)13 Expression (org.opengis.filter.expression.Expression)12 ExternalGraphic (org.geotools.styling.ExternalGraphic)11 Stroke (org.geotools.styling.Stroke)10 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)9 AnchorPoint (org.geotools.styling.AnchorPoint)8 Displacement (org.geotools.styling.Displacement)8 ArrayList (java.util.ArrayList)7 Mark (org.geotools.styling.Mark)7 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)6 MarkImpl (org.geotools.styling.MarkImpl)6 Rule (org.geotools.styling.Rule)6 JsonObject (com.google.gson.JsonObject)5 LineSymbolizer (org.geotools.styling.LineSymbolizer)5 JsonElement (com.google.gson.JsonElement)4 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)4 NamedLayer (org.geotools.styling.NamedLayer)4