From 597b6ba575c7577a13c1fda0230d467495909a8b Mon Sep 17 00:00:00 2001 From: Aleksandr Demchenko Date: Mon, 23 Feb 2026 14:12:41 +0100 Subject: [PATCH 1/2] Calculate polyline visibility based on strokeWidth --- lib/src/layer/polyline_layer/painter.dart | 36 ++++++++++--------- lib/src/layer/shared/feature_layer_utils.dart | 9 +++-- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/src/layer/polyline_layer/painter.dart b/lib/src/layer/polyline_layer/painter.dart index 4656f83a4..5b7f38625 100644 --- a/lib/src/layer/polyline_layer/painter.dart +++ b/lib/src/layer/polyline_layer/painter.dart @@ -48,14 +48,16 @@ class _PolylinePainter extends CustomPainter points: projectedPolyline.points, shift: shift, ); - if (!areOffsetsVisible(offsets)) return WorldWorkControl.invisible; final strokeWidth = polyline.useStrokeWidthInMeter ? metersToScreenPixels( - projectedPolyline.polyline.points.first, - polyline.strokeWidth, - ) + 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, @@ -133,18 +135,6 @@ class _PolylinePainter 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) { @@ -155,7 +145,19 @@ class _PolylinePainter 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; diff --git a/lib/src/layer/shared/feature_layer_utils.dart b/lib/src/layer/shared/feature_layer_utils.dart index 981eb775e..0fbd6057f 100644 --- a/lib/src/layer/shared/feature_layer_utils.dart +++ b/lib/src/layer/shared/feature_layer_utils.dart @@ -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 offsets) { + bool areOffsetsVisible(Iterable offsets, [double margin = 0]) { if (offsets.isEmpty) { return false; } @@ -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) From 6bd8035ed68d8f934662606a191af2cda6736419 Mon Sep 17 00:00:00 2001 From: Aleksandr Demchenko Date: Mon, 23 Feb 2026 19:36:07 +0100 Subject: [PATCH 2/2] Fix formatting --- lib/src/layer/polyline_layer/painter.dart | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/src/layer/polyline_layer/painter.dart b/lib/src/layer/polyline_layer/painter.dart index 5b7f38625..945f39c0e 100644 --- a/lib/src/layer/polyline_layer/painter.dart +++ b/lib/src/layer/polyline_layer/painter.dart @@ -51,12 +51,14 @@ class _PolylinePainter extends CustomPainter final strokeWidth = polyline.useStrokeWidthInMeter ? metersToScreenPixels( - projectedPolyline.polyline.points.first, - polyline.strokeWidth, - ) + projectedPolyline.polyline.points.first, + polyline.strokeWidth, + ) : polyline.strokeWidth; - if (!areOffsetsVisible(offsets, strokeWidth)) return WorldWorkControl.invisible; + if (!areOffsetsVisible(offsets, strokeWidth)) { + return WorldWorkControl.invisible; + } final hittableDistance = math.max( strokeWidth / 2 + polyline.borderStrokeWidth / 2, @@ -146,7 +148,8 @@ class _PolylinePainter extends CustomPainter strokeWidth = polyline.strokeWidth; } - if (!areOffsetsVisible(offsets, strokeWidth)) return WorldWorkControl.invisible; + if (!areOffsetsVisible(offsets, strokeWidth)) + return WorldWorkControl.invisible; final hash = polyline.renderHashCode; if (needsLayerSaving || (lastHash != null && lastHash != hash)) {