[google_maps_flutter_platform_interface] Adds support for holes in polygon overlays to the Google Maps plugin (#3135)
diff --git a/AUTHORS b/AUTHORS
index 51345c9..09bab9d 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -59,3 +59,4 @@
Eitan Schwartz <eshvartz@gmail.com>
Chris Rutkowski <chrisrutkowski89@gmail.com>
Juan Alvarez <juan.alvarez@resideo.com>
+Aleksandr Yurkovskiy <sanekyy@gmail.com>
diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md
index b40fc9d..1e76168 100644
--- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md
+++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.1.0
+
+* Add support for holes in Polygons.
+
## 1.0.6
* Update Flutter SDK constraint.
diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart
index 3b5e250..96b3915 100644
--- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart
+++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/polygon.dart
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart' show listEquals, VoidCallback;
import 'package:flutter/material.dart' show Color, Colors;
import 'package:meta/meta.dart' show immutable, required;
@@ -46,6 +47,7 @@
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,
@@ -77,6 +79,14 @@
/// default; to form a closed polygon, the start and end points must be the same.
final List<LatLng> points;
+ /// To create an empty area within a polygon, you need to use holes.
+ /// To create the hole, the coordinates defining the hole path must be inside the polygon.
+ ///
+ /// 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.
+ final List<List<LatLng>> holes;
+
/// True if the marker is visible.
final bool visible;
@@ -106,6 +116,7 @@
Color fillColorParam,
bool geodesicParam,
List<LatLng> pointsParam,
+ List<List<LatLng>> holesParam,
Color strokeColorParam,
int strokeWidthParam,
bool visibleParam,
@@ -118,6 +129,7 @@
fillColor: fillColorParam ?? fillColor,
geodesic: geodesicParam ?? geodesic,
points: pointsParam ?? points,
+ holes: holesParam ?? holes,
strokeColor: strokeColorParam ?? strokeColor,
strokeWidth: strokeWidthParam ?? strokeWidth,
visible: visibleParam ?? visible,
@@ -154,6 +166,10 @@
json['points'] = _pointsToJson();
}
+ if (holes != null) {
+ json['holes'] = _holesToJson();
+ }
+
return json;
}
@@ -167,6 +183,7 @@
fillColor == typedOther.fillColor &&
geodesic == typedOther.geodesic &&
listEquals(points, typedOther.points) &&
+ DeepCollectionEquality().equals(holes, typedOther.holes) &&
visible == typedOther.visible &&
strokeColor == typedOther.strokeColor &&
strokeWidth == typedOther.strokeWidth &&
@@ -183,4 +200,16 @@
}
return result;
}
+
+ List<List<dynamic>> _holesToJson() {
+ final List<List<dynamic>> result = <List<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;
+ }
}
diff --git a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml
index 633478c..d8b260a 100644
--- a/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml
+++ b/packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml
@@ -3,7 +3,7 @@
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
-version: 1.0.6
+version: 1.1.0
dependencies:
flutter:
@@ -11,6 +11,7 @@
meta: ^1.0.5
plugin_platform_interface: ^1.0.1
stream_transform: ^1.2.0
+ collection: ^1.14.13
dev_dependencies:
flutter_test: