Search in sources :

Example 11 with FeatureStyle

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

the class FilterTest method visiblePoint.

@Test
public void visiblePoint() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    assertTrue(point.visibleIf.get() instanceof ConstantFilter);
    point.visibleIf.createValue(initializeFilter(ff.equals(ff.property("prop"), ff.literal("literal"))));
    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);
    assertTrue(rule.getFilter() instanceof PropertyIsEqualTo);
    PropertyIsEqualTo filter = (PropertyIsEqualTo) rule.getFilter();
    assertTrue(filter.getExpression1() instanceof PropertyName);
    assertEquals("prop", ((PropertyName) filter.getExpression1()).getPropertyName());
    assertTrue(filter.getExpression2() instanceof Literal);
    assertEquals("literal", ((Literal) filter.getExpression2()).getValue());
    PointSymbolizer sym = (PointSymbolizer) rule.getSymbolizers()[0];
    assertEquals(SLDSerializer2.ff.literal(23.0), sym.getGraphic().getSize());
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) PointSymbolizer(org.geotools.styling.PointSymbolizer) PointStyle(org.polymap.core.style.model.feature.PointStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) Literal(org.opengis.filter.expression.Literal) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) FeatureStyle(org.polymap.core.style.model.FeatureStyle) PointStyle(org.polymap.core.style.model.feature.PointStyle) Rule(org.geotools.styling.Rule) Test(org.junit.Test)

Example 12 with FeatureStyle

use of org.polymap.core.style.model.FeatureStyle 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 13 with FeatureStyle

use of org.polymap.core.style.model.FeatureStyle 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)

Example 14 with FeatureStyle

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

the class StyleModelTest method propertyMappedColors.

@Ignore
@Test
public void propertyMappedColors() {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PointStyle point = fs.members().createElement(PointStyle.defaults);
    point.diameter.createValue(ConstantNumber.defaults(5.0));
    point.fill.get().color.createValue(new ValueInitializer<FilterMappedColors>() {

        @Override
        public FilterMappedColors initialize(FilterMappedColors proto) throws Exception {
            proto.add(ff.equals(ff.property("foo"), ff.literal("big")), new Color(255, 0, 0));
            proto.add(ff.equals(ff.property("foo"), ff.literal("bigger")), new Color(0, 0, 255));
            proto.add(ff.and(ff.notEqual(ff.property("foo"), ff.literal("big")), ff.notEqual(ff.property("foo"), ff.literal("bigger"))), new Color(0, 0, 255));
            return proto;
        }
    });
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
    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());
}
Also used : PointStyle(org.polymap.core.style.model.feature.PointStyle) Color(java.awt.Color) ConstantColor(org.polymap.core.style.model.feature.ConstantColor) 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) FilterMappedColors(org.polymap.core.style.model.feature.FilterMappedColors) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with FeatureStyle

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

the class StyleModelTest method testPolygon.

@Ignore
@Test
public void testPolygon() throws Exception {
    FeatureStyle fs = repo.newFeatureStyle();
    // point
    PolygonStyle polygon = fs.members().createElement(PolygonStyle.defaults);
    assertTrue(polygon.visibleIf.get() instanceof ConstantFilter);
    polygon.fill.get().color.createValue(ConstantColor.defaults(1, 2, 3));
    polygon.stroke.get().color.createValue(ConstantColor.defaults(100, 100, 100));
    polygon.stroke.get().width.createValue(ConstantNumber.defaults(5.0));
    polygon.stroke.get().opacity.createValue(FilterMappedPrimitives.defaults()).add(ff.equals(ff.literal(1), ff.literal(1)), 0.1).add(ff.equals(ff.literal(2), ff.literal(2)), 0.2);
    polygon.stroke.get().strokeStyle.get().capStyle.createValue(ConstantStrokeCapStyle.defaults());
    polygon.stroke.get().strokeStyle.get().dashStyle.createValue(ConstantStrokeDashStyle.defaults());
    polygon.stroke.get().strokeStyle.get().joinStyle.createValue(ConstantStrokeJoinStyle.defaults());
    fs.store();
    log.info("SLD: " + repo.serializedFeatureStyle(fs.id(), String.class));
}
Also used : ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) PolygonStyle(org.polymap.core.style.model.feature.PolygonStyle) FeatureStyle(org.polymap.core.style.model.FeatureStyle) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

FeatureStyle (org.polymap.core.style.model.FeatureStyle)18 Test (org.junit.Test)17 PointStyle (org.polymap.core.style.model.feature.PointStyle)14 LineStyle (org.polymap.core.style.model.feature.LineStyle)13 PolygonStyle (org.polymap.core.style.model.feature.PolygonStyle)13 TextStyle (org.polymap.core.style.model.feature.TextStyle)13 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)11 Style (org.geotools.styling.Style)11 ConstantStrokeCapStyle (org.polymap.core.style.model.feature.ConstantStrokeCapStyle)11 ConstantStrokeDashStyle (org.polymap.core.style.model.feature.ConstantStrokeDashStyle)11 ConstantStrokeJoinStyle (org.polymap.core.style.model.feature.ConstantStrokeJoinStyle)11 StrokeDashStyle (org.polymap.core.style.model.feature.StrokeDashStyle)11 Ignore (org.junit.Ignore)8 PointSymbolizer (org.geotools.styling.PointSymbolizer)7 ConstantFilter (org.polymap.core.style.model.feature.ConstantFilter)7 Rule (org.geotools.styling.Rule)6 FilterMappedPrimitives (org.polymap.core.style.model.feature.FilterMappedPrimitives)2 Cloner (com.rits.cloning.Cloner)1 Color (java.awt.Color)1 List (java.util.List)1