use of org.geotoolkit.display2d.style.labeling.PointLabelDescriptor in project geotoolkit by Geomatys.
the class PointLabelCandidateRenderer method render.
@Override
public void render(final Candidate candidate) {
if (!(candidate instanceof PointCandidate))
return;
final PointCandidate pointCandidate = (PointCandidate) candidate;
final PointLabelDescriptor label = pointCandidate.getDescriptor();
final double rotation = Math.toRadians(label.getRotation());
context.switchToDisplayCRS();
// rotation--------------------------------------------------------------
if (rotation != 0) {
g2.rotate(rotation, pointCandidate.getCorrectedX(), pointCandidate.getCorrectedY());
}
final String text = label.getText();
final Font font = label.getTextFont();
g2.setFont(font);
// paint halo------------------------------------------------------------
final float haloWidth = label.getHaloWidth();
if (haloWidth > 0) {
final float haloWidth2 = haloWidth + haloWidth;
final GlyphVector glyphVector = font.createGlyphVector(g2.getFontRenderContext(), text);
final Rectangle2D bounds = glyphVector.getVisualBounds();
Shape shape = new RoundRectangle2D.Double(bounds.getMinX() + pointCandidate.getCorrectedX() - haloWidth, bounds.getMinY() + pointCandidate.getCorrectedY() - haloWidth, bounds.getWidth() + haloWidth2, bounds.getHeight() + haloWidth2, 2 + haloWidth2, 2 + haloWidth2);
g2.setPaint(label.getHaloPaint());
g2.fill(shape);
}
// paint text------------------------------------------------------------
g2.setPaint(label.getTextPaint());
g2.drawString(text, pointCandidate.getCorrectedX(), pointCandidate.getCorrectedY());
// reset rotation
if (rotation != 0) {
g2.rotate(-rotation, pointCandidate.getCorrectedX(), pointCandidate.getCorrectedY());
}
}
use of org.geotoolkit.display2d.style.labeling.PointLabelDescriptor in project geotoolkit by Geomatys.
the class DisplacementLabelRenderer method portrayLabels.
/**
* {@inheritDoc }
*/
@Override
public boolean portrayLabels() {
final Graphics2D g2 = context.getGraphics();
// enable antialiasing for labels
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
List<Candidate> candidates = new ArrayList<Candidate>();
// generate all the candidates
// priority is in the order of the layers provided.
int priority = layers.size();
for (final LabelLayer layer : layers) {
for (LabelDescriptor label : layer.labels()) {
Candidate[] cs = null;
if (label instanceof PointLabelDescriptor) {
cs = pointRenderer.generateCandidat((PointLabelDescriptor) label);
} else if (label instanceof LinearLabelDescriptor) {
cs = LinearRenderer.generateCandidat((LinearLabelDescriptor) label);
} else {
cs = null;
}
if (cs != null) {
for (Candidate c : cs) {
c.setPriority(priority);
candidates.add(c);
}
}
}
priority--;
}
// displace or remove the candidates
candidates = optimize(candidates);
// paint the remaining candidates
for (Candidate candidate : candidates) {
if (candidate instanceof PointCandidate) {
pointRenderer.render(candidate);
} else if (candidate instanceof LinearCandidate) {
LinearRenderer.render(candidate);
}
}
layers.clear();
return !candidates.isEmpty();
}
Aggregations