use of org.geotools.styling.LineSymbolizer in project polymap4-core by Polymap4.
the class StyleModelTest method testSimpleLine.
@Test
public void testSimpleLine() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
LineStyle style = fs.members().createElement(LineStyle.defaults);
assertTrue(style.visibleIf.get() instanceof ConstantFilter);
style.fill.get().color.createValue(ConstantColor.defaults(0, 0, 0));
style.fill.get().width.createValue(ConstantNumber.defaults(5.0));
style.fill.get().opacity.createValue(ConstantNumber.defaults(0.0));
style.stroke.get().color.createValue(ConstantColor.defaults(100, 100, 100));
style.stroke.get().width.createValue(ConstantNumber.defaults(5.0));
style.stroke.get().opacity.createValue(ConstantNumber.defaults(0.5));
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
Style result = repo.serializedFeatureStyle(fs.id(), Style.class).get();
assertEquals(1, result.featureTypeStyles().size());
FeatureTypeStyle fts = result.featureTypeStyles().get(0);
assertEquals(1, fts.rules().size());
Rule rule = fts.rules().get(0);
assertEquals(0, rule.getMinScaleDenominator(), 0);
assertEquals(Double.POSITIVE_INFINITY, rule.getMaxScaleDenominator(), 0);
assertEquals(2, rule.symbolizers().size());
assertNull(rule.getFilter());
LineSymbolizer strokeLine = (LineSymbolizer) rule.symbolizers().get(0);
assertEqualsLiteral(0.5, strokeLine.getStroke().getOpacity());
assertEqualsLiteral(15.0, strokeLine.getStroke().getWidth());
LineSymbolizer fillLine = (LineSymbolizer) rule.symbolizers().get(1);
assertEqualsLiteral(0.0, fillLine.getStroke().getOpacity());
assertEqualsLiteral(5.0, fillLine.getStroke().getWidth());
}
use of org.geotools.styling.LineSymbolizer 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;
}
use of org.geotools.styling.LineSymbolizer in project hale by halestudio.
the class SimpleLineStylePage method createControl.
/**
* @see IDialogPage#createControl(Composite)
*/
@Override
public void createControl(Composite parent) {
// create new controls
Composite page = new Composite(parent, SWT.NONE);
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
page.setLayout(layout);
Style style = getParent().getStyle();
LineSymbolizer line = null;
try {
Symbolizer[] symbolizers = SLD.symbolizers(style);
for (Symbolizer symbol : symbolizers) {
if (symbol instanceof LineSymbolizer) {
line = (LineSymbolizer) symbol;
break;
}
}
} catch (Exception e) {
// ignore
}
if (line == null) {
line = styleBuilder.createLineSymbolizer();
}
lineEditor = new LineSymbolizerEditor(page, line);
setControl(page);
}
use of org.geotools.styling.LineSymbolizer in project hale by halestudio.
the class SimplePointStylePage method createControl.
/**
* @see IDialogPage#createControl(Composite)
*/
@Override
public void createControl(Composite parent) {
// create new controls
Composite page = new Composite(parent, SWT.NONE);
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
page.setLayout(layout);
Style style = getParent().getStyle();
PointSymbolizer point = null;
try {
Symbolizer[] symbolizers = SLD.symbolizers(style);
for (Symbolizer symbol : symbolizers) {
if (symbol instanceof LineSymbolizer) {
point = (PointSymbolizer) symbol;
break;
}
}
} catch (Exception e) {
// ignore
}
if (point == null) {
point = styleBuilder.createPointSymbolizer();
}
pointEditor = new PointSymbolizerEditor(page, point);
setControl(page);
}
use of org.geotools.styling.LineSymbolizer 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;
}
Aggregations