use of org.geotools.styling.PolygonSymbolizer in project sldeditor by robward-scisys.
the class SLDTreeLeafPolygonTest method testRemoveStroke.
/**
* Test method for {@link com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon#removeStroke(org.opengis.style.Symbolizer)}.
*/
@Test
public void testRemoveStroke() {
SLDTreeLeafPolygon leaf = new SLDTreeLeafPolygon();
PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
leaf.removeStroke(polygonSymbolizer);
assertNull(polygonSymbolizer.getStroke());
}
use of org.geotools.styling.PolygonSymbolizer in project sldeditor by robward-scisys.
the class SLDTreeLeafPolygonTest method testHasStroke.
/**
* Test method for {@link com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon#hasStroke(org.opengis.style.Symbolizer)}.
*/
@Test
public void testHasStroke() {
SLDTreeLeafPolygon leaf = new SLDTreeLeafPolygon();
assertFalse(leaf.hasStroke(null));
assertFalse(leaf.hasStroke(DefaultSymbols.createDefaultPointSymbolizer()));
PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
assertTrue(leaf.hasStroke(polygonSymbolizer));
polygonSymbolizer.setStroke(null);
assertFalse(leaf.hasStroke(polygonSymbolizer));
}
use of org.geotools.styling.PolygonSymbolizer in project polymap4-core by Polymap4.
the class DefaultStyles method createPolygonStyle.
/**
* Create a Style to draw polygon features with a thin blue outline and
* a cyan fill
*/
public static Style createPolygonStyle(Style style) {
// create a partially opaque outline stroke
Stroke stroke = sf.createStroke(ff.literal(Color.DARK_GRAY), ff.literal(0.5), ff.literal(0.5));
// create a partial opaque fill
Fill fill = sf.createFill(ff.literal(Color.CYAN), ff.literal(0.5));
/*
* Setting the geometryPropertyName arg to null signals that we want to
* draw the default geometry of features
*/
PolygonSymbolizer sym = sf.createPolygonSymbolizer(stroke, fill, null);
Rule rule = sf.createRule();
rule.setName("Rule for PolygonSymbolizer");
rule.symbolizers().add(sym);
style.featureTypeStyles().get(0).rules().add(rule);
return style;
}
use of org.geotools.styling.PolygonSymbolizer in project polymap4-core by Polymap4.
the class PolygonStyleSerializer method serialize.
@Override
public void serialize(PolygonStyle style, Style result) {
// default symbolizer
PolygonSymbolizer polygon = sf.createPolygonSymbolizer();
polygon.setFill(sf.getDefaultFill());
polygon.setStroke(sf.getDefaultStroke());
FeatureTypeStyle fts = defaultFeatureTypeStyle(result, style, polygon);
fts.setName(style.title.opt().orElse("PolygonStyle"));
fts.getDescription().setTitle(style.title.opt().orElse("PolygonStyle"));
accessor.set(rule -> (PolygonSymbolizer) rule.symbolizers().get(0));
// fill
style.fill.opt().ifPresent(fill -> {
new FillCompositeSerializer(context).accessor.put(rule -> accessor.get().apply(rule).getFill()).serialize(fill, fts);
});
// stroke
style.stroke.opt().ifPresent(stroke -> {
new StrokeCompositeSerializer(context).accessor.put(rule -> accessor.get().apply(rule).getStroke()).serialize(stroke, fts);
});
}
use of org.geotools.styling.PolygonSymbolizer in project hale by halestudio.
the class DefinitionImages method getLegendImage.
/**
* Get a legend image for a given type definition
*
* @param type the type definition
* @param dataSet the data set the type definition belongs to
* @param definedOnly if only for defined styles a image shall be created
* @return the legend image or <code>null</code>
*/
protected BufferedImage getLegendImage(TypeDefinition type, DataSet dataSet, boolean definedOnly) {
StyleService ss = PlatformUI.getWorkbench().getService(StyleService.class);
Style style = (definedOnly) ? (ss.getDefinedStyle(type)) : (ss.getStyle(type, dataSet));
if (style == null) {
return null;
}
// create a dummy feature based on the style
Drawer d = Drawer.create();
SimpleFeature feature = null;
Symbolizer[] symbolizers = SLD.symbolizers(style);
if (symbolizers.length > 0) {
Symbolizer symbolizer = symbolizers[0];
if (symbolizer instanceof LineSymbolizer) {
feature = d.feature(d.line(LINE_POINTS));
} else if (symbolizer instanceof PointSymbolizer) {
feature = d.feature(d.point(WIDTH / 2, HEIGHT / 2));
}
if (symbolizer instanceof PolygonSymbolizer) {
feature = d.feature(d.polygon(POLY_POINTS));
}
}
if (feature != null) {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
// GraphicsEnvironment.getLocalGraphicsEnvironment().
// getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(WIDTH, HEIGHT,
// Transparency.TRANSLUCENT);
// use white background to have a neutral color even if selected
Color bg = Color.WHITE;
Graphics2D g = image.createGraphics();
try {
g.setColor(bg);
g.fillRect(0, 0, WIDTH, HEIGHT);
} finally {
g.dispose();
}
d.drawDirect(image, feature, style);
return image;
}
return null;
}
Aggregations