diff --git a/lib/src/layer/polygon_layer/polygon.dart b/lib/src/layer/polygon_layer/polygon.dart index 14436a0ec..fd48da37f 100644 --- a/lib/src/layer/polygon_layer/polygon.dart +++ b/lib/src/layer/polygon_layer/polygon.dart @@ -115,7 +115,7 @@ class Polygon { LatLngBounds? _boundingBox; - /// Get the bounding box of the [Polygon.points] (cached). + /// Get the bounding box of the [points] (cached). LatLngBounds get boundingBox => _boundingBox ??= LatLngBounds.fromPoints(points); diff --git a/lib/src/layer/polyline_layer/polyline.dart b/lib/src/layer/polyline_layer/polyline.dart index 73521a937..0ab84ccfc 100644 --- a/lib/src/layer/polyline_layer/polyline.dart +++ b/lib/src/layer/polyline_layer/polyline.dart @@ -42,6 +42,12 @@ class Polyline { /// {@macro fm.hde.hitValue} final R? hitValue; + LatLngBounds? _boundingBox; + + /// Get the bounding box of the [points] (cached). + LatLngBounds get boundingBox => + _boundingBox ??= LatLngBounds.fromPoints(points); + /// Create a new [Polyline] used for the [PolylineLayer]. Polyline({ required this.points, diff --git a/lib/src/layer/polyline_layer/polyline_layer.dart b/lib/src/layer/polyline_layer/polyline_layer.dart index 0aae00f7f..541e73c8b 100644 --- a/lib/src/layer/polyline_layer/polyline_layer.dart +++ b/lib/src/layer/polyline_layer/polyline_layer.dart @@ -145,6 +145,10 @@ class _PolylineLayerState extends State> for (final projectedPolyline in polylines) { final polyline = projectedPolyline.polyline; + // Test bounding boxes to avoid potentially expensive aggressive culling + // when none of the line is visible + if (!boundsAdjusted.isOverlapping(polyline.boundingBox)) continue; + // Gradient poylines cannot be easily segmented if (polyline.gradientColors != null) { yield projectedPolyline;