use of org.polymap.core.style.model.FeatureStyle in project polymap4-core by Polymap4.
the class StyleModelTest method testDefaultPoint.
@Test
public void testDefaultPoint() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
fs.members().createElement(PointStyle.defaults);
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
}
use of org.polymap.core.style.model.FeatureStyle in project polymap4-core by Polymap4.
the class StyleModelTest method testFilterMappedNumbers.
@Test
public void testFilterMappedNumbers() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
PointStyle point = fs.members().createElement(PointStyle.defaults);
point.rotation.createValue(FilterMappedPrimitives.defaults()).add(ff.equals(ff.literal(1), ff.literal(1)), 45d).add(ff.equals(ff.literal(2), ff.literal(2)), 90d);
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(2, fts.rules().size());
assertEqualsLiteral(45.0, ((PointSymbolizer) fts.rules().get(0).symbolizers().get(0)).getGraphic().getRotation());
assertEqualsLiteral(90.0, ((PointSymbolizer) fts.rules().get(1).symbolizers().get(0)).getGraphic().getRotation());
}
use of org.polymap.core.style.model.FeatureStyle 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.FeatureStyle in project polymap4-core by Polymap4.
the class StyleModelTest method propertyMappedNumbers.
@Ignore
@Test
public void propertyMappedNumbers() {
FeatureStyle fs = repo.newFeatureStyle();
// point
PointStyle point = fs.members().createElement(PointStyle.defaults);
point.diameter.createValue(new ValueInitializer<FilterMappedPrimitives<Double>>() {
@Override
public FilterMappedPrimitives<Double> initialize(FilterMappedPrimitives<Double> proto) throws Exception {
proto.add(ff.equals(ff.property("foo"), ff.literal("big")), new Double(5));
proto.add(ff.equals(ff.property("foo"), ff.literal("bigger")), new Double(15));
proto.add(ff.and(ff.notEqual(ff.property("foo"), ff.literal("big")), ff.notEqual(ff.property("foo"), ff.literal("bigger"))), new Double(23));
return proto;
}
});
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class, OutputFormat.GEOSERVER));
Style style = repo.serializedFeatureStyle(fs.id(), Style.class, OutputFormat.GEOSERVER).get();
List<FeatureTypeStyle> featureTypeStyles = style.featureTypeStyles();
assertEquals(1, featureTypeStyles.size());
assertEquals(Filter.INCLUDE, featureTypeStyles.get(0).rules().get(0).getFilter());
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class, OutputFormat.OGC));
style = repo.serializedFeatureStyle(fs.id(), Style.class, OutputFormat.OGC).get();
featureTypeStyles = style.featureTypeStyles();
assertEquals(1, featureTypeStyles.size());
assertEquals("[ foo = big ]", featureTypeStyles.get(0).rules().get(0).getFilter().toString());
assertEquals("[ foo = bigger ]", featureTypeStyles.get(0).rules().get(1).getFilter().toString());
assertEquals("[[ foo != big ] AND [ foo != bigger ]]", featureTypeStyles.get(0).rules().get(2).getFilter().toString());
}
use of org.polymap.core.style.model.FeatureStyle in project polymap4-core by Polymap4.
the class SLDSerializer2 method serialize.
@Override
public org.geotools.styling.Style serialize(Context context) {
FeatureStyle featureStyle = context.featureStyle.get();
List<Style> sorted = featureStyle.members().stream().sorted((s1, s2) -> s1.zPriority.get().compareTo(s2.zPriority.get())).collect(Collectors.toList());
org.geotools.styling.Style result = sf.createStyle();
for (Style style : sorted) {
if (style.active.get()) {
StyleSerializer serializer = null;
if (style instanceof PointStyle) {
serializer = new PointStyleSerializer(context);
} else if (style instanceof PolygonStyle) {
serializer = new PolygonStyleSerializer(context);
} else if (style instanceof TextStyle) {
serializer = new TextStyleSerializer(context);
} else if (style instanceof LineStyle) {
serializer = new LineStyleSerializer(context);
} else if (style instanceof RasterGrayStyle) {
serializer = new RasterSerializer.GraySerializer(context);
} else if (style instanceof RasterRGBStyle) {
serializer = new RasterSerializer.RGBSerializer(context);
} else if (style instanceof RasterColorMapStyle) {
serializer = new RasterSerializer.ColorMapSerializer(context);
} else {
throw new RuntimeException("Unhandled Style type: " + style.getClass().getName());
}
serializer.serialize(style, result);
}
}
return result;
}
Aggregations