Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions lib/src/layer/polyline_layer/painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ class _PolylinePainter<R extends Object> extends CustomPainter
points: projectedPolyline.points,
shift: shift,
);
if (!areOffsetsVisible(offsets)) return WorldWorkControl.invisible;

final strokeWidth = polyline.useStrokeWidthInMeter
? metersToScreenPixels(
projectedPolyline.polyline.points.first,
polyline.strokeWidth,
)
: polyline.strokeWidth;

if (!areOffsetsVisible(offsets, strokeWidth)) {
return WorldWorkControl.invisible;
}

final hittableDistance = math.max(
strokeWidth / 2 + polyline.borderStrokeWidth / 2,
minimumHitbox,
Expand Down Expand Up @@ -133,18 +137,6 @@ class _PolylinePainter<R extends Object> extends CustomPainter
points: projectedPolyline.points,
shift: shift,
);
if (!areOffsetsVisible(offsets)) return WorldWorkControl.invisible;

final hash = polyline.renderHashCode;
if (needsLayerSaving || (lastHash != null && lastHash != hash)) {
drawPaths();
}
lastHash = hash;
needsLayerSaving = polyline.color.a < 1 ||
(polyline.gradientColors?.any((c) => c.a < 1) ?? false);

// strokeWidth, or strokeWidth + borderWidth if relevant.
late double largestStrokeWidth;

late final double strokeWidth;
if (polyline.useStrokeWidthInMeter) {
Expand All @@ -155,7 +147,20 @@ class _PolylinePainter<R extends Object> extends CustomPainter
} else {
strokeWidth = polyline.strokeWidth;
}
largestStrokeWidth = strokeWidth;

if (!areOffsetsVisible(offsets, strokeWidth))
return WorldWorkControl.invisible;

final hash = polyline.renderHashCode;
if (needsLayerSaving || (lastHash != null && lastHash != hash)) {
drawPaths();
}
lastHash = hash;
needsLayerSaving = polyline.color.a < 1 ||
(polyline.gradientColors?.any((c) => c.a < 1) ?? false);

// strokeWidth, or strokeWidth + borderWidth if relevant.
double largestStrokeWidth = strokeWidth;

final isSolid = polyline.pattern == const StrokePattern.solid();
final isDashed = polyline.pattern.segments != null;
Expand Down
9 changes: 7 additions & 2 deletions lib/src/layer/shared/feature_layer_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mixin FeatureLayerUtils on CustomPainter {
/// Determine whether the specified offsets are visible within the viewport
///
/// Always returns `false` if the specified list is empty.
bool areOffsetsVisible(Iterable<Offset> offsets) {
bool areOffsetsVisible(Iterable<Offset> offsets, [double margin = 0]) {
if (offsets.isEmpty) {
return false;
}
Expand All @@ -43,7 +43,12 @@ mixin FeatureLayerUtils on CustomPainter {
if (maxX < offset.dx) maxX = offset.dx;
if (maxY < offset.dy) maxY = offset.dy;
}
return viewportRect.overlaps(Rect.fromLTRB(minX, minY, maxX, maxY));
return viewportRect.overlaps(Rect.fromLTRB(
minX - margin,
minY - margin,
maxX + margin,
maxY + margin,
));
}

/// Perform the callback in all world copies (until stopped)
Expand Down