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);
}
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());
}
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;
}
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;
}
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;
}
Aggregations