Search in sources :

Example 1 with ExternalGraphic

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

the class StyleCacheTest method externalCacheTest.

@Test
public void externalCacheTest() throws Exception {
    final ExternalGraphic ext = SF.externalGraphic("/org/geotoolkit/display2d/sample.svg", "image/svg");
    CachedExternal cached = CachedExternal.cache(ext);
    assertFalse(cached.isStatic());
    assertEquals(VisibilityState.VISIBLE, cached.isStaticVisible());
    assertTrue(cached.isVisible(null));
    BufferedImage buffer = cached.getImage(Float.NaN, 1, null);
    assertNotNull(buffer);
    assertEquals(buffer.getWidth(), 12);
    assertEquals(buffer.getHeight(), 12);
    buffer = cached.getImage(null, 1, null);
    assertEquals(buffer.getWidth(), 12);
    assertEquals(buffer.getHeight(), 12);
    buffer = cached.getImage(24f, 1, null);
    assertEquals(buffer.getWidth(), 24);
    assertEquals(buffer.getHeight(), 24);
}
Also used : CachedExternal(org.geotoolkit.display2d.style.CachedExternal) ExternalGraphic(org.opengis.style.ExternalGraphic) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 2 with ExternalGraphic

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

the class InlineImageTest method readImage.

@Test
public void readImage() throws Exception {
    final BufferedImage image = new BufferedImage(20, 10, BufferedImage.TYPE_INT_ARGB);
    final String geometry = null;
    final ExternalGraphic external = SF.externalGraphic(new ImageIcon(image), Collections.EMPTY_LIST);
    final Graphic graphic = SF.graphic(Collections.singletonList((GraphicalSymbol) external), LITERAL_ONE_FLOAT, LITERAL_ONE_FLOAT, LITERAL_ONE_FLOAT, DEFAULT_ANCHOR_POINT, DEFAULT_DISPLACEMENT);
    final PointSymbolizer ips = SF.pointSymbolizer("", geometry, DEFAULT_DESCRIPTION, Units.POINT, graphic);
    final MutableStyle style = SF.style(ips);
    final File f = File.createTempFile("sld", ".xml");
    f.deleteOnExit();
    final StyleXmlIO io = new StyleXmlIO();
    io.writeStyle(f, style, Specification.StyledLayerDescriptor.V_1_1_0);
    final MutableStyle result = io.readStyle(f, Specification.SymbologyEncoding.V_1_1_0);
    final Symbolizer s = result.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
    assertTrue(s instanceof PointSymbolizer);
    final PointSymbolizer ps = (PointSymbolizer) s;
    final ExternalGraphic eg = (ExternalGraphic) ps.getGraphic().graphicalSymbols().get(0);
    assertNotNull(eg);
    final Icon ri = eg.getInlineContent();
    assertNotNull(ri);
    assertEquals(20, ri.getIconWidth());
    assertEquals(10, ri.getIconHeight());
}
Also used : ImageIcon(javax.swing.ImageIcon) PointSymbolizer(org.opengis.style.PointSymbolizer) MutableStyle(org.geotoolkit.style.MutableStyle) Graphic(org.opengis.style.Graphic) ExternalGraphic(org.opengis.style.ExternalGraphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) ExternalGraphic(org.opengis.style.ExternalGraphic) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) PointSymbolizer(org.opengis.style.PointSymbolizer) Symbolizer(org.opengis.style.Symbolizer) Test(org.junit.Test)

Example 3 with ExternalGraphic

use of org.opengis.style.ExternalGraphic 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 4 with ExternalGraphic

use of org.opengis.style.ExternalGraphic 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 5 with ExternalGraphic

use of org.opengis.style.ExternalGraphic 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)

Aggregations

ExternalGraphic (org.opengis.style.ExternalGraphic)7 GraphicalSymbol (org.opengis.style.GraphicalSymbol)6 Mark (org.opengis.style.Mark)4 BufferedImage (java.awt.image.BufferedImage)3 Test (org.junit.Test)3 Expression (org.opengis.filter.Expression)3 ExternalMark (org.opengis.style.ExternalMark)3 AnchorPoint (org.opengis.style.AnchorPoint)2 Displacement (org.opengis.style.Displacement)2 PointSymbolizer (org.opengis.style.PointSymbolizer)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Icon (javax.swing.Icon)1 ImageIcon (javax.swing.ImageIcon)1 CachedExternal (org.geotoolkit.display2d.style.CachedExternal)1 CachedPointSymbolizer (org.geotoolkit.display2d.style.CachedPointSymbolizer)1 ExternalGraphicType (org.geotoolkit.se.xml.v110.ExternalGraphicType)1 GraphicType (org.geotoolkit.se.xml.v110.GraphicType)1 LegendGraphicType (org.geotoolkit.se.xml.v110.LegendGraphicType)1 StyleXmlIO (org.geotoolkit.sld.xml.StyleXmlIO)1