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;
}
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();
}
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);
}
});
});
}
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;
}
Aggregations