use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class DefaultSymbols method createNewPolygon.
/**
* Creates a new polygon symbol.
*
* @return the styled layer descriptor
*/
public static StyledLayerDescriptor createNewPolygon() {
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);
PolygonSymbolizer polygon = createDefaultPolygonSymbolizer();
rule.symbolizers().add(polygon);
return sld;
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class SymbolizerDetailsPanel method getMinimumVersion.
/**
* Gets the minimum version vendor option present in the SLD.
*
* @param parentObj the parent obj
* @param sldObj the sld obj
* @param vendorOptionsPresentList the vendor options present list
*/
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
Class<?> parentClass = null;
Class<?> classSelected = sldObj.getClass();
if (sldObj instanceof StyledLayerDescriptor) {
// No parent
} else if (sldObj instanceof StyledLayer) {
parentClass = StyledLayerDescriptor.class;
} else if (sldObj instanceof Style) {
parentClass = StyledLayer.class;
} else if (sldObj instanceof FeatureTypeStyle) {
parentClass = Style.class;
} else if (sldObj instanceof Rule) {
parentClass = FeatureTypeStyle.class;
} else if (sldObj instanceof Symbolizer) {
parentClass = Rule.class;
}
internal_getMinimumVersion(parentObj, sldObj, vendorOptionsPresentList, parentClass, classSelected);
if (sldObj instanceof PointSymbolizerImpl) {
PointSymbolizerImpl pointSymbolizer = (PointSymbolizerImpl) sldObj;
parentClass = PointSymbolizerImpl.class;
classSelected = FillImpl.class;
internal_getMinimumVersion(pointSymbolizer, pointSymbolizer.getGraphic(), vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof LineSymbolizerImpl) {
LineSymbolizerImpl lineSymbolizer = (LineSymbolizerImpl) sldObj;
parentClass = LineSymbolizerImpl.class;
classSelected = StrokeImpl.class;
internal_getMinimumVersion(lineSymbolizer, lineSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof PolygonSymbolizerImpl) {
PolygonSymbolizerImpl polygonSymbolizer = (PolygonSymbolizerImpl) sldObj;
parentClass = PolygonSymbolizerImpl.class;
classSelected = FillImpl.class;
internal_getMinimumVersion(polygonSymbolizer, polygonSymbolizer.getFill(), vendorOptionsPresentList, parentClass, classSelected);
classSelected = StrokeImpl.class;
internal_getMinimumVersion(polygonSymbolizer, polygonSymbolizer.getStroke(), vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof TextSymbolizerImpl) {
TextSymbolizerImpl textSymbolizer = (TextSymbolizerImpl) sldObj;
parentClass = Rule.class;
classSelected = TextSymbolizerImpl.class;
internal_getMinimumVersion(parentObj, textSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
} else if (sldObj instanceof RasterSymbolizerImpl) {
RasterSymbolizerImpl rasterSymbolizer = (RasterSymbolizerImpl) sldObj;
parentClass = Rule.class;
classSelected = RasterSymbolizerImpl.class;
internal_getMinimumVersion(parentObj, rasterSymbolizer, vendorOptionsPresentList, parentClass, classSelected);
}
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class RenderSymbol method renderSymbol.
/**
* Render symbol.
*
* @param style the style
* @param ftsToRender the fts to render
* @param ruleToRender the rule to render
* @param options the options
* @return the style
*/
private Style renderSymbol(Style style, FeatureTypeStyle ftsToRender, Rule ruleToRender, RuleRenderOptions options) {
int symbolIndex = SelectedSymbol.getInstance().getSymbolIndex();
RuleRenderVisitor visitor = new RuleRenderVisitor(ftsToRender, ruleToRender, symbolIndex, options);
style.accept(visitor);
Style copy = (Style) visitor.getCopy();
return copy;
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class RenderSymbol method getRenderStyle.
/**
* Gets the render style.
*
* @param selectedSymbol the selected symbol
* @return the render style
*/
public Style getRenderStyle(SelectedSymbol selectedSymbol) {
List<StyledLayer> styledLayerList = selectedSymbol.getSld().layers();
for (StyledLayer styledLayer : styledLayerList) {
List<Style> styleList = null;
if (styledLayer instanceof NamedLayerImpl) {
NamedLayerImpl namedLayer = (NamedLayerImpl) styledLayer;
styleList = namedLayer.styles();
} else if (styledLayer instanceof UserLayerImpl) {
UserLayerImpl userLayer = (UserLayerImpl) styledLayer;
styleList = userLayer.userStyles();
}
if (styleList != null) {
for (Style style : styleList) {
FeatureTypeStyle ftsToRender = selectedSymbol.getFeatureTypeStyle();
Rule ruleToRender = selectedSymbol.getRule();
// Check to see if style contains the rule to render
if (shouldRenderSymbol(style, ftsToRender, ruleToRender)) {
return renderSymbol(style, ftsToRender, ruleToRender, renderOptions);
}
}
}
}
return null;
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class LegendManager method createLegend.
/**
* Creates the legend.
*
* @param sld the sld
* @param heading the heading
* @param filename the filename
* @param separateSymbolizers the separate symbolizers
* @return the map
*/
public Map<String, BufferedImage> createLegend(StyledLayerDescriptor sld, String heading, String filename, boolean separateSymbolizers) {
Map<String, BufferedImage> imageMap = new HashMap<String, BufferedImage>();
//
// Set legend options
//
Map<String, Object> legendOptions = new HashMap<String, Object>();
if (heading != null) {
legendOptions.put("heading", heading);
}
if (filename != null) {
legendOptions.put("filename", filename);
}
if (legendOptionData == null) {
legendOptionData = new LegendOptionData();
}
GetLegendGraphicRequest request = new GetLegendGraphicRequest();
request.setWidth(legendOptionData.getImageWidth());
request.setHeight(legendOptionData.getImageHeight());
request.setTransparent(legendOptionData.isTransparent());
request.setStrict(false);
legendOptions.put("bgColor", ColourUtils.fromColour(legendOptionData.getBackgroundColour()));
legendOptions.put("fontColor", ColourUtils.fromColour(legendOptionData.getLabelFontColour()));
//
// Label Font
//
Font font = legendOptionData.getLabelFont();
legendOptions.put("fontName", font.getFontName());
String styleValue = null;
if ((font.getStyle() & java.awt.Font.BOLD) == java.awt.Font.BOLD) {
styleValue = "bold";
}
if ((font.getStyle() & java.awt.Font.ITALIC) == java.awt.Font.ITALIC) {
styleValue = "italic";
}
if (styleValue != null) {
legendOptions.put("fontStyle", styleValue);
}
legendOptions.put("fontSize", String.valueOf(font.getSize()));
legendOptions.put("dpi", Integer.valueOf(legendOptionData.getDpi()));
legendOptions.put("fontAntiAliasing", getBooleanValueOnOff(legendOptionData.isFontAntiAliasing()));
legendOptions.put("forceLabels", getBooleanValueOnOff(legendOptionData.isShowLabels()));
legendOptions.put("forceTitles", getBooleanValueOnOff(legendOptionData.isShowTitle()));
legendOptions.put("bandInfo", getBooleanValueTrueFalse(legendOptionData.isBandInformation()));
legendOptions.put("border", getBooleanValueTrueFalse(legendOptionData.isBorder()));
legendOptions.put("borderColor", ColourUtils.fromColour(legendOptionData.getBorderColour()));
legendOptions.put("imageSizeFactor", String.valueOf(legendOptionData.getImageSize() / 100.0));
request.setLegendOptions(legendOptions);
if (sld != null) {
Map<String, Style> styleMap = new LinkedHashMap<String, Style>();
StyledLayer selectedStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
Style selectedStyle = SelectedSymbol.getInstance().getStyle();
if (selectedStyle != null) {
createSingleStyleLegend(styleMap, selectedStyledLayer, selectedStyle);
} else {
createMultipleStyleLegend(sld, styleMap, selectedStyledLayer);
}
// Merge symbolizers into 1 image
if (!separateSymbolizers) {
for (String key : styleMap.keySet()) {
Style style = styleMap.get(key);
if (!style.featureTypeStyles().isEmpty()) {
FeatureTypeStyle featureTypeStyle = style.featureTypeStyles().get(0);
if (featureTypeStyle != null) {
if (!featureTypeStyle.rules().isEmpty()) {
LegendRequest legendEntryRequest = request.new LegendRequest();
request.getLegends().add(legendEntryRequest);
legendEntryRequest.setTitle(key);
legendEntryRequest.setStyle(style);
}
}
}
}
BufferedImage legendGraphic = null;
try {
legendGraphic = legendBuilder.buildLegendGraphic(request);
} catch (Exception e) {
// Ignore
}
imageMap.put("", legendGraphic);
} else {
for (String key : styleMap.keySet()) {
request.getLegends().clear();
LegendRequest legendEntryRequest = request.new LegendRequest();
legendEntryRequest.setStyle(styleMap.get(key));
legendEntryRequest.setStyleName(key);
request.getLegends().add(legendEntryRequest);
BufferedImage legendGraphic = null;
try {
legendGraphic = legendBuilder.buildLegendGraphic(request);
} catch (Exception e) {
// Ignore
}
imageMap.put(key, legendGraphic);
}
}
}
return imageMap;
}
Aggregations