use of org.geotools.styling.PointSymbolizer in project sldeditor by robward-scisys.
the class MultiLayerMarkerSymbol method convert.
/**
* Convert.
*
* @param rule the rule
* @param element the element
* @param layerName the layer name
* @param transparency the transparency
*/
@Override
public void convert(Rule rule, JsonElement element, String layerName, int transparency) {
if (rule == null)
return;
if (element == null)
return;
JsonArray layerArray = element.getAsJsonArray();
List<Symbolizer> symbolizerList = rule.symbolizers();
if (layerArray.size() > 0) {
for (int index = 0; index < layerArray.size(); index++) {
JsonObject obj = layerArray.get(index).getAsJsonObject();
JsonElement jsonElement = obj.get(MultiLayerMarkerSymbolKeys.MARKER);
if (jsonElement != null) {
JsonObject asJsonObject = jsonElement.getAsJsonObject();
if (asJsonObject != null) {
List<Graphic> markerList = SymbolManager.getInstance().getMarkerList(asJsonObject);
if (markerList != null) {
for (Graphic marker : markerList) {
PointSymbolizer pointSymbolizer = styleFactory.createPointSymbolizer(marker, null);
symbolizerList.add(pointSymbolizer);
}
}
}
}
}
}
}
use of org.geotools.styling.PointSymbolizer in project sldeditor by robward-scisys.
the class StrokeDetailsTest method testStrokeDetailsCircle.
/**
* Test method for
* {@link com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
*/
@Test
public void testStrokeDetailsCircle() {
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);
PointSymbolizer symbolizer = DefaultSymbols.createDefaultPointSymbolizer();
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);
FieldConfigSymbolType symbolTypeField = (FieldConfigSymbolType) fieldDataManager.get(FieldIdEnum.STROKE_STYLE);
symbolTypeField.populateField("circle");
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);
FieldConfigString dashField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.STROKE_DASH_ARRAY);
String dashArray = "1 2";
dashField.populateField(dashArray);
panel.dataChanged(null);
double actualValue = angleField.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
assertFalse(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.PointSymbolizer in project sldeditor by robward-scisys.
the class PointFillDetailsTest method testFillDetailsPoint.
/**
* Test method for {@link com.sldeditor.ui.detail.PointFillDetailsTest#FillDetails(java.lang.Class, com.sldeditor.filter.v2.function.FunctionNameInterface)}.
*/
@Test
public void testFillDetailsPoint() {
PointFillDetails panel = new PointFillDetails();
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);
PointSymbolizer symbolizer = DefaultSymbols.createDefaultPointSymbolizer();
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.ANGLE);
angleField.populateField(expectedAngle);
FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
double opacity = 0.15;
opacityField.populateField(opacity);
panel.dataChanged(FieldIdEnum.UNKNOWN);
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.PointSymbolizer in project sldeditor by robward-scisys.
the class DefaultSymbols method createNewPoint.
/**
* Creates a new point symbol.
*
* @return the styled layer descriptor
*/
public static StyledLayerDescriptor createNewPoint() {
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
sld.addStyledLayer(namedLayer);
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);
PointSymbolizer point = createDefaultPointSymbolizer();
rule.symbolizers().add(point);
return sld;
}
use of org.geotools.styling.PointSymbolizer in project sldeditor by robward-scisys.
the class DefaultSymbols method createArrow.
/**
* Creates the arrow.
*
* @param angleFunction the angle function
* @param locationFunction the location function
* @param markerSymbol the marker symbol
* @param isSourceArrow the is source arrow
* @return the point symbolizer
*/
private static PointSymbolizer createArrow(FunctionName angleFunction, FunctionName locationFunction, String markerSymbol, boolean isSourceArrow) {
String name = isSourceArrow ? Localisation.getString(SLDTreeTools.class, "TreeItem.sourceArrow") : Localisation.getString(SLDTreeTools.class, "TreeItem.destArrow");
PointSymbolizer pointSymbolizer = createDefaultPointSymbolizer();
pointSymbolizer.setName(name);
Graphic graphic = pointSymbolizer.getGraphic();
graphic.setSize(ff.literal(DEFAULT_ARROW_SIZE));
List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
MarkImpl mark = (MarkImpl) graphicalSymbolList.get(0);
Expression wellKnownName = ff.literal(markerSymbol);
mark.setWellKnownName(wellKnownName);
mark.getFill().setColor(ff.literal(DEFAULT_COLOUR));
// Arrow rotation
List<Expression> rotationArgumentList = new ArrayList<Expression>();
String geometryFieldName = "geom";
DataSourceInterface dsInfo = DataSourceFactory.getDataSource();
if (dsInfo != null) {
geometryFieldName = dsInfo.getGeometryFieldName();
}
rotationArgumentList.add(ff.property(geometryFieldName));
Expression rotation = FunctionManager.getInstance().createExpression(angleFunction, rotationArgumentList);
if (isSourceArrow) {
graphic.setRotation(ff.add(ff.literal(DEGREES_180), rotation));
} else {
graphic.setRotation(rotation);
}
AnchorPoint anchorPoint = styleFactory.anchorPoint(ff.literal(0.5), ff.literal(0.5));
graphic.setAnchorPoint(anchorPoint);
// Set location of the arrow head
List<Expression> endPointArgumentList = new ArrayList<Expression>();
endPointArgumentList.add(ff.property(geometryFieldName));
Expression geometry = FunctionManager.getInstance().createExpression(locationFunction, endPointArgumentList);
pointSymbolizer.setGeometry(geometry);
return pointSymbolizer;
}
Aggregations