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