use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.
the class StyleHelper method createPolygonStyle.
/**
* Create a default polygon style.
*
* @param color the polygon color
* @param width the line width
* @return a Style for Polygon objects
*/
private static FeatureTypeStyle createPolygonStyle(Color color, double width) {
PolygonSymbolizer symbolizer = createPolygonSymbolizer(color, width);
Rule rule = styleFactory.createRule();
rule.symbolizers().add(symbolizer);
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
fts.rules().add(rule);
return fts;
}
use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.
the class StyleHelper method getDefaultStyle.
/**
* Returns a default style for the given type.
*
* @param typeDef the type definition
* @param dataSet the data set (if known)
* @return the style
*/
public static FeatureTypeStyle getDefaultStyle(TypeDefinition typeDef, @Nullable DataSet dataSet) {
// GeometrySchemaService gss = (GeometrySchemaService) PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
// List<QName> geomPath = gss.getDefaultGeometry(typeDef);
// TODO determine default style from default geometry?
Color defColor;
if (dataSet != null) {
defColor = StylePreferences.getDefaultColor(dataSet);
} else {
defColor = Color.DARK_GRAY;
}
int defWidth = StylePreferences.getDefaultWidth();
FeatureTypeStyle result;
// XXX for now create a polygon style in any case, as it contains fill
// and stroke
// if (type != null) {
// if (type.isAssignableFrom(Polygon.class)
// || type.isAssignableFrom(MultiPolygon.class)) {
result = createPolygonStyle(defColor, defWidth);
// } else if (type.isAssignableFrom(LineString.class)
// || type.isAssignableFrom(MultiLineString.class)) {
// result = createLineStyle(defColor, defWidth);
// } else {
// result = createPointStyle(defColor, defWidth);
// }
// }
// else {
// result = createPointStyle(defColor, defWidth);
// }
// XXX StyleBuilder does not support feature type names with namespace
// QName name = getFeatureTypeName(typeDef);
// result.featureTypeNames().add(new NameImpl(name.getNamespaceURI(), name.getLocalPart()));
result.featureTypeNames().add(new NameImpl(getFeatureTypeName(typeDef)));
return result;
}
use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.
the class StyleServiceImpl method getStyle.
/**
* This implementation will build a simple style if none is defined
* previously.
*
* @see StyleService#getStyle(TypeDefinition, DataSet)
*/
@Override
public Style getStyle(TypeDefinition type, @Nullable DataSet dataSet) {
FeatureTypeStyle fts = styles.get(type);
Style style = styleFactory.createStyle();
if (fts != null) {
style.featureTypeStyles().add(fts);
} else {
if (fbStyle != null) {
style.featureTypeStyles().add(fbStyle);
} else {
style.featureTypeStyles().add(StyleHelper.getDefaultStyle(type, dataSet));
}
}
return style;
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class SLDUtilsTest method testFindRule.
@Test
public void testFindRule() {
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
sld.layers().add(DefaultSymbols.createNewNamedLayer());
sld.layers().add(namedLayer);
String expectedNamedLayer = "namedLayer";
namedLayer.setName(expectedNamedLayer);
Style style = DefaultSymbols.createNewStyle();
String expectedStyleLayer = "style";
style.setName(expectedStyleLayer);
namedLayer.addStyle(DefaultSymbols.createNewStyle());
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedFeatureTypeStyleLayer = "feature type style";
fts.setName(expectedFeatureTypeStyleLayer);
style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
fts.rules().add(DefaultSymbols.createNewRule());
fts.rules().add(rule);
String expectedRule = "rule";
rule.setName(expectedRule);
String expectedSymbolizer = "text symbolizer";
TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
symbolizer.setName(expectedSymbolizer);
rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
rule.symbolizers().add(symbolizer);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
symbolizer.setFont(font);
DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
duplicate.visit(sld);
StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
Rule actualRule = SLDUtils.findRule(sld, rule, sldCopy);
assertNotNull(actualRule);
assertEquals(rule.getName(), actualRule.getName());
actualRule = SLDUtils.findRule(sld, null, sldCopy);
assertNull(actualRule);
actualRule = SLDUtils.findRule(sld, rule, null);
assertNull(actualRule);
}
use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.
the class SLDUtilsTest method testFindSymbolizer.
@Test
public void testFindSymbolizer() {
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
sld.layers().add(DefaultSymbols.createNewNamedLayer());
sld.layers().add(namedLayer);
String expectedNamedLayer = "namedLayer";
namedLayer.setName(expectedNamedLayer);
Style style = DefaultSymbols.createNewStyle();
String expectedStyleLayer = "style";
style.setName(expectedStyleLayer);
namedLayer.addStyle(DefaultSymbols.createNewStyle());
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedFeatureTypeStyleLayer = "feature type style";
fts.setName(expectedFeatureTypeStyleLayer);
style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
fts.rules().add(DefaultSymbols.createNewRule());
fts.rules().add(rule);
String expectedRule = "rule";
rule.setName(expectedRule);
String expectedSymbolizer = "text symbolizer";
TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
symbolizer.setName(expectedSymbolizer);
rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
rule.symbolizers().add(symbolizer);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
symbolizer.setFont(font);
DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
duplicate.visit(sld);
StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
Symbolizer actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, sldCopy);
assertNotNull(actualSymbolizer);
assertEquals(symbolizer.getLabel().toString(), ((TextSymbolizer) actualSymbolizer).getLabel().toString());
actualSymbolizer = SLDUtils.findSymbolizer(sld, null, sldCopy);
assertNull(actualSymbolizer);
actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, null);
assertNull(actualSymbolizer);
}
Aggregations