use of org.geotools.styling.PolygonSymbolizer in project hale by halestudio.
the class StyleHelper method createPolygonStyle.
/**
* Create a default polygon style.
*
* @param color the polygon color
* @param width the line width
* @return a Style for Polygon objects
*/
private static FeatureTypeStyle createPolygonStyle(Color color, double width) {
PolygonSymbolizer symbolizer = createPolygonSymbolizer(color, width);
Rule rule = styleFactory.createRule();
rule.symbolizers().add(symbolizer);
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
fts.rules().add(rule);
return fts;
}
use of org.geotools.styling.PolygonSymbolizer in project hale by halestudio.
the class StyleHelper method createPolygonSymbolizer.
/**
* Create a default polygon symbolizer.
*
* @param color the color
* @param width the line width
* @return the polygon symbolizer
*/
public static PolygonSymbolizer createPolygonSymbolizer(Color color, double width) {
PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer();
SLD.setPolyColour(symbolizer, color);
symbolizer.getStroke().setWidth(filterFactory.literal(width));
Fill fill = styleFactory.createFill(filterFactory.literal(color), filterFactory.literal(DEFAULT_FILL_OPACITY));
symbolizer.setFill(fill);
return symbolizer;
}
use of org.geotools.styling.PolygonSymbolizer in project hale by halestudio.
the class StyleServiceImpl method getSelectionSymbolizers.
/**
* Get the symbolizers representing the given symbolizer for a selection
*
* @param symbolizer the symbolizer
*
* @return the selection symbolizers
*/
private List<Symbolizer> getSelectionSymbolizers(Symbolizer symbolizer) {
List<Symbolizer> result = new ArrayList<Symbolizer>();
Color color = StylePreferences.getSelectionColor();
int width = StylePreferences.getSelectionWidth();
if (symbolizer instanceof PolygonSymbolizer) {
result.add(StyleHelper.createPolygonSymbolizer(color, width));
} else if (symbolizer instanceof LineSymbolizer) {
result.add(StyleHelper.createLineSymbolizer(color, width));
} else if (symbolizer instanceof PointSymbolizer) {
result.add(StyleHelper.mutatePointSymbolizer((PointSymbolizer) symbolizer, color, width));
// result.add(createPointSymbolizer(color, width));
} else {
// do not fall-back to original symbolizer cause we are painting
// over it
// result.add(symbolizer);
}
return result;
}
use of org.geotools.styling.PolygonSymbolizer in project hale by halestudio.
the class StyledInstanceMarker method strokeStyle.
/**
* retrieves the stroke for the map marker
*
* @param rule a certain rule to apply, maybe null
* @param context the InstanceWayPoint, wich gets marked
*/
private synchronized void strokeStyle(Rule rule, InstanceWaypoint context) {
// retrieve stroke
Stroke stroke = null;
for (int i = 0; rule != null && stroke == null && i < rule.getSymbolizers().length; i++) {
if (rule.getSymbolizers()[i] instanceof LineSymbolizer) {
stroke = SLD.stroke((LineSymbolizer) rule.getSymbolizers()[i]);
} else if (rule.getSymbolizers()[i] instanceof PolygonSymbolizer) {
stroke = SLD.stroke((PolygonSymbolizer) rule.getSymbolizers()[i]);
} else if (rule.getSymbolizers()[i] instanceof PointSymbolizer) {
stroke = SLD.stroke((PointSymbolizer) rule.getSymbolizers()[i]);
}
}
// if we have a stroke now
if (stroke != null) {
// XXX is there any Geotools stroke to AWT stroke lib/code
// somewhere?!
// XXX have a look at the renderer code (StreamingRenderer)
// stroke color
Color sldColor = SLD.color(stroke);
double opacity = SLD.opacity(stroke);
if (Double.isNaN(opacity)) {
// fall back to default opacity
opacity = StyleHelper.DEFAULT_FILL_OPACITY;
}
if (sldColor != null) {
styleStrokeColor = new Color(sldColor.getRed(), sldColor.getGreen(), sldColor.getBlue(), (int) (opacity * 255));
} else {
styleStrokeColor = super.getBorderColor(context);
}
// stroke width
int strokeWidth = SLD.width(stroke);
if (strokeWidth == SLD.NOTFOUND) {
// fall back to default width
strokeWidth = StylePreferences.getDefaultWidth();
}
styleStroke = new BasicStroke(strokeWidth);
} else {
styleStroke = null;
styleStrokeColor = null;
}
}
use of org.geotools.styling.PolygonSymbolizer in project sldeditor by robward-scisys.
the class SelectedSymbolTest method testReplacment.
/**
* Test method for
* {@link com.sldeditor.common.data.SelectedSymbol#removeRule(org.geotools.styling.Rule)}.
*/
@Test
public void testReplacment() {
SelectedSymbol.destroyInstance();
SelectedSymbol instance = SelectedSymbol.getInstance();
Rule rule = DefaultSymbols.createNewRule();
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
Style style = DefaultSymbols.createNewStyle();
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
PolygonSymbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
instance.createNewSLD(sld);
instance.setSld(sld);
instance.addNewStyledLayer(namedLayer);
instance.setStyledLayer(namedLayer);
instance.addNewStyle(style);
instance.setStyle(style);
instance.addNewFeatureTypeStyle(fts);
instance.setFeatureTypeStyle(fts);
instance.addNewRule(rule);
instance.setRule(rule);
instance.addSymbolizerToRule(polygonSymbolizer);
instance.addNewRule(DefaultSymbols.createNewRule());
instance.setSymbolizer(polygonSymbolizer);
LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
DummySLDTreeUpdated dummyTreeUpdated = new DummySLDTreeUpdated();
instance.setTreeUpdateListener(dummyTreeUpdated);
instance.replaceSymbolizer(lineSymbolizer);
assertEquals(lineSymbolizer, instance.getSymbolizer());
assertEquals(dummyTreeUpdated.objectOld, polygonSymbolizer);
assertEquals(dummyTreeUpdated.objectNew, lineSymbolizer);
Rule newRule = DefaultSymbols.createNewRule();
newRule.setTitle("Replacement rule");
instance.replaceRule(newRule);
assertEquals(newRule, instance.getRule());
assertNull(instance.getSymbolizer());
FeatureTypeStyle newFts = DefaultSymbols.createNewFeatureTypeStyle();
newFts.setName("Replacement fts");
instance.replaceFeatureTypeStyle(newFts);
assertEquals(newFts, instance.getFeatureTypeStyle());
assertNull(instance.getRule());
Style newStyle = DefaultSymbols.createNewStyle();
newStyle.setName("Replacement style");
instance.replaceStyle(newStyle);
assertEquals(newStyle, instance.getStyle());
assertNull(instance.getRule());
NamedLayer newNamedLayer = DefaultSymbols.createNewNamedLayer();
newNamedLayer.setName("Replacement named layer");
instance.replaceStyledLayer(newNamedLayer);
assertEquals(newNamedLayer, instance.getStyledLayer());
assertNull(instance.getStyle());
}
Aggregations