use of org.polymap.core.style.model.feature.ConstantFilter in project polymap4-core by Polymap4.
the class FilterTest method pointWithScale.
@Test
public void pointWithScale() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
// point
PointStyle point = fs.members().createElement(PointStyle.defaults);
assertTrue(point.visibleIf.get() instanceof ConstantFilter);
point.visibleIf.createValue(ScaleRangeFilter.defaults(10000, 500000));
point.diameter.createValue(ConstantNumber.defaults(23.0));
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
org.geotools.styling.Style style = repo.serializedFeatureStyle(fs.id(), org.geotools.styling.Style.class).get();
Rule rule = style.featureTypeStyles().get(0).rules().get(0);
assertEquals(10000.0d, rule.getMinScaleDenominator(), 0);
assertEquals(500000.0d, rule.getMaxScaleDenominator(), 0);
PointSymbolizer sym = (PointSymbolizer) rule.getSymbolizers()[0];
assertEquals(SLDSerializer2.ff.literal(23.0), sym.getGraphic().getSize());
}
use of org.polymap.core.style.model.feature.ConstantFilter in project polymap4-core by Polymap4.
the class StyleModelTest method testSimpleLine.
@Test
public void testSimpleLine() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
LineStyle style = fs.members().createElement(LineStyle.defaults);
assertTrue(style.visibleIf.get() instanceof ConstantFilter);
style.fill.get().color.createValue(ConstantColor.defaults(0, 0, 0));
style.fill.get().width.createValue(ConstantNumber.defaults(5.0));
style.fill.get().opacity.createValue(ConstantNumber.defaults(0.0));
style.stroke.get().color.createValue(ConstantColor.defaults(100, 100, 100));
style.stroke.get().width.createValue(ConstantNumber.defaults(5.0));
style.stroke.get().opacity.createValue(ConstantNumber.defaults(0.5));
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
Style result = repo.serializedFeatureStyle(fs.id(), Style.class).get();
assertEquals(1, result.featureTypeStyles().size());
FeatureTypeStyle fts = result.featureTypeStyles().get(0);
assertEquals(1, fts.rules().size());
Rule rule = fts.rules().get(0);
assertEquals(0, rule.getMinScaleDenominator(), 0);
assertEquals(Double.POSITIVE_INFINITY, rule.getMaxScaleDenominator(), 0);
assertEquals(2, rule.symbolizers().size());
assertNull(rule.getFilter());
LineSymbolizer strokeLine = (LineSymbolizer) rule.symbolizers().get(0);
assertEqualsLiteral(0.5, strokeLine.getStroke().getOpacity());
assertEqualsLiteral(15.0, strokeLine.getStroke().getWidth());
LineSymbolizer fillLine = (LineSymbolizer) rule.symbolizers().get(1);
assertEqualsLiteral(0.0, fillLine.getStroke().getOpacity());
assertEqualsLiteral(5.0, fillLine.getStroke().getWidth());
}
use of org.polymap.core.style.model.feature.ConstantFilter in project polymap4-core by Polymap4.
the class StyleModelTest method testSimplePoint.
@Test
public void testSimplePoint() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
PointStyle style = fs.members().createElement(PointStyle.defaults);
assertTrue(style.visibleIf.get() instanceof ConstantFilter);
style.diameter.createValue(ConstantNumber.defaults(100.0));
style.rotation.createValue(ConstantNumber.defaults(45.0));
style.fill.get().color.createValue(ConstantColor.defaults(0, 0, 0));
style.fill.get().opacity.createValue(ConstantNumber.defaults(0.0));
style.stroke.get().color.createValue(ConstantColor.defaults(100, 100, 100));
style.stroke.get().width.createValue(ConstantNumber.defaults(5.0));
style.stroke.get().opacity.createValue(ConstantNumber.defaults(0.5));
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
Style result = repo.serializedFeatureStyle(fs.id(), Style.class).get();
assertEquals(1, result.featureTypeStyles().size());
FeatureTypeStyle fts = result.featureTypeStyles().get(0);
assertEquals(1, fts.rules().size());
Rule rule = fts.rules().get(0);
assertEquals(0, rule.getMinScaleDenominator(), 0);
assertEquals(Double.POSITIVE_INFINITY, rule.getMaxScaleDenominator(), 0);
assertEquals(1, rule.symbolizers().size());
assertNull(rule.getFilter());
PointSymbolizer sym = (PointSymbolizer) rule.symbolizers().get(0);
assertEqualsLiteral(100.0, sym.getGraphic().getSize());
assertEqualsLiteral(45.0, sym.getGraphic().getRotation());
assertEquals(1, sym.getGraphic().graphicalSymbols().size());
GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
Mark mark = (Mark) symbol;
assertEqualsLiteral(0.0, mark.getFill().getOpacity());
assertEqualsLiteral(0.5, mark.getStroke().getOpacity());
assertEqualsLiteral(5.0, mark.getStroke().getWidth());
}
use of org.polymap.core.style.model.feature.ConstantFilter in project polymap4-core by Polymap4.
the class StyleModelTest method testFeatureBasedPoint.
@Ignore
@Test
public void testFeatureBasedPoint() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
// point
PointStyle point = fs.members().createElement(PointStyle.defaults);
assertTrue(point.visibleIf.get() instanceof ConstantFilter);
point.diameter.createValue(ConstantNumber.defaults(23.0));
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
Style style = repo.serializedFeatureStyle(fs.id(), Style.class).get();
PointSymbolizer sym = (PointSymbolizer) style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
assertEquals(ff.literal(23.0), sym.getGraphic().getSize());
point.diameter.createValue(AttributeValue.defaults("foo", null, null));
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
style = repo.serializedFeatureStyle(fs.id(), Style.class).get();
sym = (PointSymbolizer) style.featureTypeStyles().get(0).rules().get(0).getSymbolizers()[0];
assertEquals(ff.property("foo"), sym.getGraphic().getSize());
point.diameter.createValue(ConstantNumber.defaults(42.0));
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
style = repo.serializedFeatureStyle(fs.id(), Style.class).get();
sym = (PointSymbolizer) style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
assertEquals(ff.literal(42.0), sym.getGraphic().getSize());
}
use of org.polymap.core.style.model.feature.ConstantFilter in project polymap4-core by Polymap4.
the class StyleCompositeSerializer method defaultFeatureTypeStyle.
protected FeatureTypeStyle defaultFeatureTypeStyle(org.geotools.styling.Style result, Style style, Symbolizer... symbolizers) {
Rule rule = sf.createRule();
// handle visibleIf
FilterStyleProperty visibleIf = (FilterStyleProperty) style.visibleIf.get();
if (visibleIf instanceof ScaleRangeFilter) {
rule.setMinScaleDenominator(((ScaleRangeFilter) visibleIf).minScale.get());
rule.setMaxScaleDenominator(((ScaleRangeFilter) visibleIf).maxScale.get());
} else if (visibleIf instanceof ConstantFilter) {
Filter filter = ((ConstantFilter) visibleIf).filter();
if (!filter.equals(Filter.INCLUDE)) {
rule.setFilter(filter);
}
} else {
throw new RuntimeException("Unhandled Style.visibleIf type: " + visibleIf.getClass());
}
for (Symbolizer s : symbolizers) {
rule.symbolizers().add(s);
}
;
FeatureTypeStyle fts = sf.createFeatureTypeStyle();
fts.rules().add(rule);
result.featureTypeStyles().add(fts);
return fts;
}
Aggregations