Skip to content

Commit 6c3244f

Browse files
committed
possible fix for fleaflet#1510
1 parent 578bda0 commit 6c3244f

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

lib/src/layer/polyline_layer.dart

+18-16
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ class PolylineLayer extends StatelessWidget {
6969
final bool saveLayers;
7070

7171
const PolylineLayer({
72-
super.key,
73-
this.polylines = const [],
74-
this.polylineCulling = false,
75-
this.saveLayers = false,
72+
super.key,
73+
this.polylines = const [],
74+
this.polylineCulling = false,
75+
this.saveLayers = false,
7676
});
7777

7878
@override
@@ -82,8 +82,8 @@ class PolylineLayer extends StatelessWidget {
8282

8383
final List<Polyline> lines = polylineCulling
8484
? polylines.where((p) {
85-
return p.boundingBox.isOverlapping(map.bounds);
86-
}).toList()
85+
return p.boundingBox.isOverlapping(map.bounds);
86+
}).toList()
8787
: polylines;
8888

8989
return CustomPaint(
@@ -141,9 +141,7 @@ class PolylinePainter extends CustomPainter {
141141
int? lastHash;
142142

143143
void drawPaths() {
144-
canvas.drawPath(path, paint);
145-
path = ui.Path();
146-
paint = Paint();
144+
if (saveLayers) canvas.saveLayer(rect, Paint());
147145

148146
if (borderPaint != null) {
149147
canvas.drawPath(borderPath, borderPaint!);
@@ -156,6 +154,12 @@ class PolylinePainter extends CustomPainter {
156154
filterPath = ui.Path();
157155
filterPaint = null;
158156
}
157+
158+
canvas.drawPath(path, paint);
159+
path = ui.Path();
160+
paint = Paint();
161+
162+
if (saveLayers) canvas.restore();
159163
}
160164

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

167171
final hash = polyline.renderHashCode;
168-
if (lastHash != null && lastHash != hash) {
172+
if (saveLayers || (lastHash != null && lastHash != hash)) {
169173
drawPaths();
170174
}
171175
lastHash = hash;
@@ -225,7 +229,6 @@ class PolylinePainter extends CustomPainter {
225229
final radius = paint.strokeWidth / 2;
226230
final borderRadius = (borderPaint?.strokeWidth ?? 0) / 2;
227231

228-
if (saveLayers) canvas.saveLayer(rect, Paint());
229232
if (isDotted) {
230233
final spacing = strokeWidth * 1.5;
231234
if (borderPaint != null && filterPaint != null) {
@@ -240,7 +243,6 @@ class PolylinePainter extends CustomPainter {
240243
}
241244
_paintLine(path, offsets);
242245
}
243-
if (saveLayers) canvas.restore();
244246
}
245247

246248
drawPaths();
@@ -281,16 +283,16 @@ class PolylinePainter extends CustomPainter {
281283

282284
List<double>? _getColorsStop(Polyline polyline) =>
283285
(polyline.colorsStop != null &&
284-
polyline.colorsStop!.length == polyline.gradientColors!.length)
286+
polyline.colorsStop!.length == polyline.gradientColors!.length)
285287
? polyline.colorsStop
286288
: _calculateColorsStop(polyline);
287289

288290
List<double> _calculateColorsStop(Polyline polyline) {
289291
final colorsStopInterval = 1.0 / polyline.gradientColors!.length;
290292
return polyline.gradientColors!
291293
.map((gradientColor) =>
292-
polyline.gradientColors!.indexOf(gradientColor) *
293-
colorsStopInterval)
294+
polyline.gradientColors!.indexOf(gradientColor) *
295+
colorsStopInterval)
294296
.toList();
295297
}
296298

@@ -301,4 +303,4 @@ class PolylinePainter extends CustomPainter {
301303
oldDelegate.polylines.length != polylines.length ||
302304
oldDelegate.hash != hash;
303305
}
304-
}
306+
}

0 commit comments

Comments
 (0)