use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class SLDEditorBufferedImageLegendGraphicBuilder method calcSymbolScale.
/**
* Calculates a global rescaling factor for all the symbols to be drawn in the given rules. This
* is to be sure all symbols are drawn inside the given w x h box.
*
* @param width horizontal constraint
* @param height vertical constraint
* @param featureType FeatureType to be used for size extraction in expressions (used to create
* a sample if feature is null)
* @param feature Feature to be used for size extraction in expressions (if null a sample
* Feature will be created from featureType)
* @param rules set of rules to scan for symbols
* @param minimumSymbolSize lower constraint for the symbols size
*/
private double calcSymbolScale(int width, int height, FeatureType featureType, Feature feature, final Rule[] rules, double minimumSymbolsSize) {
// check for max and min size in rendered symbols
double minSize = Double.MAX_VALUE;
double maxSize = 0.0;
final int ruleCount = rules.length;
for (int i = 0; i < ruleCount; i++) {
Feature sample = getSampleFeatureForRule(featureType, feature, rules[i]);
final Symbolizer[] symbolizers = rules[i].getSymbolizers();
for (int sIdx = 0; sIdx < symbolizers.length; sIdx++) {
final Symbolizer symbolizer = symbolizers[sIdx];
if (symbolizer instanceof PointSymbolizer) {
double size = getGraphicSize(sample, ((PointSymbolizer) symbolizer).getGraphic(), Math.min(width, height));
if (size < minSize) {
minSize = size;
}
if (size > maxSize) {
maxSize = size;
}
}
}
}
if (minSize != maxSize) {
return (maxSize - minSize + 1) / (Math.min(width, height) - minimumSymbolsSize);
} else {
return maxSize / (Math.min(width, height) - minimumSymbolsSize);
}
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class StrokeTreeItem method itemSelected.
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.tree.SLDTreeItemInterface#itemSelected(javax.swing.tree.DefaultMutableTreeNode, java.lang.Object)
*/
@Override
public void itemSelected(DefaultMutableTreeNode node, Object userObject) {
if (node != null) {
SelectedSymbol selectedSymbol = SelectedSymbol.getInstance();
// Individual symbol selected
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
if ((parent != null) && (parent.getUserObject() instanceof Symbolizer)) {
Symbolizer symbolizer = (Symbolizer) parent.getUserObject();
selectedSymbol.setSymbolizer(symbolizer);
}
}
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class SymbolizerTreeItem method itemSelected.
/**
* Item selected.
*
* @param node the node
* @param userObject the user object
*/
@Override
public void itemSelected(DefaultMutableTreeNode node, Object userObject) {
SelectedSymbol selectedSymbol = SelectedSymbol.getInstance();
// Individual symbol selected
Symbolizer symbolizer = (Symbolizer) userObject;
if (node != null) {
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
if (parent != null) {
selectedSymbol.setSymbolizer(symbolizer);
}
}
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class SelectedSymbol method updateInternalData.
/**
* Update internal data based on the supplied mask.
*
* @param maskValue the mask value
*/
private void updateInternalData(SelectedSymbolMask.SymbolMaskEnum maskValue) {
SymbolData localSymbolData = new SymbolData();
SelectedSymbolMask mask = new SelectedSymbolMask(maskValue);
if (sld == null) {
return;
}
List<StyledLayer> styledLayers = sld.layers();
if (!styledLayers.isEmpty()) {
localSymbolData.initialiseSelectedStyledLayerIndex();
for (StyledLayer styledLayer : styledLayers) {
localSymbolData.setStyledLayer(styledLayer);
if (styledLayer == symbolData.getStyledLayer()) {
this.symbolData.update(localSymbolData);
return;
}
List<Style> styleList = null;
if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_STYLED_LAYER)) {
styleList = SLDUtils.getStylesList(styledLayer);
}
if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_STYLE) && (styleList != null) && !styleList.isEmpty()) {
localSymbolData.initialiseSelectedStyleIndex();
for (Style style : styleList) {
localSymbolData.setStyle(style);
if (style == symbolData.getStyle()) {
this.symbolData.update(localSymbolData);
return;
}
if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_FEATURE_TYPE_STYLE)) {
localSymbolData.initialiseSelectedFTSIndex();
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
localSymbolData.setFeatureTypeStyle(fts);
if (fts == symbolData.getFeatureTypeStyle()) {
this.symbolData.update(localSymbolData);
return;
}
if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_RULE)) {
localSymbolData.initialiseSelectedRuleIndex();
for (Rule rule : fts.rules()) {
localSymbolData.setRule(rule);
if (rule == symbolData.getRule()) {
this.symbolData.update(localSymbolData);
return;
}
if (mask.shouldContinue(SelectedSymbolMask.SymbolMaskEnum.E_SYMBOLIZER)) {
localSymbolData.initialiseSelectedSymbolizerIndex();
for (Symbolizer symbol : rule.symbolizers()) {
localSymbolData.setSymbolizer(symbol);
if (symbol == this.symbolData.getSymbolizer()) {
this.symbolData.update(localSymbolData);
return;
} else {
localSymbolData.incrementSelectedSymbolizerIndex();
}
}
}
localSymbolData.incrementSelectedRuleIndex();
}
}
localSymbolData.incrementSelectedFTSIndex();
}
}
localSymbolData.incrementSelectedStyleIndex();
}
}
localSymbolData.incrementSelectedStyledLayerIndex();
}
}
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class NewPolygonSLDTest method testNewPolygonSLD.
/**
* Test new polygon sld.
*/
@Test
public void testNewPolygonSLD() {
NewPolygonSLD newData = new NewPolygonSLD();
StyledLayerDescriptor sld = newData.create();
assertTrue(sld.layers().size() == 1);
StyledLayer styledLayer = sld.layers().get(0);
NamedLayer namedLayer = (NamedLayer) styledLayer;
Symbolizer symbolizer = namedLayer.styles().get(0).featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
assertTrue(symbolizer instanceof PolygonSymbolizer);
}
Aggregations