use of org.polymap.core.style.model.feature.LineStyle 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.LineStyle in project polymap4-core by Polymap4.
the class DefaultStyle method fillLineStyle.
public static LineStyle fillLineStyle(FeatureStyle fs) {
LineStyle line = fs.members().createElement(LineStyle.defaults);
line.fill.get().width.createValue(ConstantNumber.defaults(5.0));
line.fill.get().color.createValue(ConstantColor.defaults(randomColor()));
line.fill.get().opacity.createValue(ConstantNumber.defaults(1.0));
return line;
}
use of org.polymap.core.style.model.feature.LineStyle 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;
}
use of org.polymap.core.style.model.feature.LineStyle in project polymap4-core by Polymap4.
the class LineStyleSerializer method serialize.
@Override
public void serialize(LineStyle style, FeatureTypeStyle fts) {
accessor.set(rule -> rule.symbolizers().stream().map(s -> (LineSymbolizer) s).collect(Collectors.toList()));
// inner line: 2nd LineSymbolizer
style.fill.opt().ifPresent(fillStroke -> {
new StrokeCompositeSerializer(context).accessor.put(rule -> accessor.get().apply(rule).get(1).getStroke()).serialize(fillStroke, fts);
});
// stroke line: 1st LineSymbolizer
style.stroke.opt().ifPresent(outerStroke -> {
set(fts, outerStroke.width, (value, syms) -> {
Literal innerWidth = (Literal) syms.get(1).getStroke().getWidth();
syms.get(0).getStroke().setWidth(ff.add(ff.multiply(value, ff.literal(2)), innerWidth));
});
set(fts, outerStroke.color, (value, syms) -> syms.get(0).getStroke().setColor(value));
set(fts, outerStroke.opacity, (value, syms) -> syms.get(0).getStroke().setOpacity(value));
// XXX linestyle
});
}
use of org.polymap.core.style.model.feature.LineStyle in project polymap4-core by Polymap4.
the class StyleModelTest method simpleLine.
@Ignore
@Test
public void simpleLine() throws Exception {
FeatureStyle fs = repo.newFeatureStyle();
// point
LineStyle line = fs.members().createElement(LineStyle.defaults);
line.fill.get().color.createValue(ConstantColor.defaults(0, 0, 100));
line.fill.get().width.createValue(ConstantNumber.defaults(15.0));
line.fill.get().strokeStyle.get().capStyle.createValue(ConstantStrokeCapStyle.defaults());
line.fill.get().strokeStyle.get().dashStyle.createValue(ConstantStrokeDashStyle.defaults(StrokeDashStyle.dashdot));
line.fill.get().strokeStyle.get().joinStyle.createValue(ConstantStrokeJoinStyle.defaults());
line.stroke.get().color.createValue(ConstantColor.defaults(100, 0, 0));
line.stroke.get().width.createValue(ConstantNumber.defaults(2.0));
line.stroke.get().strokeStyle.get().capStyle.createValue(ConstantStrokeCapStyle.defaults());
line.stroke.get().strokeStyle.get().dashStyle.createValue(ConstantStrokeDashStyle.defaults());
line.stroke.get().strokeStyle.get().joinStyle.createValue(ConstantStrokeJoinStyle.defaults());
fs.store();
log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
}
Aggregations