@@ -98,11 +98,15 @@ class PolygonLayer extends StatelessWidget {
98
98
// Turn on/off per-polygon label drawing on the layer-level.
99
99
final bool polygonLabels;
100
100
101
+ // Whether to draw labels last and thus over all the polygons.
102
+ final bool drawLabelsLast;
103
+
101
104
const PolygonLayer ({
102
105
super .key,
103
106
required this .polygons,
104
107
this .polygonCulling = false ,
105
108
this .polygonLabels = true ,
109
+ this .drawLabelsLast = false ,
106
110
});
107
111
108
112
@override
@@ -118,7 +122,7 @@ class PolygonLayer extends StatelessWidget {
118
122
119
123
return MobileLayerTransformer (
120
124
child: CustomPaint (
121
- painter: PolygonPainter (pgons, map, polygonLabels),
125
+ painter: PolygonPainter (pgons, map, polygonLabels, drawLabelsLast ),
122
126
size: size,
123
127
isComplex: true ,
124
128
),
@@ -131,8 +135,10 @@ class PolygonPainter extends CustomPainter {
131
135
final MapCamera map;
132
136
final LatLngBounds bounds;
133
137
final bool polygonLabels;
138
+ final bool drawLabelsLast;
134
139
135
- PolygonPainter (this .polygons, this .map, this .polygonLabels)
140
+ PolygonPainter (
141
+ this .polygons, this .map, this .polygonLabels, this .drawLabelsLast)
136
142
: bounds = map.visibleBounds;
137
143
138
144
int get hash {
@@ -235,7 +241,7 @@ class PolygonPainter extends CustomPainter {
235
241
}
236
242
}
237
243
238
- if (polygonLabels && polygon.label != null ) {
244
+ if (polygonLabels && ! drawLabelsLast && polygon.label != null ) {
239
245
// Labels are expensive because:
240
246
// * they themselves cannot easily be pulled into our batched path
241
247
// painting with the given text APIs
@@ -267,6 +273,31 @@ class PolygonPainter extends CustomPainter {
267
273
}
268
274
269
275
drawPaths ();
276
+
277
+ if (polygonLabels && drawLabelsLast) {
278
+ for (final polygon in polygons) {
279
+ final offsets = getOffsets (polygon.points);
280
+ if (offsets.isEmpty) {
281
+ continue ;
282
+ }
283
+
284
+ if (polygon.label != null ) {
285
+ final painter = buildLabelTextPainter (
286
+ polygon.points,
287
+ polygon.labelPosition,
288
+ placementPoint: map.getOffsetFromOrigin (polygon.labelPosition),
289
+ points: offsets,
290
+ labelText: polygon.label! ,
291
+ labelStyle: polygon.labelStyle,
292
+ rotationRad: map.rotationRad,
293
+ rotate: polygon.rotateLabel,
294
+ padding: 50 ,
295
+ );
296
+
297
+ painter? .call (canvas);
298
+ }
299
+ }
300
+ }
270
301
}
271
302
272
303
Paint _getBorderPaint (Polygon polygon) {
0 commit comments