renderWay method

  1. @override
void renderWay(
  1. RenderInfo<Renderinstruction> renderInfo,
  2. RenderContext renderContext,
  3. WayProperties wayProperties
)

Renders text along a way.

Implementation

@override
void renderWay(RenderInfo renderInfo, RenderContext renderContext, WayProperties wayProperties) {
  if (renderContext is! UiRenderContext) throw Exception("renderContext is not UiRenderContext ${renderContext.runtimeType}");
  if (renderInfo is! RenderInfoWay) throw Exception("renderInfo is not RenderInfoWay ${renderInfo.runtimeType}");

  LineSegmentPath? lineSegmentPath = wayProperties.calculateStringPath(renderinstruction.dy);
  if (lineSegmentPath == null || lineSegmentPath.segments.isEmpty) {
    return;
  }

  MapSize textSize = renderinstruction.getEstimatedTextBoundary(renderInfo.caption!, renderinstruction.strokeWidth);
  lineSegmentPath = lineSegmentPath.reducePathForText(textSize.width, renderinstruction.repeatStart, renderinstruction.repeatGap);
  if (lineSegmentPath.segments.isEmpty) return;

  for (var segment in lineSegmentPath.segments) {
    // So text isn't upside down
    bool doInvert = segment.end.x <= segment.start.x;
    Mappoint start;
    double diff = (segment.length() - textSize.width) / 2;
    if (doInvert) {
      start = segment.pointAlongLineSegment(diff + textSize.width);
    } else {
      start = segment.pointAlongLineSegment(diff);
    }

    if (paintBack != null) {
      ParagraphEntry entry = ParagraphCacheMgr().getEntry(renderInfo.caption!, textPaint, paintBack!, renderinstruction.getMaxTextWidth());
      renderContext.canvas.drawTextRotated(entry.paragraph, renderContext.rotationRadian + segment.getTheta(), start.offset(renderContext.reference));
    }
    if (paintFront != null) {
      ParagraphEntry entry = ParagraphCacheMgr().getEntry(renderInfo.caption!, textPaint, paintFront!, renderinstruction.getMaxTextWidth());
      renderContext.canvas.drawTextRotated(entry.paragraph, renderContext.rotationRadian + segment.getTheta(), start.offset(renderContext.reference));
    }
  }
}