use of org.geotools.styling.LineSymbolizer in project sldeditor by robward-scisys.
the class LineSymbolizerDetails method updateSymbol.
/**
* Update symbol.
*/
private void updateSymbol() {
if (!Controller.getInstance().isPopulating()) {
Expression perpendicularOffset = fieldConfigVisitor.getExpression(FieldIdEnum.PERPENDICULAR_OFFSET);
Expression geometryField = ExtractGeometryField.getGeometryField(fieldConfigVisitor);
StandardData standardData = getStandardData();
LineSymbolizer lineSymbolizer = (LineSymbolizer) SelectedSymbol.getInstance().getSymbolizer();
if (lineSymbolizer != null) {
lineSymbolizer.setName(standardData.name);
lineSymbolizer.setDescription(standardData.description);
lineSymbolizer.setUnitOfMeasure(standardData.unit);
lineSymbolizer.setGeometry(geometryField);
lineSymbolizer.setPerpendicularOffset(perpendicularOffset);
this.fireUpdateSymbol();
}
}
}
use of org.geotools.styling.LineSymbolizer in project sldeditor by robward-scisys.
the class CreateInternalDataSourceTest method testDetermineGeometryType.
/**
* Test method for
* {@link com.sldeditor.datasource.impl.CreateInternalDataSource#determineGeometryType(StyledLayerDescriptor)}.
*/
@Test
public void testDetermineGeometryType() {
TestCreateInternalDataSource ds = new TestCreateInternalDataSource();
assertEquals(GeometryTypeEnum.UNKNOWN, ds.callDetermineGeometryType(null));
// Create StyledLayerDescriptor
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
sld.addStyledLayer(namedLayer);
UserLayer userLayer = styleFactory.createUserLayer();
sld.addStyledLayer(userLayer);
Style style = styleFactory.createStyle();
namedLayer.addStyle(style);
List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
ftsList.add(fts);
Rule rule = styleFactory.createRule();
fts.rules().add(rule);
// Raster
RasterSymbolizer raster = DefaultSymbols.createDefaultRasterSymbolizer();
rule.symbolizers().add(raster);
assertEquals(GeometryTypeEnum.RASTER, ds.callDetermineGeometryType(sld));
// Polygon
rule.symbolizers().clear();
PolygonSymbolizer polygon = DefaultSymbols.createDefaultPolygonSymbolizer();
rule.symbolizers().add(polygon);
assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
// Line
rule.symbolizers().clear();
LineSymbolizer line = DefaultSymbols.createDefaultLineSymbolizer();
rule.symbolizers().add(line);
assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
// Point
rule.symbolizers().clear();
PointSymbolizer point = DefaultSymbols.createDefaultPointSymbolizer();
rule.symbolizers().add(point);
assertEquals(GeometryTypeEnum.POINT, ds.callDetermineGeometryType(sld));
// Add line to point
rule.symbolizers().add(line);
assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
// Add point, line
rule.symbolizers().clear();
rule.symbolizers().add(line);
rule.symbolizers().add(point);
assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
// Add polygon, line
rule.symbolizers().clear();
rule.symbolizers().add(point);
rule.symbolizers().add(polygon);
assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
}
use of org.geotools.styling.LineSymbolizer in project sldeditor by robward-scisys.
the class LineSymbolizerDetailsTest method testLineSymbolizerDetails.
/**
* Test method for {@link com.sldeditor.ui.detail.LineSymbolizerDetails#LineSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
* Test method for {@link com.sldeditor.ui.detail.LineSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
* Test method for {@link com.sldeditor.ui.detail.LineSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
* Test method for {@link com.sldeditor.ui.detail.LineSymbolizerDetails#getFieldDataManager()}.
* Test method for {@link com.sldeditor.ui.detail.LineSymbolizerDetails#isDataPresent()}.
* Test method for {@link com.sldeditor.ui.detail.LineSymbolizerDetails#preLoadSymbol()}.
*/
@Test
public void testLineSymbolizerDetails() {
LineSymbolizerDetails panel = new LineSymbolizerDetails();
panel.populate(null);
// Set up test data
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
SelectedSymbol.getInstance().createNewSLD(sld);
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
String expectedNameLayerValue = "named layer test value";
namedLayer.setName(expectedNameLayerValue);
Style style = DefaultSymbols.createNewStyle();
String expectedNameStyleValue = "style test value";
style.setName(expectedNameStyleValue);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedNameFTSValue = "feature type style test value";
fts.setName(expectedNameFTSValue);
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
String expectedRuleValue = "rule test value";
rule.setName(expectedRuleValue);
LineSymbolizer symbolizer = DefaultSymbols.createDefaultLineSymbolizer();
String expectedNameValue = "symbolizer test value";
symbolizer.setName(expectedNameValue);
rule.symbolizers().add(symbolizer);
fts.rules().add(rule);
sld.layers().add(namedLayer);
SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyle(style);
SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
SelectedSymbol.getInstance().setRule(rule);
SelectedSymbol.getInstance().setSymbolizer(symbolizer);
panel.populate(SelectedSymbol.getInstance());
GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
assertNotNull(fieldDataManager);
panel.dataChanged(null);
FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
assertNull(nameField);
assertTrue(panel.isDataPresent());
// Reset to default value
panel.preLoadSymbol();
}
use of org.geotools.styling.LineSymbolizer in project sldeditor by robward-scisys.
the class StrokeDetailsTest method testStrokeDetailsLine.
/**
* Test method for
* {@link com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testStrokeDetailsLine() {
StrokeDetails panel = new StrokeDetails();
panel.populate(null);
// Set up test data
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
SelectedSymbol.getInstance().createNewSLD(sld);
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
String expectedNameLayerValue = "named layer test value";
namedLayer.setName(expectedNameLayerValue);
Style style = DefaultSymbols.createNewStyle();
String expectedNameStyleValue = "style test value";
style.setName(expectedNameStyleValue);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedNameFTSValue = "feature type style test value";
fts.setName(expectedNameFTSValue);
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
String expectedNameValue = "rule test value";
rule.setName(expectedNameValue);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Stroke stroke = styleFactory.getDefaultStroke();
SymbolTypeFactory fillFactory = new SymbolTypeFactory(StrokeDetails.class, new ColourFieldConfig(GroupIdEnum.FILLCOLOUR, FieldIdEnum.STROKE_FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH), new ColourFieldConfig(GroupIdEnum.STROKECOLOUR, FieldIdEnum.STROKE_FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH), FieldIdEnum.STROKE_STYLE);
fillFactory.populate(panel, panel.getFieldDataManager());
Expression symbolType = ff.literal("star");
List<GraphicalSymbol> symbols = fillFactory.getValue(panel.getFieldDataManager(), symbolType, true, true, FieldConfigMarker.class);
Expression initalGap = ff.literal(0);
Expression gap = ff.literal(0);
GraphicStroke graphicStroke = styleFactory.graphicStroke(symbols, null, ff.literal(10), ff.literal(0), styleFactory.createAnchorPoint(ff.literal(0.5), ff.literal(0.75)), styleFactory.createDisplacement(ff.literal(0.35), ff.literal(0.12)), initalGap, gap);
stroke.setDashArray(new float[] { 1.0f, 2.0f, 3.0f });
stroke.setGraphicStroke(graphicStroke);
LineSymbolizer symbolizer = DefaultSymbols.createDefaultLineSymbolizer();
symbolizer.setStroke(stroke);
rule.symbolizers().add(symbolizer);
fts.rules().add(rule);
sld.layers().add(namedLayer);
SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyle(style);
SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
SelectedSymbol.getInstance().setRule(rule);
SelectedSymbol.getInstance().setSymbolizer(symbolizer);
panel.populate(SelectedSymbol.getInstance());
GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
assertNotNull(fieldDataManager);
double expectedAngle = 14.5;
FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.STROKE_SYMBOL_ANGLE);
angleField.populateField(expectedAngle);
FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
double opacity = 0.15;
opacityField.populateField(opacity);
panel.dataChanged(null);
double actualValue = angleField.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
assertTrue(panel.isDataPresent());
actualValue = opacityField.getDoubleValue();
assertTrue(Math.abs(actualValue - opacity) < 0.01);
// Reset to default value
panel.preLoadSymbol();
actualValue = angleField.getDoubleValue();
assertTrue(Math.abs(actualValue - 0.0) < 0.01);
actualValue = opacityField.getDoubleValue();
assertTrue(Math.abs(actualValue - 1.0) < 0.01);
}
use of org.geotools.styling.LineSymbolizer in project polymap4-core by Polymap4.
the class LineStyleSerializer method serialize.
@Override
public void serialize(LineStyle style, Style result) {
FeatureTypeStyle fts = defaultFeatureTypeStyle(result, style);
// stroke line: 1st LineSymbolizer
LineSymbolizer strokeLine = sf.createLineSymbolizer();
strokeLine.setStroke(sf.getDefaultStroke());
fts.rules().get(0).symbolizers().add(strokeLine);
// accessor.set( rule -> (LineSymbolizer)rule.symbolizers().get( 0 ) );
// style.stroke.opt().ifPresent( stroke -> {
// new StrokeCompositeSerializer( context )
// .accessor.put( rule -> accessor.get().apply( rule ).getStroke() )
// .serialize( stroke, fts );
// });
// inner line: 2nd LineSymbolizer
LineSymbolizer innerLine = sf.createLineSymbolizer();
innerLine.setStroke(sf.getDefaultStroke());
fts.rules().get(0).symbolizers().add(innerLine);
// accessor.set( rule -> (LineSymbolizer)rule.symbolizers().get( 1 ) );
// style.fill.opt().ifPresent( fillStroke -> {
// new StrokeCompositeSerializer( context )
// .accessor.put( rule -> accessor.get().apply( rule ).getStroke() )
// .serialize( fillStroke, fts );
// });
serialize(style, fts);
}
Aggregations