Search in sources :

Example 1 with ExternalMark

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

the class ListingPropertyVisitor method visit.

@Override
public Object visit(final Mark mark, Object data) {
    final ExternalMark em = mark.getExternalMark();
    if (em != null) {
        data = em.accept(this, data);
    }
    final Fill fill = mark.getFill();
    if (fill != null) {
        data = fill.accept(this, data);
    }
    final Stroke stroke = mark.getStroke();
    if (stroke != null) {
        data = stroke.accept(this, data);
    }
    final Expression wkn = mark.getWellKnownName();
    if (wkn != null) {
        visit(wkn, (Collection<String>) data);
    }
    return data;
}
Also used : GraphicFill(org.opengis.style.GraphicFill) Fill(org.opengis.style.Fill) Stroke(org.opengis.style.Stroke) GraphicStroke(org.opengis.style.GraphicStroke) ExternalMark(org.opengis.style.ExternalMark) Expression(org.opengis.filter.Expression)

Example 2 with ExternalMark

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

the class GTtoSE110Transformer method visit.

/**
 * transform a GT graphic in jaxb graphic
 */
@Override
public GraphicType visit(final Graphic graphic, final Object data) {
    final GraphicType gt = se_factory.createGraphicType();
    gt.setAnchorPoint(visit(graphic.getAnchorPoint(), null));
    for (final GraphicalSymbol gs : graphic.graphicalSymbols()) {
        if (gs instanceof Mark) {
            final Mark mark = (Mark) gs;
            gt.getExternalGraphicOrMark().add(visit(mark, null));
        } else if (gs instanceof ExternalMark) {
            final ExternalMark ext = (ExternalMark) gs;
            gt.getExternalGraphicOrMark().add(visit(ext, null));
        } else if (gs instanceof ExternalGraphic) {
            final ExternalGraphic ext = (ExternalGraphic) gs;
            gt.getExternalGraphicOrMark().add(visit(ext, null));
        }
    }
    gt.setDisplacement(visit(graphic.getDisplacement(), null));
    gt.setOpacity(visitExpression(graphic.getOpacity()));
    gt.setRotation(visitExpression(graphic.getRotation()));
    gt.setSize(visitExpression(graphic.getSize()));
    return gt;
}
Also used : GraphicType(org.geotoolkit.se.xml.v110.GraphicType) ExternalGraphicType(org.geotoolkit.se.xml.v110.ExternalGraphicType) LegendGraphicType(org.geotoolkit.se.xml.v110.LegendGraphicType) ExternalMark(org.opengis.style.ExternalMark) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ExternalMark(org.opengis.style.ExternalMark) Mark(org.opengis.style.Mark) ExternalGraphic(org.opengis.style.ExternalGraphic)

Example 3 with ExternalMark

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

the class CachedMark method getShape.

public Shape getShape(final Object candidate, final RenderingHints hints) {
    evaluate();
    final Expression wkn = styleElement.getWellKnownName();
    final ExternalMark external = styleElement.getExternalMark();
    Shape candidateShape = cachedWKN;
    if (candidateShape == null) {
        String format = null;
        Object markRef = null;
        int markIndex = 0;
        if (wkn != null) {
            markRef = wkn.apply(candidate);
        } else if (external != null) {
            format = external.getFormat();
            markRef = external.getOnlineResource().getLinkage().toString();
            markIndex = external.getMarkIndex();
        }
        for (int i = 0; i < MARK_FACTORIES.length && candidateShape == null; i++) {
            try {
                candidateShape = MARK_FACTORIES[i].evaluateShape(format, markRef, markIndex);
            } catch (PortrayalException ex) {
                LOGGER.log(Level.WARNING, ex.getLocalizedMessage(), ex);
            }
        }
    }
    return candidateShape;
}
Also used : Shape(java.awt.Shape) TransformedShape(org.geotoolkit.display.shape.TransformedShape) ExternalMark(org.opengis.style.ExternalMark) Expression(org.opengis.filter.Expression) PortrayalException(org.geotoolkit.display.PortrayalException)

Example 4 with ExternalMark

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

the class CachedMark method getImage.

public BufferedImage getImage(final Object candidate, final Float size, final RenderingHints hints) {
    evaluate();
    final Expression wkn = styleElement.getWellKnownName();
    final ExternalMark external = styleElement.getExternalMark();
    int j2dSize = 16;
    float margin = 0;
    int maxWidth = 0;
    int center = 0;
    Shape candidateShape = getShape(candidate, hints);
    if (wkn != null || external != null) {
        j2dSize = (size != null) ? size.intValue() : 16;
        if (j2dSize < 0)
            j2dSize = 0;
        if (j2dSize > 1000)
            j2dSize = 1000;
        margin = cachedStroke.getMargin(candidate, 1);
        maxWidth = (int) (margin * 2 + 0.5f) + j2dSize;
        center = maxWidth / 2;
    }
    if (maxWidth < 1)
        maxWidth = 1;
    if (candidateShape != null) {
        BufferedImage buffer = new BufferedImage(maxWidth, maxWidth, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = (Graphics2D) buffer.getGraphics();
        if (hints != null)
            g2.setRenderingHints(hints);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.translate(center, center);
        TransformedShape trs = new TransformedShape();
        trs.setOriginalShape(candidateShape);
        trs.scale(j2dSize, j2dSize);
        // trs.createTransformedShape(marker);
        Shape shp = trs;
        // test if we need to paint the fill
        if (cachedFill.isVisible(candidate)) {
            g2.setPaint(cachedFill.getJ2DPaint(candidate, 0, 0, 1, hints));
            g2.setComposite(cachedFill.getJ2DComposite(candidate));
            g2.fill(shp);
        }
        // test if we need to paint the stroke
        if (cachedStroke.isVisible(candidate)) {
            g2.setStroke(cachedStroke.getJ2DStroke(candidate, 1));
            g2.setPaint(cachedStroke.getJ2DPaint(candidate, 0, 0, 1, hints));
            g2.setComposite(cachedStroke.getJ2DComposite(candidate));
            g2.draw(shp);
        }
        g2.dispose();
        return buffer;
    } else if (external != null) {
        return createImage(external, j2dSize, hints);
    }
    return null;
}
Also used : Shape(java.awt.Shape) TransformedShape(org.geotoolkit.display.shape.TransformedShape) ExternalMark(org.opengis.style.ExternalMark) TransformedShape(org.geotoolkit.display.shape.TransformedShape) Expression(org.opengis.filter.Expression) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 5 with ExternalMark

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

the class CachedMark method evaluateMark.

private boolean evaluateMark() {
    final Expression expWKN = styleElement.getWellKnownName();
    boolean isWKN = false;
    if (expWKN == null) {
        isWKN = false;
    } else if (GO2Utilities.isStatic(expWKN)) {
        Object markRef = expWKN.apply(null);
        for (int i = 0; i < MARK_FACTORIES.length && cachedWKN == null; i++) {
            try {
                cachedWKN = MARK_FACTORIES[i].evaluateShape(null, markRef, 0);
            } catch (PortrayalException ex) {
                LOGGER.log(Level.WARNING, ex.getLocalizedMessage(), ex);
            }
        }
        // we return false, invalid marker
        if (cachedWKN == null) {
            isStaticVisible = VisibilityState.UNVISIBLE;
            return false;
        }
        // this style is visible
        if (isStaticVisible == VisibilityState.NOT_DEFINED)
            isStaticVisible = VisibilityState.VISIBLE;
        isWKN = true;
    } else {
        // this style visibility is dynamic
        if (isStaticVisible == VisibilityState.NOT_DEFINED)
            isStaticVisible = VisibilityState.VISIBLE;
        isStatic = false;
        GO2Utilities.getRequieredAttributsName(expWKN, requieredAttributs);
        isWKN = true;
    }
    final ExternalMark external = styleElement.getExternalMark();
    if (!isWKN && external != null) {
        // no well knowned mark but an external mark
        return true;
    } else if (!isWKN) {
        // no well knowned mark and no external
        isStaticVisible = VisibilityState.UNVISIBLE;
        isStatic = true;
        return false;
    }
    return true;
}
Also used : ExternalMark(org.opengis.style.ExternalMark) Expression(org.opengis.filter.Expression) PortrayalException(org.geotoolkit.display.PortrayalException)

Aggregations

ExternalMark (org.opengis.style.ExternalMark)10 Expression (org.opengis.filter.Expression)7 Fill (org.opengis.style.Fill)4 GraphicFill (org.opengis.style.GraphicFill)4 GraphicStroke (org.opengis.style.GraphicStroke)4 Stroke (org.opengis.style.Stroke)4 GraphicalSymbol (org.opengis.style.GraphicalSymbol)3 Mark (org.opengis.style.Mark)3 Shape (java.awt.Shape)2 BufferedImage (java.awt.image.BufferedImage)2 PortrayalException (org.geotoolkit.display.PortrayalException)2 TransformedShape (org.geotoolkit.display.shape.TransformedShape)2 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 RenderedImage (java.awt.image.RenderedImage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Unit (javax.measure.Unit)1