Search in sources :

Example 11 with Mark

use of org.opengis.style.Mark in project geotoolkit by Geomatys.

the class Styles method markPoint.

public static MutableStyle markPoint() {
    // general informations
    final String name = "mySymbol";
    final Description desc = DEFAULT_DESCRIPTION;
    // use the default geometry of the feature
    final String geometry = null;
    final Unit unit = Units.POINT;
    // the visual element
    final Expression size = FF.literal(12);
    final Expression opacity = LITERAL_ONE_FLOAT;
    final Expression rotation = LITERAL_ONE_FLOAT;
    final AnchorPoint anchor = DEFAULT_ANCHOR_POINT;
    final Displacement disp = DEFAULT_DISPLACEMENT;
    final List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
    final Stroke stroke = SF.stroke(Color.BLACK, 2);
    final Fill fill = SF.fill(Color.RED);
    final Mark mark = SF.mark(MARK_CIRCLE, fill, stroke);
    symbols.add(mark);
    final Graphic graphic = SF.graphic(symbols, opacity, size, rotation, anchor, disp);
    final PointSymbolizer symbolizer = SF.pointSymbolizer(name, geometry, desc, unit, graphic);
    final MutableStyle style = SF.style(symbolizer);
    return style;
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) Stroke(org.opengis.style.Stroke) GraphicStroke(org.opengis.style.GraphicStroke) Fill(org.opengis.style.Fill) GraphicFill(org.opengis.style.GraphicFill) Description(org.opengis.style.Description) Graphic(org.opengis.style.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) ExternalMark(org.opengis.style.ExternalMark) Mark(org.opengis.style.Mark) Unit(javax.measure.Unit) Displacement(org.opengis.style.Displacement) AnchorPoint(org.opengis.style.AnchorPoint) MutableStyle(org.geotoolkit.style.MutableStyle) Expression(org.opengis.filter.Expression)

Example 12 with Mark

use of org.opengis.style.Mark in project geotoolkit by Geomatys.

the class CachedGraphic method evaluateGraphic.

private boolean evaluateGraphic() {
    final List<GraphicalSymbol> symbols = styleElement.graphicalSymbols();
    final Expression expOpacity = styleElement.getOpacity();
    final Expression expRotation = styleElement.getRotation();
    final Expression expSize = styleElement.getSize();
    // Opacity -------------------------------------
    if (GO2Utilities.isStatic(expOpacity)) {
        cachedOpacity = GO2Utilities.evaluate(expOpacity, null, 1f, 0f, 1f);
        // we return false, opacity is 0 no need to cache or draw anything
        if (cachedOpacity <= 0) {
            isStaticVisible = VisibilityState.UNVISIBLE;
            return false;
        }
        // this style is visible
        if (isStaticVisible == VisibilityState.NOT_DEFINED)
            isStaticVisible = VisibilityState.VISIBLE;
    } else {
        // this style visibility is dynamic
        if (isStaticVisible != VisibilityState.UNVISIBLE)
            isStaticVisible = VisibilityState.DYNAMIC;
        isStatic = false;
        GO2Utilities.getRequieredAttributsName(expOpacity, requieredAttributs);
    }
    // Rotation ------------------------------------
    if (GO2Utilities.isStatic(expRotation)) {
        cachedRotation = (float) Math.toRadians(GO2Utilities.evaluate(expRotation, null, Number.class, 0d).doubleValue());
    } else {
        isStatic = false;
        GO2Utilities.getRequieredAttributsName(expRotation, requieredAttributs);
    }
    // Size ----------------------------------------
    if (GO2Utilities.isStatic(expSize)) {
        cachedSize = GO2Utilities.evaluate(expSize, null, Number.class, Float.NaN).floatValue();
        // we return false, size is 0 no need to cache or draw anything
        if (cachedSize <= 0) {
            isStaticVisible = VisibilityState.UNVISIBLE;
            return false;
        }
        // this style is visible
        if (isStaticVisible == VisibilityState.NOT_DEFINED)
            isStaticVisible = VisibilityState.VISIBLE;
    } else {
        // this style visibility is dynamic
        if (isStaticVisible != VisibilityState.UNVISIBLE)
            isStaticVisible = VisibilityState.DYNAMIC;
        isStatic = false;
        GO2Utilities.getRequieredAttributsName(expSize, requieredAttributs);
    }
    // grab the first available symbol-------------------
    boolean found = false;
    graphicLoop: for (GraphicalSymbol symbol : symbols) {
        if (symbol instanceof Mark) {
            CachedMark candidateMark = CachedMark.cache((Mark) symbol);
            // test if the mark is valid, could be false if an URL or anything is broken
            if (candidateMark.isValid()) {
                // if the mark is invisible this graphic is invisible too
                // so there is nothing to cache
                VisibilityState markStaticVisibility = candidateMark.isStaticVisible();
                if (markStaticVisibility == VisibilityState.UNVISIBLE) {
                    isStaticVisible = VisibilityState.UNVISIBLE;
                    return false;
                } else if (markStaticVisibility == VisibilityState.VISIBLE) {
                    if (isStaticVisible == VisibilityState.NOT_DEFINED)
                        isStaticVisible = VisibilityState.VISIBLE;
                    if (!candidateMark.isStatic())
                        isStatic = false;
                    this.cachedMark = candidateMark;
                } else {
                    if (isStaticVisible != VisibilityState.UNVISIBLE)
                        isStaticVisible = VisibilityState.DYNAMIC;
                    if (!candidateMark.isStatic())
                        isStatic = false;
                    this.cachedMark = candidateMark;
                }
                candidateMark.getRequieredAttributsName(requieredAttributs);
                found = true;
                break graphicLoop;
            }
        } else if (symbol instanceof ExternalGraphic) {
            CachedExternal candidateExternal = CachedExternal.cache((ExternalGraphic) symbol);
            if (candidateExternal.isValid()) {
                // so there is nothing to cache
                if (candidateExternal.isStaticVisible() == VisibilityState.UNVISIBLE) {
                    isStaticVisible = VisibilityState.UNVISIBLE;
                    return false;
                }
                // }else{
                if (isStaticVisible != VisibilityState.UNVISIBLE)
                    isStaticVisible = VisibilityState.DYNAMIC;
                isStatic = false;
                this.cachedExternal = candidateExternal;
                // }
                candidateExternal.getRequieredAttributsName(requieredAttributs);
                found = true;
                break graphicLoop;
            }
        }
    }
    // create the default square symbol is no symbol found
    if (!found) {
        Mark mark = GO2Utilities.STYLE_FACTORY.mark();
        cachedMark = CachedMark.cache(mark);
        if (isStaticVisible == VisibilityState.NOT_DEFINED)
            isStaticVisible = VisibilityState.VISIBLE;
    // //if size is static, we can cache the symbol graphic
    // if(!Float.isNaN(cachedSize)){
    // BufferedImage buffer = cachedMark.getImage(null, cachedSize);
    // cachedValues.put(ID_SUBBUFFER, buffer);
    // }else{
    // }
    }
    return true;
}
Also used : Expression(org.opengis.filter.Expression) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.opengis.style.Mark) ExternalGraphic(org.opengis.style.ExternalGraphic)

Example 13 with Mark

use of org.opengis.style.Mark in project geotoolkit by Geomatys.

the class DefaultStyleVisitor method visit.

@Override
public Object visit(final Graphic graphic, Object data) {
    final AnchorPoint ac = graphic.getAnchorPoint();
    if (ac != null) {
        data = ac.accept(this, data);
    }
    final Displacement disp = graphic.getDisplacement();
    if (disp != null) {
        data = disp.accept(this, data);
    }
    final Expression opa = graphic.getOpacity();
    if (opa != null) {
        visit(opa, data);
    }
    final Expression rot = graphic.getRotation();
    if (rot != null) {
        visit(rot, data);
    }
    final Expression size = graphic.getSize();
    if (size != null) {
        visit(size, data);
    }
    final List<GraphicalSymbol> symbols = graphic.graphicalSymbols();
    if (symbols != null) {
        for (GraphicalSymbol gs : symbols) {
            if (gs instanceof Mark) {
                data = ((Mark) gs).accept(this, data);
            } else if (gs instanceof ExternalGraphic) {
                data = ((ExternalGraphic) gs).accept(this, data);
            }
        }
    }
    return data;
}
Also used : AnchorPoint(org.opengis.style.AnchorPoint) Expression(org.opengis.filter.Expression) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.opengis.style.Mark) ExternalMark(org.opengis.style.ExternalMark) ExternalGraphic(org.opengis.style.ExternalGraphic) Displacement(org.opengis.style.Displacement)

Example 14 with Mark

use of org.opengis.style.Mark in project geotoolkit by Geomatys.

the class ListingPropertyVisitor method visit.

@Override
public Object visit(final Graphic graphic, Object data) {
    final AnchorPoint ac = graphic.getAnchorPoint();
    if (ac != null) {
        data = ac.accept(this, data);
    }
    final Displacement disp = graphic.getDisplacement();
    if (disp != null) {
        data = disp.accept(this, data);
    }
    final Expression opa = graphic.getOpacity();
    if (opa != null) {
        visit(opa, (Collection<String>) data);
    }
    final Expression rot = graphic.getRotation();
    if (rot != null) {
        visit(rot, (Collection<String>) data);
    }
    final Expression size = graphic.getSize();
    if (size != null) {
        visit(size, (Collection<String>) data);
    }
    final List<GraphicalSymbol> symbols = graphic.graphicalSymbols();
    if (symbols != null) {
        for (GraphicalSymbol gs : symbols) {
            if (gs instanceof Mark) {
                data = ((Mark) gs).accept(this, data);
            } else if (gs instanceof ExternalGraphic) {
                data = ((ExternalGraphic) gs).accept(this, data);
            }
        }
    }
    return data;
}
Also used : AnchorPoint(org.opengis.style.AnchorPoint) Expression(org.opengis.filter.Expression) GraphicalSymbol(org.opengis.style.GraphicalSymbol) Mark(org.opengis.style.Mark) ExternalMark(org.opengis.style.ExternalMark) ExternalGraphic(org.opengis.style.ExternalGraphic) Displacement(org.opengis.style.Displacement)

Example 15 with Mark

use of org.opengis.style.Mark in project geotoolkit by Geomatys.

the class SEforSLD110Test method testPointSymbolizer.

@Test
public void testPointSymbolizer() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_SE_SYMBOL_POINT);
    assertNotNull(obj);
    JAXBElement<org.geotoolkit.se.xml.v110.PointSymbolizerType> jax = (JAXBElement<org.geotoolkit.se.xml.v110.PointSymbolizerType>) obj;
    PointSymbolizer pointSymbol = TRANSFORMER_GT.visit(jax.getValue());
    assertNotNull(pointSymbol);
    assertEquals(pointSymbol.getGeometryPropertyName(), valueGeom);
    assertEquals(Units.POINT, pointSymbol.getUnitOfMeasure());
    assertNotNull(pointSymbol.getGraphic());
    assertEquals(floatValue(pointSymbol.getGraphic().getOpacity()), 0.7f, DELTA);
    assertEquals(floatValue(pointSymbol.getGraphic().getRotation()), 110f, DELTA);
    assertEquals(floatValue(pointSymbol.getGraphic().getSize()), 32f, DELTA);
    Mark mark = (Mark) pointSymbol.getGraphic().graphicalSymbols().get(0);
    assertEquals(stringValue(mark.getWellKnownName()), "square");
    assertEquals(floatValue(mark.getStroke().getWidth()), 13f, DELTA);
    assertEquals(floatValue(mark.getStroke().getOpacity()), 0.4f, DELTA);
    assertEquals(stringValue(mark.getStroke().getLineJoin()), "bevel");
    assertEquals(stringValue(mark.getStroke().getLineCap()), "butt");
    assertEquals(floatValue(mark.getStroke().getDashOffset()), 2.3f, DELTA);
    assertEquals(colorValue(mark.getStroke().getColor()), ObjectConverters.convert("#404040", Color.class));
    assertEquals(floatValue(mark.getFill().getOpacity()), 1.0f, DELTA);
    assertEquals(colorValue(mark.getFill().getColor()), ObjectConverters.convert("#808080", Color.class));
    // Write test
    JAXBElement<org.geotoolkit.se.xml.v110.PointSymbolizerType> pvt = TRANSFORMER_OGC.visit(pointSymbol, null);
    assertNotNull(pvt);
    assertEquals(pvt.getValue().getGeometry(), null);
    org.geotoolkit.se.xml.v110.GraphicType gra = pvt.getValue().getGraphic();
    assertNotNull(gra.getOpacity());
    assertNotNull(gra.getRotation());
    assertNotNull(gra.getSize());
    assertEquals(gra.getExternalGraphicOrMark().size(), 1);
    assertNotNull(pvt.getValue().getGraphic());
    MARSHALLER.marshal(pvt, TEST_FILE_SE_SYMBOL_POINT);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) Marshaller(javax.xml.bind.Marshaller) Color(java.awt.Color) Mark(org.opengis.style.Mark) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Aggregations

Mark (org.opengis.style.Mark)19 GraphicalSymbol (org.opengis.style.GraphicalSymbol)14 Expression (org.opengis.filter.Expression)11 ArrayList (java.util.ArrayList)10 PointSymbolizer (org.opengis.style.PointSymbolizer)10 AnchorPoint (org.opengis.style.AnchorPoint)9 Displacement (org.opengis.style.Displacement)9 ExternalMark (org.opengis.style.ExternalMark)9 Fill (org.opengis.style.Fill)9 Stroke (org.opengis.style.Stroke)9 Graphic (org.opengis.style.Graphic)8 Unit (javax.measure.Unit)6 Description (org.opengis.style.Description)6 MutableStyle (org.geotoolkit.style.MutableStyle)5 Test (org.junit.Test)5 GraphicFill (org.opengis.style.GraphicFill)5 GraphicStroke (org.opengis.style.GraphicStroke)5 ExternalGraphic (org.opengis.style.ExternalGraphic)4 LineSymbolizer (org.opengis.style.LineSymbolizer)4 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)4