Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit a0e7937

Browse files
authored
[google_maps_flutter_platform_interface] Adds support for holes in polygon overlays to the Google Maps plugin (#3135)
1 parent 71a8317 commit a0e7937

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ Kazuki Yamaguchi <[email protected]>
5959
Eitan Schwartz <[email protected]>
6060
Chris Rutkowski <[email protected]>
6161
Juan Alvarez <[email protected]>
62+
Aleksandr Yurkovskiy <[email protected]>

packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.0
2+
3+
* Add support for holes in Polygons.
4+
15
## 1.0.6
26

37
* Update Flutter SDK constraint.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:collection/collection.dart';
56
import 'package:flutter/foundation.dart' show listEquals, VoidCallback;
67
import 'package:flutter/material.dart' show Color, Colors;
78
import 'package:meta/meta.dart' show immutable, required;
@@ -46,6 +47,7 @@ class Polygon {
4647
this.fillColor = Colors.black,
4748
this.geodesic = false,
4849
this.points = const <LatLng>[],
50+
this.holes = const <List<LatLng>>[],
4951
this.strokeColor = Colors.black,
5052
this.strokeWidth = 10,
5153
this.visible = true,
@@ -77,6 +79,14 @@ class Polygon {
7779
/// default; to form a closed polygon, the start and end points must be the same.
7880
final List<LatLng> points;
7981

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+
8090
/// True if the marker is visible.
8191
final bool visible;
8292

@@ -106,6 +116,7 @@ class Polygon {
106116
Color fillColorParam,
107117
bool geodesicParam,
108118
List<LatLng> pointsParam,
119+
List<List<LatLng>> holesParam,
109120
Color strokeColorParam,
110121
int strokeWidthParam,
111122
bool visibleParam,
@@ -118,6 +129,7 @@ class Polygon {
118129
fillColor: fillColorParam ?? fillColor,
119130
geodesic: geodesicParam ?? geodesic,
120131
points: pointsParam ?? points,
132+
holes: holesParam ?? holes,
121133
strokeColor: strokeColorParam ?? strokeColor,
122134
strokeWidth: strokeWidthParam ?? strokeWidth,
123135
visible: visibleParam ?? visible,
@@ -154,6 +166,10 @@ class Polygon {
154166
json['points'] = _pointsToJson();
155167
}
156168

169+
if (holes != null) {
170+
json['holes'] = _holesToJson();
171+
}
172+
157173
return json;
158174
}
159175

@@ -167,6 +183,7 @@ class Polygon {
167183
fillColor == typedOther.fillColor &&
168184
geodesic == typedOther.geodesic &&
169185
listEquals(points, typedOther.points) &&
186+
DeepCollectionEquality().equals(holes, typedOther.holes) &&
170187
visible == typedOther.visible &&
171188
strokeColor == typedOther.strokeColor &&
172189
strokeWidth == typedOther.strokeWidth &&
@@ -183,4 +200,16 @@ class Polygon {
183200
}
184201
return result;
185202
}
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+
}
186215
}

packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ description: A common platform interface for the google_maps_flutter plugin.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 1.0.6
6+
version: 1.1.0
77

88
dependencies:
99
flutter:
1010
sdk: flutter
1111
meta: ^1.0.5
1212
plugin_platform_interface: ^1.0.1
1313
stream_transform: ^1.2.0
14+
collection: ^1.14.13
1415

1516
dev_dependencies:
1617
flutter_test:

0 commit comments

Comments
 (0)