Search in sources :

Example 31 with Mark

use of org.geotools.styling.Mark in project sldeditor by robward-scisys.

the class FieldConfigArrowTest method testAccept.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.arrow.FieldConfigArrow#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigArrow field = new FieldConfigArrow(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
    assertFalse(field.accept(null));
    StyleBuilder styleBuilder = new StyleBuilder();
    Mark marker1 = styleBuilder.createMark("star");
    assertFalse(field.accept(marker1));
    Mark marker2 = styleBuilder.createMark("extshape://arrow?hr=1.2&t=0.34&ab=0.56");
    assertTrue(field.accept(marker2));
}
Also used : FieldConfigArrow(com.sldeditor.ui.detail.vendor.geoserver.marker.arrow.FieldConfigArrow) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StyleBuilder(org.geotools.styling.StyleBuilder) Mark(org.geotools.styling.Mark) Test(org.junit.Test)

Example 32 with Mark

use of org.geotools.styling.Mark in project sldeditor by robward-scisys.

the class FieldConfigWindBarbsTest method testAccept.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigWindBarbs field = new FieldConfigWindBarbs(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
    assertFalse(field.accept(null));
    StyleBuilder styleBuilder = new StyleBuilder();
    ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
    assertFalse(field.accept(externalGraphic));
    Mark marker1 = styleBuilder.createMark("triangle");
    assertFalse(field.accept(marker1));
    Mark marker2 = styleBuilder.createMark("windbarbs://default(15)[kts]");
    assertTrue(field.accept(marker2));
}
Also used : ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StyleBuilder(org.geotools.styling.StyleBuilder) Mark(org.geotools.styling.Mark) FieldConfigWindBarbs(com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs) Test(org.junit.Test)

Example 33 with Mark

use of org.geotools.styling.Mark in project polymap4-core by Polymap4.

the class PointStyleSerializer method serialize.

@Override
public void serialize(PointStyle style, Style result) {
    // default symbolizer
    Graphic gr = sf.createGraphic(null, new Mark[] {}, null, null, null, null);
    PointSymbolizer point = sf.createPointSymbolizer(gr, null);
    // basics / init symbolizer
    FeatureTypeStyle fts = defaultFeatureTypeStyle(result, style, point);
    fts.setName(style.title.opt().orElse("PointStyle"));
    fts.getDescription().setTitle(style.title.opt().orElse("PointStyle"));
    accessor.set(rule -> (PointSymbolizer) rule.symbolizers().get(0));
    serialize(style, fts);
    // fill
    style.fill.opt().ifPresent(fill -> {
        // color
        set(fts, style.fill.get().color, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            // Mark
            if (symbol instanceof Mark) {
                ((Mark) symbol).getFill().setColor(value);
            } else // ExternalGraphic
            if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "fill", SLDSerializer2.toHexString(literalValue(value)));
                addParam((ExternalGraphic) symbol, "fill-color", SLDSerializer2.toHexString(literalValue(value)));
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
        // opacity
        set(fts, style.fill.get().opacity, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            // Mark
            if (symbol instanceof Mark) {
                ((Mark) symbol).getFill().setOpacity(value);
            } else // ExternalGraphic
            if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "fill-opacity", literalValue(value).toString());
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
    });
    // stroke
    style.stroke.opt().ifPresent(stroke -> {
        // color
        set(fts, style.stroke.get().color, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            if (symbol instanceof Mark) {
                ((Mark) symbol).getStroke().setColor(value);
            } else if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "stroke-color", SLDSerializer2.toHexString(literalValue(value)));
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
        // opacity
        set(fts, style.stroke.get().opacity, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            if (symbol instanceof Mark) {
                ((Mark) symbol).getStroke().setOpacity(value);
            } else if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "stroke-opacity", literalValue(value).toString());
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
        // width
        set(fts, style.stroke.get().width, (value, sym) -> {
            GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
            if (symbol instanceof Mark) {
                ((Mark) symbol).getStroke().setWidth(value);
            } else if (symbol instanceof ExternalGraphic) {
                addParam((ExternalGraphic) symbol, "stroke-width", literalValue(value).toString() + "px");
            } else {
                throw new RuntimeException("Unhandled symbol type" + symbol);
            }
        });
    });
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.geotools.styling.Mark) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) ExternalGraphic(org.geotools.styling.ExternalGraphic)

Example 34 with Mark

use of org.geotools.styling.Mark in project polymap4-core by Polymap4.

the class DefaultStyles method createPointStyle.

/**
 * Create a Style to draw point features as circles with blue outlines
 * and cyan fill
 */
public static Style createPointStyle(Style style) {
    Graphic gr = sf.createDefaultGraphic();
    Mark mark = sf.getCircleMark();
    mark.setStroke(sf.createStroke(ff.literal(Color.RED), ff.literal(1.5)));
    mark.setFill(sf.createFill(ff.literal(Color.YELLOW)));
    gr.graphicalSymbols().clear();
    gr.graphicalSymbols().add(mark);
    gr.setSize(ff.literal(8));
    /*
         * Setting the geometryPropertyName arg to null signals that we want to draw
         * the default geometry of features
         */
    PointSymbolizer sym = sf.createPointSymbolizer(gr, null);
    Rule rule = sf.createRule();
    rule.symbolizers().add(sym);
    rule.setName("Rule for PointSymbolizer");
    style.featureTypeStyles().get(0).rules().add(rule);
    return style;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) Graphic(org.geotools.styling.Graphic) Mark(org.geotools.styling.Mark) Rule(org.geotools.styling.Rule)

Aggregations

Mark (org.geotools.styling.Mark)34 Test (org.junit.Test)17 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)16 StyleBuilder (org.geotools.styling.StyleBuilder)16 Expression (org.opengis.filter.expression.Expression)16 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)14 GraphicalSymbol (org.opengis.style.GraphicalSymbol)14 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)13 Fill (org.geotools.styling.Fill)11 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)10 ExternalGraphicImpl (org.geotools.styling.ExternalGraphicImpl)10 Stroke (org.geotools.styling.Stroke)10 PointFillDetails (com.sldeditor.ui.detail.PointFillDetails)9 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)8 ArrayList (java.util.ArrayList)8 FieldConfigSlider (com.sldeditor.ui.detail.config.FieldConfigSlider)7 FieldConfigSymbolType (com.sldeditor.ui.detail.config.FieldConfigSymbolType)7 Graphic (org.geotools.styling.Graphic)7 GraphicFill (org.opengis.style.GraphicFill)7 ColourFieldConfig (com.sldeditor.ui.detail.ColourFieldConfig)6