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