use of org.geotools.styling.ExternalGraphic 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.ExternalGraphic 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.ExternalGraphic in project sldeditor by robward-scisys.
the class UpdateGraphicalSymbol method processGraphicalSymbol.
/*
* (non-Javadoc)
*
* @see com.sldeditor.common.data.ProcessGraphicSymbolInterface#processGraphicalSymbol(java.net.URL, java.util.List, java.util.List)
*/
@Override
public void processGraphicalSymbol(URL resourceLocator, List<GraphicalSymbol> graphicalSymbolList, List<String> externalImageList) {
for (GraphicalSymbol symbol : graphicalSymbolList) {
if (symbol instanceof ExternalGraphic) {
ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) symbol;
OnLineResourceImpl onlineResource = (OnLineResourceImpl) externalGraphic.getOnlineResource();
String currentValue = null;
URL currentValueURL = null;
try {
currentValueURL = onlineResource.getLinkage().toURL();
currentValue = currentValueURL.toExternalForm();
} catch (MalformedURLException e) {
ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
}
if ((resourceLocator == null) || RelativePath.hasHost(currentValueURL)) {
// Just report back the external image
URI uri = null;
try {
uri = new URI(currentValue);
externalImageList.add(uri.toASCIIString());
} catch (URISyntaxException e) {
ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
}
} else {
try {
File file = new File(currentValueURL.getFile());
File folder = new File(resourceLocator.getFile());
currentValue = RelativePath.getRelativePath(file, folder);
// If the backslashes are not converted to forward slashes
// creating the URI does not work
currentValue = currentValue.replace('\\', '/');
OnLineResourceImpl updatedOnlineResource = new OnLineResourceImpl();
URI uri = new URI(currentValue);
updatedOnlineResource.setLinkage(uri);
externalGraphic.setOnlineResource(updatedOnlineResource);
externalGraphic.setURI(uri.toASCIIString());
externalImageList.add(uri.toASCIIString());
} catch (URISyntaxException e) {
ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
}
}
}
}
}
use of org.geotools.styling.ExternalGraphic in project sldeditor by robward-scisys.
the class ExternalGraphicDetails method getSymbol.
/**
* Gets the symbol.
*
* @return the symbol
*/
public ExternalGraphic getSymbol() {
ExternalGraphic extGraphic = null;
if (externalURL != null) {
String fileExtension = ExternalFilenames.getFileExtension(externalURL.toString());
String imageFormat = ExternalFilenames.getImageFormat(fileExtension);
String uri = "";
try {
uri = externalURL.toURI().toString();
} catch (URISyntaxException e) {
ConsoleManager.getInstance().exception(this, e);
}
extGraphic = getStyleFactory().createExternalGraphic(uri, imageFormat);
}
return extGraphic;
}
use of org.geotools.styling.ExternalGraphic in project sldeditor by robward-scisys.
the class FieldConfigFilename method getValue.
/**
* Gets the value.
*
* @param fieldConfigManager the field config manager
* @param symbolType the symbol type
* @param fillEnabled the fill enabled
* @param strokeEnabled the stroke enabled
* @return the value
*/
@Override
public List<GraphicalSymbol> getValue(GraphicPanelFieldManager fieldConfigManager, Expression symbolType, boolean fillEnabled, boolean strokeEnabled) {
List<GraphicalSymbol> symbols = null;
if (externalGraphicPanel != null) {
ExternalGraphic extGraphic = externalGraphicPanel.getSymbol();
symbols = SelectedSymbol.getInstance().getSymbolList(extGraphic);
}
return symbols;
}
Aggregations