Search in sources :

Example 1 with TextStyle

use of org.polymap.core.style.model.feature.TextStyle in project polymap4-core by Polymap4.

the class DefaultStyle method fillTextStyle.

public static TextStyle fillTextStyle(FeatureStyle fs, FeatureType schema) {
    TextStyle text = fs.members().createElement(TextStyle.defaults);
    text.font.get().family.createValue(ConstantFontFamily.defaults(FontFamily.Arial));
    text.font.get().style.createValue(ConstantFontStyle.defaults());
    text.font.get().weight.createValue(ConstantFontWeight.defaults());
    text.font.get().size.createValue(ConstantNumber.defaults(12.0));
    text.color.createValue(ConstantColor.defaults(new Color(0x40, 0x40, 0x40)));
    if (schema != null) {
        Collection<PropertyDescriptor> schemaDescriptors = schema.getDescriptors();
        GeometryDescriptor geometryDescriptor = schema.getGeometryDescriptor();
        for (PropertyDescriptor descriptor : schemaDescriptors) {
            if (geometryDescriptor == null || !geometryDescriptor.equals(descriptor)) {
                if (String.class.isAssignableFrom(descriptor.getType().getBinding())) {
                    text.property.createValue(AttributeValue.defaults(descriptor.getName().getLocalPart(), null, null));
                    break;
                }
            }
        }
    }
    return text;
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) TextStyle(org.polymap.core.style.model.feature.TextStyle) Color(java.awt.Color) ConstantColor(org.polymap.core.style.model.feature.ConstantColor)

Example 2 with TextStyle

use of org.polymap.core.style.model.feature.TextStyle in project polymap4-core by Polymap4.

the class TextStyleSerializer method serialize.

@Override
public void serialize(TextStyle style, Style result) {
    // default symbolizer
    TextSymbolizer text = sf.createTextSymbolizer();
    text.setFill(sf.getDefaultFill());
    style.halo.opt().ifPresent(halo -> text.setHalo(sf.createHalo(sf.getDefaultFill(), ff.literal(1))));
    style.font.opt().ifPresent(font -> text.setFont(sf.getDefaultFont()));
    FeatureTypeStyle fts = defaultFeatureTypeStyle(result, style, text);
    fts.setName(style.title.opt().orElse("TextStyle"));
    fts.getDescription().setTitle(style.title.opt().orElse("TextStyle"));
    accessor.set(rule -> (TextSymbolizer) rule.symbolizers().get(0));
    serialize(style, fts);
    // font
    style.font.opt().ifPresent(font -> {
        new FontCompositeSerializer(context).accessor.put(rule -> accessor.get().apply(rule).getFont()).serialize(font, fts);
    });
    // halo
    style.halo.opt().ifPresent(halo -> {
        // XXX for what reason ever for halo color an awt.Color does not seem to work
        set(fts, halo.color, (value, sym) -> sym.getHalo().getFill().setColor(ff.literal(SLDSerializer2.toHexString((Color) ((Literal) value).getValue()))));
        set(fts, halo.opacity, (value, sym) -> sym.getHalo().getFill().setOpacity(value));
        set(fts, halo.width, (value, sym) -> sym.getHalo().setRadius(value));
    });
}
Also used : Color(java.awt.Color) Style(org.geotools.styling.Style) TextStyle(org.polymap.core.style.model.feature.TextStyle) Literal(org.opengis.filter.expression.Literal) Context(org.polymap.core.style.serialize.FeatureStyleSerializer.Context) TextSymbolizer(org.geotools.styling.TextSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) TextSymbolizer(org.geotools.styling.TextSymbolizer) Color(java.awt.Color) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Example 3 with TextStyle

use of org.polymap.core.style.model.feature.TextStyle 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;
}
Also used : PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) RasterColorMapStyle(org.polymap.core.style.model.raster.RasterColorMapStyle) Cloner(com.rits.cloning.Cloner) SLD(org.geotools.styling.SLD) FeatureStyleSerializer(org.polymap.core.style.serialize.FeatureStyleSerializer) CommonFactoryFinder(org.geotools.factory.CommonFactoryFinder) Collectors(java.util.stream.Collectors) StyleFactory(org.geotools.styling.StyleFactory) StringUtils(org.apache.commons.lang3.StringUtils) SLDTransformer(org.geotools.styling.SLDTransformer) Style(org.polymap.core.style.model.Style) RasterRGBStyle(org.polymap.core.style.model.raster.RasterRGBStyle) List(java.util.List) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) FilterFactory2(org.opengis.filter.FilterFactory2) Log(org.apache.commons.logging.Log) FeatureStyle(org.polymap.core.style.model.FeatureStyle) LogFactory(org.apache.commons.logging.LogFactory) RasterGrayStyle(org.polymap.core.style.model.raster.RasterGrayStyle) DataPlugin(org.polymap.core.data.DataPlugin) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) FeatureStyleSerializer(org.polymap.core.style.serialize.FeatureStyleSerializer) RasterColorMapStyle(org.polymap.core.style.model.raster.RasterColorMapStyle) RasterGrayStyle(org.polymap.core.style.model.raster.RasterGrayStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) RasterRGBStyle(org.polymap.core.style.model.raster.RasterRGBStyle) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) RasterColorMapStyle(org.polymap.core.style.model.raster.RasterColorMapStyle) Style(org.polymap.core.style.model.Style) RasterRGBStyle(org.polymap.core.style.model.raster.RasterRGBStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) RasterGrayStyle(org.polymap.core.style.model.raster.RasterGrayStyle) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle)

Example 4 with TextStyle

use of org.polymap.core.style.model.feature.TextStyle in project polymap4-core by Polymap4.

the class StyleModelTest method testSimpleText.

@Test
public void testSimpleText() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    TextStyle style = fs.members().createElement(TextStyle.defaults);
    style.color.createValue(ConstantColor.defaults(0, 0, 0));
    style.opacity.createValue(ConstantNumber.defaults(0.0));
    style.font.createValue(Font.defaults);
    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());
    TextSymbolizer text = (TextSymbolizer) rule.symbolizers().get(0);
    // assertEqualsLiteral( 0.5, text.getStroke().getOpacity() );
    // assertEqualsLiteral( 5.0, text.getStroke().getWidth() );
    assertEqualsLiteral(0.0, text.getFill().getOpacity());
}
Also used : TextStyle(org.polymap.core.style.model.feature.TextStyle) TextSymbolizer(org.geotools.styling.TextSymbolizer) Style(org.geotools.styling.Style) ConstantStrokeDashStyle(org.polymap.core.style.model.feature.ConstantStrokeDashStyle) ConstantStrokeJoinStyle(org.polymap.core.style.model.feature.ConstantStrokeJoinStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) TextStyle(org.polymap.core.style.model.feature.TextStyle) ConstantStrokeCapStyle(org.polymap.core.style.model.feature.ConstantStrokeCapStyle) StrokeDashStyle(org.polymap.core.style.model.feature.StrokeDashStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) LineStyle(org.polymap.core.style.model.feature.LineStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Test(org.junit.Test)

Example 5 with TextStyle

use of org.polymap.core.style.model.feature.TextStyle in project polymap4-core by Polymap4.

the class StyleModelTest method testText.

@Ignore
@Test
public void testText() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    TextStyle text = fs.members().createElement(TextStyle.defaults);
    text.property.createValue(ConstantString.defaults("constant"));
    // text.halo.createValue( Halo.defaults );
    text.halo.get().color.createValue(ConstantColor.defaults(1, 2, 3));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    text.property.createValue(AttributeValue.defaults("featureproperty", null, null));
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
}
Also used : TextStyle(org.polymap.core.style.model.feature.TextStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TextStyle (org.polymap.core.style.model.feature.TextStyle)5 FeatureStyle (org.polymap.core.style.model.FeatureStyle)3 Color (java.awt.Color)2 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)2 Style (org.geotools.styling.Style)2 TextSymbolizer (org.geotools.styling.TextSymbolizer)2 Test (org.junit.Test)2 LineStyle (org.polymap.core.style.model.feature.LineStyle)2 PointStyle (org.polymap.core.style.model.feature.PointStyle)2 PolygonStyle (org.polymap.core.style.model.feature.PolygonStyle)2 Cloner (com.rits.cloning.Cloner)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 CommonFactoryFinder (org.geotools.factory.CommonFactoryFinder)1 Rule (org.geotools.styling.Rule)1 SLD (org.geotools.styling.SLD)1 SLDTransformer (org.geotools.styling.SLDTransformer)1