use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.
the class StyleServiceImpl method addStyles.
/**
* @see StyleService#addStyles(Style[])
*/
@Override
public void addStyles(Style... styles) {
boolean somethingHappened = false;
for (Style style : styles) {
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
if (!fts.featureTypeNames().isEmpty() && fts.featureTypeNames().iterator().next().getLocalPart().equals("Feature")) {
this.fbStyle = fts;
somethingHappened = true;
} else {
Collection<TypeDefinition> types = findTypes(fts.featureTypeNames());
if (types != null && !types.isEmpty()) {
for (TypeDefinition type : types) {
if (addStyle(type, fts)) {
somethingHappened = true;
}
}
} else {
/*
* store for later schema update when feature type might
* be present
*/
queuedStyles.add(fts);
}
}
}
}
if (somethingHappened) {
notifyStylesAdded();
}
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class MXDParser method processLabelRenderer.
/**
* Gets the label renderer.
*
* @param sld the sld
* @param labelRenderArrayElement the label render array element
* @param transparency the transparency
*/
private void processLabelRenderer(StyledLayerDescriptor sld, JsonArray labelRenderArrayElement, int transparency) {
if (sld != null) {
if (labelRenderArrayElement != null) {
List<StyledLayer> styledLayers = sld.layers();
if (!styledLayers.isEmpty()) {
if (styledLayers.get(0) instanceof NamedLayer) {
NamedLayer namedLayer = (NamedLayer) styledLayers.get(0);
List<Style> styleList = namedLayer.styles();
if (!styleList.isEmpty()) {
List<FeatureTypeStyle> ftsList = styleList.get(0).featureTypeStyles();
if (!ftsList.isEmpty()) {
List<Rule> ruleList = ftsList.get(0).rules();
List<Rule> newLabelRuleList = new ArrayList<Rule>();
for (int index = 0; index < labelRenderArrayElement.size(); index++) {
JsonElement labelRenderElement = labelRenderArrayElement.get(index);
JsonObject renderer = labelRenderElement.getAsJsonObject();
boolean found = false;
for (String labelRendererType : labelRendererMap.keySet()) {
JsonElement obj = renderer.get(labelRendererType);
if (obj != null) {
EsriLabelRendererInterface esriLabelRenderer = labelRendererMap.get(labelRendererType);
if (esriLabelRenderer != null) {
for (Rule rule : ruleList) {
esriLabelRenderer.convert(newLabelRuleList, rule, obj, transparency);
}
}
found = true;
break;
}
}
if (!found) {
ConsoleManager.getInstance().error(this, "Unsupported label renderer : " + SymbolUtils.extractName(labelRenderElement));
}
}
ruleList.addAll(newLabelRuleList);
}
}
}
}
}
}
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class SimpleRenderer method convert.
/* (non-Javadoc)
* @see com.sldeditor.convert.esri.renderer.EsriRendererInterface#convert(com.google.gson.JsonObject, java.lang.String, double, double, int)
*/
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
String label = json.get(CommonRendererKeys.LABEL).getAsString();
namedLayer.setName(label);
sld.addStyledLayer(namedLayer);
Style style = styleFactory.createStyle();
namedLayer.addStyle(style);
List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
// style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
ftsList.add(fts);
Rule rule = styleFactory.createRule();
if (minScale > 0.0) {
rule.setMinScaleDenominator(minScale);
}
if (maxScale > 0.0) {
rule.setMaxScaleDenominator(maxScale);
}
JsonElement jsonElement = json.get(CommonRendererKeys.SYMBOL);
rule.setName(label);
SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonElement);
fts.rules().add(rule);
return sld;
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class UniqueValueRenderer method convert.
/* (non-Javadoc)
* @see com.sldeditor.convert.esri.renderer.EsriRendererInterface#convert(com.google.gson.JsonObject, java.lang.String, double, double, int)
*/
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
boolean useDefaultSymbol = false;
JsonElement useDefaultSymbolElement = json.get(UniqueValueRendererKeys.USE_DEFAULTSYMBOL);
if (useDefaultSymbolElement != null) {
useDefaultSymbol = useDefaultSymbolElement.getAsBoolean();
}
JsonElement jsonElement = json.get(CommonRendererKeys.LABEL);
if (jsonElement != null) {
namedLayer.setName(jsonElement.getAsString());
}
sld.addStyledLayer(namedLayer);
Style style = styleFactory.createStyle();
namedLayer.addStyle(style);
List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
// style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
ftsList.add(fts);
JsonElement element = json.get(UniqueValueRendererKeys.VALUES);
if (element != null) {
JsonArray valueList = element.getAsJsonArray();
for (int index = 0; index < valueList.size(); index++) {
JsonElement valueElement = valueList.get(index);
if (valueElement != null) {
Rule rule = styleFactory.createRule();
JsonObject valueObj = valueElement.getAsJsonObject();
String value = getString(valueObj, UniqueValueRendererKeys.VALUES_VALUE);
String label = getString(valueObj, UniqueValueRendererKeys.VALUES_LABEL);
rule.setName(label);
createFilter(rule, json.get(UniqueValueRendererKeys.FIELDS), json.get(UniqueValueRendererKeys.FIELD_DELIMETER), value);
// Heading /description
String heading = getString(valueObj, UniqueValueRendererKeys.VALUES_HEADING);
@SuppressWarnings("unused") String description = getString(valueObj, UniqueValueRendererKeys.VALUES_DESCRIPTION);
if ((heading != null) && !heading.isEmpty() || (label != null) && !label.isEmpty()) {
if (label == null) {
label = "";
}
InternationalString titleString = Text.text(label);
if (heading == null) {
heading = "";
}
InternationalString descriptionString = Text.text(heading);
Description descriptionObj = styleFactory.description(titleString, descriptionString);
rule.setDescription(descriptionObj);
}
if (minScale > 0.0) {
rule.setMinScaleDenominator(minScale);
}
if (maxScale > 0.0) {
rule.setMaxScaleDenominator(maxScale);
}
JsonElement jsonSymbolElement = valueObj.get(UniqueValueRendererKeys.VALUES_SYMBOL);
SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonSymbolElement);
if (useDefaultSymbol && value == null) {
rule.setIsElseFilter(true);
}
fts.rules().add(rule);
}
}
}
return sld;
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class StrokeDetailsTest method testStrokeDetailsPolygon.
/**
* Test method for
* {@link com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
*/
@Test
public void testStrokeDetailsPolygon() {
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);
PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
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);
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);
}
Aggregations