2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ import 'package:collection/collection.dart' ;
5
6
import 'package:flutter/foundation.dart' show listEquals, VoidCallback;
6
7
import 'package:flutter/material.dart' show Color, Colors;
7
8
import 'package:meta/meta.dart' show immutable, required;
@@ -46,6 +47,7 @@ class Polygon {
46
47
this .fillColor = Colors .black,
47
48
this .geodesic = false ,
48
49
this .points = const < LatLng > [],
50
+ this .holes = const < List <LatLng >> [],
49
51
this .strokeColor = Colors .black,
50
52
this .strokeWidth = 10 ,
51
53
this .visible = true ,
@@ -77,6 +79,14 @@ class Polygon {
77
79
/// default; to form a closed polygon, the start and end points must be the same.
78
80
final List <LatLng > points;
79
81
82
+ /// To create an empty area within a polygon, you need to use holes.
83
+ /// To create the hole, the coordinates defining the hole path must be inside the polygon.
84
+ ///
85
+ /// The vertices of the holes to be cut out of polygon.
86
+ ///
87
+ /// Line segments of each points of hole are drawn inside polygon between consecutive hole points.
88
+ final List <List <LatLng >> holes;
89
+
80
90
/// True if the marker is visible.
81
91
final bool visible;
82
92
@@ -106,6 +116,7 @@ class Polygon {
106
116
Color fillColorParam,
107
117
bool geodesicParam,
108
118
List <LatLng > pointsParam,
119
+ List <List <LatLng >> holesParam,
109
120
Color strokeColorParam,
110
121
int strokeWidthParam,
111
122
bool visibleParam,
@@ -118,6 +129,7 @@ class Polygon {
118
129
fillColor: fillColorParam ?? fillColor,
119
130
geodesic: geodesicParam ?? geodesic,
120
131
points: pointsParam ?? points,
132
+ holes: holesParam ?? holes,
121
133
strokeColor: strokeColorParam ?? strokeColor,
122
134
strokeWidth: strokeWidthParam ?? strokeWidth,
123
135
visible: visibleParam ?? visible,
@@ -154,6 +166,10 @@ class Polygon {
154
166
json['points' ] = _pointsToJson ();
155
167
}
156
168
169
+ if (holes != null ) {
170
+ json['holes' ] = _holesToJson ();
171
+ }
172
+
157
173
return json;
158
174
}
159
175
@@ -167,6 +183,7 @@ class Polygon {
167
183
fillColor == typedOther.fillColor &&
168
184
geodesic == typedOther.geodesic &&
169
185
listEquals (points, typedOther.points) &&
186
+ DeepCollectionEquality ().equals (holes, typedOther.holes) &&
170
187
visible == typedOther.visible &&
171
188
strokeColor == typedOther.strokeColor &&
172
189
strokeWidth == typedOther.strokeWidth &&
@@ -183,4 +200,16 @@ class Polygon {
183
200
}
184
201
return result;
185
202
}
203
+
204
+ List <List <dynamic >> _holesToJson () {
205
+ final List <List <dynamic >> result = < List <dynamic >> [];
206
+ for (final List <LatLng > hole in holes) {
207
+ final List <dynamic > jsonHole = < dynamic > [];
208
+ for (final LatLng point in hole) {
209
+ jsonHole.add (point.toJson ());
210
+ }
211
+ result.add (jsonHole);
212
+ }
213
+ return result;
214
+ }
186
215
}
0 commit comments