use of org.geotools.styling.Mark in project sldeditor by robward-scisys.
the class FieldConfigArrowTest method testAccept.
/**
* Test method for
* {@link com.sldeditor.ui.detail.vendor.geoserver.marker.arrow.FieldConfigArrow#accept(org.opengis.style.GraphicalSymbol)}.
*/
@Test
public void testAccept() {
boolean valueOnly = true;
FieldConfigArrow field = new FieldConfigArrow(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
assertFalse(field.accept(null));
StyleBuilder styleBuilder = new StyleBuilder();
Mark marker1 = styleBuilder.createMark("star");
assertFalse(field.accept(marker1));
Mark marker2 = styleBuilder.createMark("extshape://arrow?hr=1.2&t=0.34&ab=0.56");
assertTrue(field.accept(marker2));
}
use of org.geotools.styling.Mark in project sldeditor by robward-scisys.
the class FieldConfigWindBarbsTest method testAccept.
/**
* Test method for
* {@link com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs#accept(org.opengis.style.GraphicalSymbol)}.
*/
@Test
public void testAccept() {
boolean valueOnly = true;
FieldConfigWindBarbs field = new FieldConfigWindBarbs(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
assertFalse(field.accept(null));
StyleBuilder styleBuilder = new StyleBuilder();
ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
assertFalse(field.accept(externalGraphic));
Mark marker1 = styleBuilder.createMark("triangle");
assertFalse(field.accept(marker1));
Mark marker2 = styleBuilder.createMark("windbarbs://default(15)[kts]");
assertTrue(field.accept(marker2));
}
use of org.geotools.styling.Mark 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.Mark 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