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