Skip to content

Commit

Permalink
possible fix for fleaflet#1510
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrierley committed May 11, 2023
1 parent 578bda0 commit 6c3244f
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions lib/src/layer/polyline_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ class PolylineLayer extends StatelessWidget {
final bool saveLayers;

const PolylineLayer({
super.key,
this.polylines = const [],
this.polylineCulling = false,
this.saveLayers = false,
super.key,
this.polylines = const [],
this.polylineCulling = false,
this.saveLayers = false,
});

@override
Expand All @@ -82,8 +82,8 @@ class PolylineLayer extends StatelessWidget {

final List<Polyline> lines = polylineCulling
? polylines.where((p) {
return p.boundingBox.isOverlapping(map.bounds);
}).toList()
return p.boundingBox.isOverlapping(map.bounds);
}).toList()
: polylines;

return CustomPaint(
Expand Down Expand Up @@ -141,9 +141,7 @@ class PolylinePainter extends CustomPainter {
int? lastHash;

void drawPaths() {
canvas.drawPath(path, paint);
path = ui.Path();
paint = Paint();
if (saveLayers) canvas.saveLayer(rect, Paint());

if (borderPaint != null) {
canvas.drawPath(borderPath, borderPaint!);
Expand All @@ -156,6 +154,12 @@ class PolylinePainter extends CustomPainter {
filterPath = ui.Path();
filterPaint = null;
}

canvas.drawPath(path, paint);
path = ui.Path();
paint = Paint();

if (saveLayers) canvas.restore();
}

for (final polyline in polylines) {
Expand All @@ -165,7 +169,7 @@ class PolylinePainter extends CustomPainter {
}

final hash = polyline.renderHashCode;
if (lastHash != null && lastHash != hash) {
if (saveLayers || (lastHash != null && lastHash != hash)) {
drawPaths();
}
lastHash = hash;
Expand Down Expand Up @@ -225,7 +229,6 @@ class PolylinePainter extends CustomPainter {
final radius = paint.strokeWidth / 2;
final borderRadius = (borderPaint?.strokeWidth ?? 0) / 2;

if (saveLayers) canvas.saveLayer(rect, Paint());
if (isDotted) {
final spacing = strokeWidth * 1.5;
if (borderPaint != null && filterPaint != null) {
Expand All @@ -240,7 +243,6 @@ class PolylinePainter extends CustomPainter {
}
_paintLine(path, offsets);
}
if (saveLayers) canvas.restore();
}

drawPaths();
Expand Down Expand Up @@ -281,16 +283,16 @@ class PolylinePainter extends CustomPainter {

List<double>? _getColorsStop(Polyline polyline) =>
(polyline.colorsStop != null &&
polyline.colorsStop!.length == polyline.gradientColors!.length)
polyline.colorsStop!.length == polyline.gradientColors!.length)
? polyline.colorsStop
: _calculateColorsStop(polyline);

List<double> _calculateColorsStop(Polyline polyline) {
final colorsStopInterval = 1.0 / polyline.gradientColors!.length;
return polyline.gradientColors!
.map((gradientColor) =>
polyline.gradientColors!.indexOf(gradientColor) *
colorsStopInterval)
polyline.gradientColors!.indexOf(gradientColor) *
colorsStopInterval)
.toList();
}

Expand All @@ -301,4 +303,4 @@ class PolylinePainter extends CustomPainter {
oldDelegate.polylines.length != polylines.length ||
oldDelegate.hash != hash;
}
}
}

0 comments on commit 6c3244f

Please sign in to comment.