matchWay method

  1. @override
void matchWay(
  1. LayerContainer layerContainer,
  2. WayProperties wayProperties
)
override

Checks the wayProperties and adds itself to the layerContainer if there is something to draw.

Implementation

@override
void matchWay(LayerContainer layerContainer, WayProperties wayProperties) {
  String? caption = textKey!.getValue(wayProperties.getTags());
  if (caption == null || caption.trim().isEmpty) {
    return;
  }
  caption = caption.trim();
  LineSegmentPath? lineSegmentPath = wayProperties.calculateStringPath(dy);
  if (lineSegmentPath == null || lineSegmentPath.segments.isEmpty) {
    return;
  }

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

  PixelProjection projection = PixelProjection(zoomlevel);
  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.end.offset(-origin.x, -origin.y);
      start = segment.pointAlongLineSegment(diff + textSize.width);
    } else {
      //start = segment.start.offset(-origin.x, -origin.y);
      start = segment.pointAlongLineSegment(diff);
    }

    layerContainer.addClash(
      RenderInfoNode(
        NodeProperties(
          PointOfInterest(
            wayProperties.layer,
            wayProperties.getTags().tags,
            LatLong(projection.pixelYToLatitude(start.y), projection.pixelXToLongitude(start.x)),
          ),
          projection,
        ),
        this,
        rotateRadians: segment.getTheta(),
        caption: caption,
      ),
    );
  }
}