@@ -19,6 +19,7 @@ class Polyline {
19
19
final bool isDotted;
20
20
final StrokeCap strokeCap;
21
21
final StrokeJoin strokeJoin;
22
+ final bool useStrokeWidthInMeter;
22
23
late LatLngBounds boundingBox;
23
24
24
25
Polyline ({
@@ -33,6 +34,7 @@ class Polyline {
33
34
this .isDotted = false ,
34
35
this .strokeCap = StrokeCap .round,
35
36
this .strokeJoin = StrokeJoin .round,
37
+ this .useStrokeWidthInMeter = false ,
36
38
});
37
39
}
38
40
@@ -68,6 +70,7 @@ class PolylineLayer extends StatelessWidget {
68
70
@override
69
71
Widget build (BuildContext context) {
70
72
final map = FlutterMapState .maybeOf (context)! ;
73
+
71
74
return LayoutBuilder (
72
75
builder: (BuildContext context, BoxConstraints bc) {
73
76
final size = Size (bc.maxWidth, bc.maxHeight);
@@ -87,7 +90,7 @@ class PolylineLayer extends StatelessWidget {
87
90
polylineWidgets.add (
88
91
CustomPaint (
89
92
key: polylineOpt.key,
90
- painter: PolylinePainter (polylineOpt, saveLayers),
93
+ painter: PolylinePainter (polylineOpt, saveLayers, map ),
91
94
size: size,
92
95
),
93
96
);
@@ -123,17 +126,36 @@ class PolylinePainter extends CustomPainter {
123
126
/// {@endtemplate}
124
127
final bool saveLayers;
125
128
126
- PolylinePainter (this .polylineOpt, this .saveLayers);
129
+ final FlutterMapState map;
130
+
131
+ PolylinePainter (this .polylineOpt, this .saveLayers, this .map);
127
132
128
133
@override
129
134
void paint (Canvas canvas, Size size) {
130
135
if (polylineOpt.offsets.isEmpty) {
131
136
return ;
132
137
}
138
+
133
139
final rect = Offset .zero & size;
134
140
canvas.clipRect (rect);
141
+
142
+ late final double strokeWidth;
143
+ if (polylineOpt.useStrokeWidthInMeter) {
144
+ final firstPoint = polylineOpt.points.first;
145
+ final firstOffset = polylineOpt.offsets.first;
146
+ final r = const Distance ().offset (
147
+ firstPoint,
148
+ polylineOpt.strokeWidth,
149
+ 180 ,
150
+ );
151
+ final delta = firstOffset - map.getOffsetFromOrigin (r);
152
+
153
+ strokeWidth = delta.distance;
154
+ } else {
155
+ strokeWidth = polylineOpt.strokeWidth;
156
+ }
135
157
final paint = Paint ()
136
- ..strokeWidth = polylineOpt. strokeWidth
158
+ ..strokeWidth = strokeWidth
137
159
..strokeCap = polylineOpt.strokeCap
138
160
..strokeJoin = polylineOpt.strokeJoin
139
161
..blendMode = BlendMode .srcOver;
@@ -150,7 +172,7 @@ class PolylinePainter extends CustomPainter {
150
172
if (polylineOpt.borderColor != null ) {
151
173
filterPaint = Paint ()
152
174
..color = polylineOpt.borderColor! .withAlpha (255 )
153
- ..strokeWidth = polylineOpt. strokeWidth
175
+ ..strokeWidth = strokeWidth
154
176
..strokeCap = polylineOpt.strokeCap
155
177
..strokeJoin = polylineOpt.strokeJoin
156
178
..blendMode = BlendMode .dstOut;
@@ -159,16 +181,15 @@ class PolylinePainter extends CustomPainter {
159
181
final borderPaint = polylineOpt.borderStrokeWidth > 0.0
160
182
? (Paint ()
161
183
..color = polylineOpt.borderColor ?? const Color (0x00000000 )
162
- ..strokeWidth =
163
- polylineOpt.strokeWidth + polylineOpt.borderStrokeWidth
184
+ ..strokeWidth = strokeWidth + polylineOpt.borderStrokeWidth
164
185
..strokeCap = polylineOpt.strokeCap
165
186
..strokeJoin = polylineOpt.strokeJoin
166
187
..blendMode = BlendMode .srcOver)
167
188
: null ;
168
189
final radius = paint.strokeWidth / 2 ;
169
190
final borderRadius = (borderPaint? .strokeWidth ?? 0 ) / 2 ;
170
191
if (polylineOpt.isDotted) {
171
- final spacing = polylineOpt. strokeWidth * 1.5 ;
192
+ final spacing = strokeWidth * 1.5 ;
172
193
if (saveLayers) canvas.saveLayer (rect, Paint ());
173
194
if (borderPaint != null && filterPaint != null ) {
174
195
_paintDottedLine (
0 commit comments