diff --git a/example/lib/pages/polyline.dart b/example/lib/pages/polyline.dart index a21c44625..41f2e65b6 100644 --- a/example/lib/pages/polyline.dart +++ b/example/lib/pages/polyline.dart @@ -111,6 +111,24 @@ class _PolylinePageState extends State { subtitle: 'Solid translucent color fill, with different color outline', ), ), + Polyline( + points: const [ + LatLng(43.864797, 11.7112939), + LatLng(36.7948545, 10.2256785), + LatLng(35.566530, 5.584283), + ], + strokeWidth: 10, + color: Colors.blueAccent, + isDotted: true, + segmentSpacingFactor: 3, + borderStrokeWidth: 8, + borderColor: Colors.blue.withOpacity(0.5), + hitValue: ( + title: 'Blue Dotted Line with Custom Spacing', + subtitle: + 'Dotted line with segment spacing controlled by `segmentSpacingFactor`', + ), + ), ]; late final _polylines = Map.fromEntries(_polylinesRaw.map((e) => MapEntry(e.hitValue, e))); diff --git a/lib/src/layer/polyline_layer/painter.dart b/lib/src/layer/polyline_layer/painter.dart index 65b8e1c11..2203a7c3f 100644 --- a/lib/src/layer/polyline_layer/painter.dart +++ b/lib/src/layer/polyline_layer/painter.dart @@ -200,7 +200,7 @@ class _PolylinePainter extends CustomPainter { final borderRadius = (borderPaint?.strokeWidth ?? 0) / 2; if (isDotted) { - final spacing = strokeWidth * 1.5; + final spacing = strokeWidth * polyline.segmentSpacingFactor; if (borderPaint != null && filterPaint != null) { _paintDottedLine(borderPath, offsets, borderRadius, spacing); _paintDottedLine(filterPath, offsets, radius, spacing); diff --git a/lib/src/layer/polyline_layer/polyline.dart b/lib/src/layer/polyline_layer/polyline.dart index b96fd77e7..d56c491d7 100644 --- a/lib/src/layer/polyline_layer/polyline.dart +++ b/lib/src/layer/polyline_layer/polyline.dart @@ -8,6 +8,15 @@ class Polyline { /// The width of the stroke final double strokeWidth; + /// The multiplier used to calculate the spacing between segments in a dotted/ + /// dashed polyline + /// + /// A value of 1.0 will result in spacing equal to the `strokeWidth`. + /// Increasing the value increases the spacing with respect to `strokeWidth`. + /// + /// Defaults to 1.5. + final double segmentSpacingFactor; + /// The color of the line stroke. final Color color; @@ -58,6 +67,7 @@ class Polyline { this.strokeJoin = StrokeJoin.round, this.useStrokeWidthInMeter = false, this.hitValue, + this.segmentSpacingFactor = 1.5, }); @override @@ -69,6 +79,7 @@ class Polyline { borderStrokeWidth == other.borderStrokeWidth && borderColor == other.borderColor && isDotted == other.isDotted && + segmentSpacingFactor == other.segmentSpacingFactor && strokeCap == other.strokeCap && strokeJoin == other.strokeJoin && useStrokeWidthInMeter == other.useStrokeWidthInMeter && @@ -90,6 +101,7 @@ class Polyline { gradientColors, colorsStop, isDotted, + segmentSpacingFactor, strokeCap, strokeJoin, useStrokeWidthInMeter,