use of org.geotools.styling.Graphic in project sldeditor by robward-scisys.
the class CharacterMarkerSymbol method convert.
/**
* Convert.
*
* @param element the element
* @return the marker graphic
*/
@Override
public List<Graphic> convert(JsonElement element) {
if (element == null)
return null;
JsonObject obj = element.getAsJsonObject();
List<Graphic> markerList = new ArrayList<Graphic>();
double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
double symbolSize = getDouble(obj, CommonSymbolKeys.SIZE);
double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
JsonElement fontElement = obj.get(CharacterMarkerSymbolKeys.FONT);
if (fontElement != null) {
JsonObject fontObj = fontElement.getAsJsonObject();
String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME);
int code = getInt(obj, CharacterMarkerSymbolKeys.CHARACTER_INDEX);
Expression wellKnownName = ff.literal(String.format("ttf://%s#%s", fontName, code));
// Create colour
Expression colour = getColour(obj.get(CommonSymbolKeys.COLOUR));
Fill fill = styleFactory.createFill(colour);
Stroke stroke = null;
Mark mark = styleFactory.mark(wellKnownName, fill, stroke);
ExternalGraphic[] externalGraphics = null;
Mark[] marks = new Mark[1];
marks[0] = mark;
Symbol[] symbols = null;
Expression opacity = null;
Expression rotation = ff.literal(angle);
Expression size = ff.literal(symbolSize);
Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, opacity, size, rotation);
// Displacement (offsets)
if ((xOffset > 0.0) && (yOffset > 0.0)) {
Expression expressionX = ff.literal(xOffset);
Expression expressionY = ff.literal(yOffset);
Displacement displacement = styleFactory.createDisplacement(expressionX, expressionY);
graphic.setDisplacement(displacement);
}
markerList.add(graphic);
}
return markerList;
}
use of org.geotools.styling.Graphic 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.Graphic in project sldeditor by robward-scisys.
the class SimpleMarkerSymbol method convert.
/**
* Convert.
*
* @param element the element
* @return the graphic marker list
*/
@Override
public List<Graphic> convert(JsonElement element) {
if (element == null)
return null;
JsonObject obj = element.getAsJsonObject();
List<Graphic> markList = new ArrayList<Graphic>();
double angle = getDouble(obj, CommonSymbolKeys.ANGLE);
double outlineSize = getDouble(obj, SimpleMarkerSymbolKeys.OUTLINE_SIZE);
double size = getDouble(obj, CommonSymbolKeys.SIZE);
int style = getInt(obj, CommonSymbolKeys.STYLE);
double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET);
double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET);
Expression markerColour = getColour(obj.get(CommonSymbolKeys.COLOUR));
Expression outlineColour = getColour(obj.get(SimpleMarkerSymbolKeys.OUTLINE_COLOUR));
Expression wellKnownName = ff.literal(styleMap.get(style));
Stroke stroke = null;
if (outlineSize > 0.0) {
stroke = styleFactory.createStroke(outlineColour, ff.literal(outlineSize));
}
Fill fill = styleFactory.createFill(markerColour);
Mark mark = styleFactory.createMark(wellKnownName, stroke, fill, ff.literal(size), ff.literal(angle));
Expression expressionOpacity = null;
ExternalGraphic[] externalGraphics = null;
Symbol[] symbols = null;
Mark[] marks = new Mark[1];
marks[0] = mark;
Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, expressionOpacity, ff.literal(size), ff.literal(angle));
// Set offset
if ((xOffset > 0.0) && (yOffset > 0.0)) {
Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset));
graphic.setDisplacement(displacement);
}
markList.add(graphic);
return markList;
}
use of org.geotools.styling.Graphic in project sldeditor by robward-scisys.
the class SymbolManager method getMarkerList.
/**
* Gets the marker list.
*
* @param jsonSymbol the json symbol
* @return the marker list
*/
public List<Graphic> getMarkerList(JsonObject jsonSymbol) {
List<Graphic> markList = null;
for (String markSymbolType : markSymbolMap.keySet()) {
JsonElement obj = jsonSymbol.get(markSymbolType);
if (obj != null) {
EsriMarkSymbolInterface esriMarkSymbol = markSymbolMap.get(markSymbolType);
markList = esriMarkSymbol.convert(obj);
break;
}
}
return markList;
}
use of org.geotools.styling.Graphic in project sldeditor by robward-scisys.
the class VOGeoServerTextSymbolizer2Test method testVOGeoServerTextSymbolizer2.
/**
* Test method for
* {@link com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSymbolizer2#VOGeoServerTextSymbolizer2(java.lang.Class, com.sldeditor.filter.v2.function.FunctionNameInterface)}.
*/
@Test
public void testVOGeoServerTextSymbolizer2() {
TextSymbolizerDetails panel = new TextSymbolizerDetails();
TextSymbolizer2 textSymbolizer = null;
VOGeoServerTextSymbolizer2 testObj = new VOGeoServerTextSymbolizer2(panel.getClass());
testObj.setParentPanel(panel);
testObj.populate(textSymbolizer);
testObj.updateSymbol(textSymbolizer);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
textSymbolizer = (TextSymbolizer2) styleFactory.createTextSymbolizer();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Literal featureDescription = ff.literal("feature description");
textSymbolizer.setFeatureDescription(featureDescription);
OtherText otherText = new OtherTextImpl();
otherText.setTarget("target");
Literal otherTextExpression = ff.literal("other text");
otherText.setText(otherTextExpression);
textSymbolizer.setOtherText(otherText);
Literal snippet = ff.literal("snippet");
textSymbolizer.setSnippet(snippet);
// Try with marker symbol
Graphic graphic = styleFactory.createDefaultGraphic();
graphic.graphicalSymbols().add(styleFactory.createMark());
textSymbolizer.setGraphic(graphic);
Controller.getInstance().setPopulating(true);
testObj.populate(textSymbolizer);
Controller.getInstance().setPopulating(false);
testObj.updateSymbol(textSymbolizer);
// Try with external graphic
graphic = styleFactory.createDefaultGraphic();
try {
graphic.graphicalSymbols().add(styleFactory.createExternalGraphic(new File("test.png").toURI().toURL(), "png"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
textSymbolizer.setGraphic(graphic);
Controller.getInstance().setPopulating(true);
testObj.populate(textSymbolizer);
Controller.getInstance().setPopulating(false);
testObj.updateSymbol(textSymbolizer);
// Find minimum version with textSymbolizer2 values set
List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
testObj.getMinimumVersion(null, textSymbolizer, vendorOptionsPresentList);
assertEquals(1, vendorOptionsPresentList.size());
// Find minimum version with no textSymbolizer2 values set
vendorOptionsPresentList.clear();
testObj.getMinimumVersion(null, styleFactory.createTextSymbolizer(), vendorOptionsPresentList);
assertEquals(0, vendorOptionsPresentList.size());
// Get the code coverage values up
testObj.populate(SelectedSymbol.getInstance());
PolygonSymbolizer polygon = null;
testObj.populate(polygon);
testObj.updateSymbol(polygon);
RasterSymbolizer raster = null;
testObj.populate(raster);
testObj.updateSymbol(raster);
testObj.preLoadSymbol();
assertTrue(testObj.isDataPresent());
}
Aggregations