renderNode method

  1. @override
void renderNode(
  1. RenderInfo<Renderinstruction> renderInfo,
  2. RenderContext renderContext,
  3. NodeProperties nodeProperties
)

Renders a symbol for a node (e.g., a POI).

Implementation

@override
void renderNode(RenderInfo renderInfo, RenderContext renderContext, NodeProperties nodeProperties) {
  if (renderContext is! UiRenderContext) throw Exception("renderContext is not UiRenderContext ${renderContext.runtimeType}");
  if (symbolImage == null) return;
  MappointRelative relative = nodeProperties.getCoordinatesAbsolute().offset(renderContext.reference).offset(0, renderinstruction.dy);
  MapRectangle boundary = renderinstruction.getBoundary(renderInfo);
  UiMatrix? matrix;
  if (renderinstruction.rotateWithMap) {
    if (renderinstruction.theta != 0) {
      matrix = UiMatrix();
      // rotation of the rotationRadian parameter is always in the opposite direction.
      // If the map is moving clockwise we must rotate the symbol counterclockwise
      // to keep it horizontal
      matrix.rotate(renderinstruction.theta, pivotX: boundary.left, pivotY: boundary.top);
    }
  } else {
    if (renderinstruction.theta != 0 || renderContext.rotationRadian != 0) {
      matrix = UiMatrix();
      // rotation of the rotationRadian parameter is always in the opposite direction.
      // If the map is moving clockwise we must rotate the symbol counterclockwise
      // to keep it horizontal
      matrix.rotate(renderinstruction.theta - renderContext.rotationRadian, pivotX: boundary.left, pivotY: boundary.top);
    }
  }

  if (debug) {
    // print(
    //   "drawing ${symbolImage} ${fill.getColorAsNumber().toRadixString(16)} at ${relative.x + boundary.left} / ${relative.y + boundary.top} (${boundary.getWidth()},${boundary.getHeight()}) ${renderinstruction.theta}/$rotationRadian at size ${(canvas as FlutterCanvas).size}",
    // ); //bitmap.debugGetOpenHandleStackTraces();
    ui.Canvas? uiCanvas = renderContext.canvas.expose();
    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),
    );
    uiCanvas.drawCircle(ui.Offset(relative.dx, relative.dy), 10, ui.Paint()..color = Colors.green.withOpacity(0.5));
  }

  renderContext.canvas.drawPicture(
    symbolImage: symbolImage!,
    matrix: matrix,
    left: relative.dx + boundary.left,
    top: relative.dy + boundary.top,
    paint: fill,
  );
}