-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[google_maps_flutter] Adds support for holes in polygon overlays to the Google Maps plugin #1721
Changes from 21 commits
76d56ca
8826721
9252dc4
a4eeab5
1b26908
01bd55c
69d3889
18137c2
a86e25f
e866736
0d404b4
32ee443
71c45b5
4f24a58
5233c0d
a952a34
1faf0d4
b4ae7bf
49d08b3
b526132
2d55631
7871f33
185f67b
14136d5
4283ce0
af1c9b0
0461f32
13dd5cf
c563086
2516df5
38ca9e9
df66101
c515201
47e5f60
6b970c8
1b2c8ef
cfd96b6
d2c06dc
d377276
17b0e6f
9f83f73
dd9e6e5
8d3d94f
c69d178
0d2a84c
aa140a0
a603d00
1496272
63cbca9
2a8837d
fedafd7
33e926e
4553a61
6ef0253
f4673a3
b082a41
9dea297
9802260
7a9b266
febcd31
a5e6a5c
d1480e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.5.21 | ||
|
||
* Add support for holes in Polygons | ||
|
||
## 0.5.20 | ||
|
||
* Add map toolbar support | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ class Polygon { | |
this.fillColor = Colors.black, | ||
this.geodesic = false, | ||
this.points = const <LatLng>[], | ||
this.holes = const <List<LatLng>>[], | ||
this.strokeColor = Colors.black, | ||
this.strokeWidth = 10, | ||
this.visible = true, | ||
|
@@ -67,6 +68,11 @@ class Polygon { | |
/// default; to form a closed polygon, the start and end points must be the same. | ||
final List<LatLng> points; | ||
|
||
/// The vertices of the holes to be cut out of polygon. | ||
/// | ||
/// Line segments of each points of hole are drawn inside polygon between consecutive hole points. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional documentation as to what a hole is would be helpful. Also something about the sequence in which the lat lngs are supposed to be input. Something along the lines of: To create an empty area within a polygon, you need to create two paths, one inside the other. To create the hole, the coordinates defining the inner path must be in the opposite order to those defining the outer path. For example, if the coordinates of the outer path are in clockwise order then the inner path must be counter-clockwise. I copied it over from https://developers.google.com/maps/documentation/javascript/shapes#polygon_hole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
final List<List<LatLng>> holes; | ||
|
||
/// True if the marker is visible. | ||
final bool visible; | ||
|
||
|
@@ -96,6 +102,7 @@ class Polygon { | |
Color fillColorParam, | ||
bool geodesicParam, | ||
List<LatLng> pointsParam, | ||
List<List<LatLng>> holesParam, | ||
Color strokeColorParam, | ||
int strokeWidthParam, | ||
bool visibleParam, | ||
|
@@ -108,6 +115,7 @@ class Polygon { | |
fillColor: fillColorParam ?? fillColor, | ||
geodesic: geodesicParam ?? geodesic, | ||
points: pointsParam ?? points, | ||
holes: holesParam ?? holes, | ||
strokeColor: strokeColorParam ?? strokeColor, | ||
strokeWidth: strokeWidthParam ?? strokeWidth, | ||
visible: visibleParam ?? visible, | ||
|
@@ -138,6 +146,10 @@ class Polygon { | |
json['points'] = _pointsToJson(); | ||
} | ||
|
||
if (holes != null) { | ||
json['holes'] = _holesToJson(); | ||
} | ||
|
||
return json; | ||
} | ||
|
||
|
@@ -159,6 +171,18 @@ class Polygon { | |
} | ||
return result; | ||
} | ||
|
||
dynamic _holesToJson() { | ||
final List<dynamic> result = <dynamic>[]; | ||
for (final List<LatLng> hole in holes) { | ||
final List<dynamic> jsonHole = <dynamic>[]; | ||
for (final LatLng point in hole) { | ||
jsonHole.add(point._toJson()); | ||
} | ||
result.add(jsonHole); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
Map<PolygonId, Polygon> _keyByPolygonId(Iterable<Polygon> polygons) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the holes lie outside the polygon? does the google maps api throw some error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation from https://developers.google.com/maps/documentation/android-sdk/shapes:
If the hole intersects the outline of the polygon, the polygon will be rendered without any fill.