renderNode method
void
renderNode(
- RenderInfo<
Renderinstruction> renderInfo, - RenderContext renderContext,
- NodeProperties nodeProperties
Renders a caption for a node (e.g., a POI).
The caption is drawn at the node's coordinates, adjusted for rotation to remain horizontal.
Implementation
@override
void renderNode(RenderInfo renderInfo, RenderContext renderContext, NodeProperties nodeProperties) {
if (renderContext is! UiRenderContext) throw Exception("renderContext is not UiRenderContext ${renderContext.runtimeType}");
//print("paint caption: $front $back $shape");
MappointRelative relative = nodeProperties.getCoordinatesAbsolute().offset(renderContext.reference).offset(0, renderinstruction.dy);
ui.Canvas? uiCanvas = renderContext.canvas.expose();
if (renderContext.rotationRadian != 0) {
uiCanvas.save();
uiCanvas.translate(relative.dx, relative.dy);
// if the map is rotated 30° clockwise we have to paint the caption -30° (counter-clockwise) so that it is horizontal
uiCanvas.rotate(-renderContext.rotationRadian);
uiCanvas.translate(-relative.dx, -relative.dy);
}
ParagraphEntry? front;
ParagraphEntry? back;
if (paintFront != null) front = ParagraphCacheMgr().getEntry(renderInfo.caption!, textPaint, paintFront!, renderinstruction.getMaxTextWidth());
if (paintBack != null) back = ParagraphCacheMgr().getEntry(renderInfo.caption!, textPaint, paintBack!, renderinstruction.getMaxTextWidth());
MapRectangle boundary = renderinstruction.calculateBoundaryWithSymbol(
renderinstruction.position,
back?.getWidth() ?? front?.getWidth() ?? 0,
back?.getHeight() ?? front?.getHeight() ?? 0,
);
// print(
// "paint caption boundar: $boundary, symbolboundary: ${renderinstruction.symbolBoundary}, ${renderInfo.caption} and position ${renderinstruction.position}",
// );
// uiCanvas.drawRect(
// ui.Rect.fromLTWH(relative.dx + boundary.left, relative.dy + boundary.top, boundary.getWidth(), boundary.getHeight()),
// ui.Paint()..color = Colors.red.withOpacity(0.5),
// );
if (back != null) uiCanvas.drawParagraph(back.paragraph, ui.Offset(relative.dx + boundary.left, relative.dy + boundary.top));
if (front != null) uiCanvas.drawParagraph(front.paragraph, ui.Offset(relative.dx + boundary.left, relative.dy + boundary.top));
//uiCanvas.drawCircle(ui.Offset(relative.dx, relative.dy), 10, ui.Paint()..color = Colors.green.withOpacity(0.5));
if (renderContext.rotationRadian != 0) {
uiCanvas.restore();
}
}