From 190ae33e3a8813c2396f7dcadb83d8808b11c9df Mon Sep 17 00:00:00 2001 From: Aleksandr Yurkovskiy Date: Sat, 10 Oct 2020 14:21:47 +0300 Subject: [PATCH 1/4] Adds support for holes in polygon overlays to the Google Maps plugin platform interface --- .../lib/src/types/polygon.dart | 29 +++++++++++++++++++ .../pubspec.yaml | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) 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 3b5e25060faf..96b39157418d 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 @@ class Polygon { this.fillColor = Colors.black, this.geodesic = false, this.points = const [], + this.holes = const >[], this.strokeColor = Colors.black, this.strokeWidth = 10, this.visible = true, @@ -77,6 +79,14 @@ class Polygon { /// default; to form a closed polygon, the start and end points must be the same. final List 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> holes; + /// True if the marker is visible. final bool visible; @@ -106,6 +116,7 @@ class Polygon { Color fillColorParam, bool geodesicParam, List pointsParam, + List> holesParam, Color strokeColorParam, int strokeWidthParam, bool visibleParam, @@ -118,6 +129,7 @@ class Polygon { 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 @@ class Polygon { json['points'] = _pointsToJson(); } + if (holes != null) { + json['holes'] = _holesToJson(); + } + return json; } @@ -167,6 +183,7 @@ class Polygon { 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 @@ class Polygon { } return result; } + + List> _holesToJson() { + final List> result = >[]; + for (final List hole in holes) { + final List jsonHole = []; + 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 fd3a1c434960..3f46cf0c2a6b 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 @@ description: A common platform interface for the google_maps_flutter plugin. 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.4 +version: 1.0.5 dependencies: flutter: @@ -11,6 +11,7 @@ dependencies: meta: ^1.0.5 plugin_platform_interface: ^1.0.1 stream_transform: ^1.2.0 + collection: ^1.14.13 dev_dependencies: flutter_test: From 4c01e2ec819ee8e648457d17fa59bdb73350edcd Mon Sep 17 00:00:00 2001 From: Aleksandr Yurkovskiy Date: Sat, 10 Oct 2020 14:34:59 +0300 Subject: [PATCH 2/4] change changelog and authors --- AUTHORS | 2 ++ .../google_maps_flutter_platform_interface/CHANGELOG.md | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/AUTHORS b/AUTHORS index 51345c9a3481..23da94189538 100644 --- a/AUTHORS +++ b/AUTHORS @@ -59,3 +59,5 @@ Kazuki Yamaguchi Eitan Schwartz Chris Rutkowski Juan Alvarez +Aleksandr Yurkovskiy + 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 dc8eddf8b557..e8344ce9a7c2 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.0.5 + +* Add support for holes in Polygons. + ## 1.0.4 * Add a `dispose` method to the interface, so implementations may cleanup resources acquired on `init`. From 8412e1f4ba3fb77feb8d287733c313afc0e1ca1e Mon Sep 17 00:00:00 2001 From: Aleksandr Yurkovskiy Date: Fri, 16 Oct 2020 19:45:34 +0300 Subject: [PATCH 3/4] remove extra line --- AUTHORS | 1 - 1 file changed, 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 23da94189538..09bab9d34d02 100644 --- a/AUTHORS +++ b/AUTHORS @@ -60,4 +60,3 @@ Eitan Schwartz Chris Rutkowski Juan Alvarez Aleksandr Yurkovskiy - From 4bff7ad87099936628b7ac20a7813d6e6337c603 Mon Sep 17 00:00:00 2001 From: Aleksandr Yurkovskiy Date: Fri, 16 Oct 2020 19:46:30 +0300 Subject: [PATCH 4/4] fix version from 1.0.5 to 1.1.0 --- .../google_maps_flutter_platform_interface/CHANGELOG.md | 2 +- .../google_maps_flutter_platform_interface/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 e8344ce9a7c2..2e7bdfb06751 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,4 +1,4 @@ -## 1.0.5 +## 1.1.0 * Add support for holes in Polygons. 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 3f46cf0c2a6b..cea6ebc9168c 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 @@ description: A common platform interface for the google_maps_flutter plugin. 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.5 +version: 1.1.0 dependencies: flutter: