From a2d607ead56ee87bc872851570d1fea85015f937 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 13 Jan 2021 11:10:52 +0100 Subject: [PATCH 01/15] Support Holes in Polygon --- .../lib/src/convert.dart | 13 ++++++++-- .../google_maps_flutter_web/pubspec.yaml | 2 +- .../test/test_driver/shapes_integration.dart | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart index 551c1572b1bb..2a69fbeec77d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart @@ -366,6 +366,11 @@ Set _rawOptionsToInitialPolygons(Map rawOptions) { points: rawPolygon['points'] ?.map((rawPoint) => LatLng.fromJson(rawPoint)) ?.toList(), + holes: rawPolygon['holes'] + ?.map>((List hole) => hole + ?.map((rawPoint) => LatLng.fromJson(rawPoint)) + ?.toList()) + ?.toList(), ); }) ?? []); @@ -473,9 +478,13 @@ gmaps.CircleOptions _circleOptionsFromCircle(Circle circle) { gmaps.PolygonOptions _polygonOptionsFromPolygon( gmaps.GMap googleMap, Polygon polygon) { - List paths = []; + List path = []; polygon.points.forEach((point) { - paths.add(_latLngToGmLatLng(point)); + path.add(_latLngToGmLatLng(point)); + }); + List> paths = [path]; + polygon.holes?.forEach((hole) { + paths.add(hole.map((point) => _latLngToGmLatLng(point)).toList()); }); return gmaps.PolygonOptions() ..paths = paths diff --git a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml index b41e24c25357..e052ca19fb0a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: flutter_web_plugins: sdk: flutter meta: ^1.1.7 - google_maps_flutter_platform_interface: ^1.0.5 + google_maps_flutter_platform_interface: ^1.1.0 google_maps: ^3.4.5 stream_transform: ^1.2.0 sanitize_html: ^1.4.1 diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart index 0c92c6a924e7..24809cce1258 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart @@ -190,6 +190,30 @@ void main() { expect(polygon.get('strokeColor'), '#c0ffee'); expect(polygon.get('strokeOpacity'), closeTo(1, _acceptableDelta)); }); + + testWidgets('Handle Polygons with holes', (WidgetTester tester) async { + final polygons = { + Polygon( + polygonId: PolygonId('BermudaTriangle'), + points: [LatLng(25.774, -80.19), + LatLng(18.466, -66.118), + LatLng(32.321, -64.757),], + holes: [ + [ + LatLng(28.745, -70.579 ), + LatLng(29.57, -67.514 ), + LatLng(27.339, -66.668 ), + ], + ], + ), + }; + + controller.addPolygons(polygons); + + expect(controller.polygons.length, 1); + expect(controller.polygons, contains(PolygonId('BermudaTriangle'))); + expect(controller.polygons, isNot(contains(PolygonId('66')))); + }); }); group('PolylinesController', () { From 6616ea3685cab18494d1ee28d80b62cbe036b473 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 13 Jan 2021 11:14:27 +0100 Subject: [PATCH 02/15] Update Version & Changelog --- .../google_maps_flutter/google_maps_flutter_web/CHANGELOG.md | 5 +++++ .../google_maps_flutter/google_maps_flutter_web/pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md index 2d03ab254bc0..940419a215fc 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.1.0+10 + +* Update `package:google_maps_flutter_platform_interface` to `^1.1.0`. +* Add support for Polygon Holes. + ## 0.1.0+9 * Update Flutter SDK constraint. diff --git a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml index e052ca19fb0a..bd879553a06d 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -1,7 +1,7 @@ name: google_maps_flutter_web description: Web platform implementation of google_maps_flutter homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter -version: 0.1.0+9 +version: 0.1.0+10 flutter: plugin: From c6293e561405d43f8ac786781179164b65829d50 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 13 Jan 2021 11:20:24 +0100 Subject: [PATCH 03/15] Add to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 09bab9d34d02..dabc20108f28 100644 --- a/AUTHORS +++ b/AUTHORS @@ -60,3 +60,4 @@ Eitan Schwartz Chris Rutkowski Juan Alvarez Aleksandr Yurkovskiy +Anton Borries \ No newline at end of file From ac6cabd81f27945b4f8b6fcef0c63610b821b27f Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Wed, 13 Jan 2021 11:44:00 +0100 Subject: [PATCH 04/15] Formatting --- .../lib/src/convert.dart | 4 ++-- .../test/test_driver/shapes_integration.dart | 22 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart index 2a69fbeec77d..c9fd1cd55d3b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart @@ -368,8 +368,8 @@ Set _rawOptionsToInitialPolygons(Map rawOptions) { ?.toList(), holes: rawPolygon['holes'] ?.map>((List hole) => hole - ?.map((rawPoint) => LatLng.fromJson(rawPoint)) - ?.toList()) + ?.map((rawPoint) => LatLng.fromJson(rawPoint)) + ?.toList()) ?.toList(), ); }) ?? diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart index 24809cce1258..d4c416ae05f3 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart @@ -194,17 +194,19 @@ void main() { testWidgets('Handle Polygons with holes', (WidgetTester tester) async { final polygons = { Polygon( - polygonId: PolygonId('BermudaTriangle'), - points: [LatLng(25.774, -80.19), - LatLng(18.466, -66.118), - LatLng(32.321, -64.757),], - holes: [ - [ - LatLng(28.745, -70.579 ), - LatLng(29.57, -67.514 ), - LatLng(27.339, -66.668 ), - ], + polygonId: PolygonId('BermudaTriangle'), + points: [ + LatLng(25.774, -80.19), + LatLng(18.466, -66.118), + LatLng(32.321, -64.757), + ], + holes: [ + [ + LatLng(28.745, -70.579), + LatLng(29.57, -67.514), + LatLng(27.339, -66.668), ], + ], ), }; From 50b418843cc74de293b2d459461a6b9776511a0e Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Thu, 14 Jan 2021 09:30:47 +0100 Subject: [PATCH 05/15] Add Test for initial geometry --- .../google_maps_controller_integration.dart | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart index 70d4452e411f..302057f0ea57 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/google_maps_controller_integration.dart @@ -166,6 +166,22 @@ void main() { [43.354762, -5.850824], ], }, + { + 'polygonId': 'polygon-2-with-holes', + 'points': [ + [43.355114, -5.851333], + [43.354797, -5.851860], + [43.354469, -5.851318], + [43.354762, -5.850824], + ], + 'holes': [ + [ + [41.354797, -6.851860], + [41.354469, -6.851318], + [41.354762, -6.850824], + ] + ] + }, ], 'polylinesToAdd': [ { @@ -202,6 +218,9 @@ void main() { expect(capturedMarkers.first.infoWindow.snippet, 'snippet for test'); expect(capturedMarkers.first.infoWindow.title, 'title for test'); expect(capturedPolygons.first.polygonId.value, 'polygon-1'); + expect(capturedPolygons.elementAt(1).polygonId.value, + 'polygon-2-with-holes'); + expect(capturedPolygons.elementAt(1).holes, isNot(null)); expect(capturedPolylines.first.polylineId.value, 'polyline-1'); }); From dc20c0084b5b11dd4d504125ca1ac1cdc26b8daf Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Thu, 14 Jan 2021 10:13:30 +0100 Subject: [PATCH 06/15] Add Test for Poly.containsLocation --- .../test/test_driver/shape_integration.dart | 26 +++++++++++++++++++ .../test/web/index.html | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart index b1a691d18def..487f02acbaee 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart @@ -8,7 +8,10 @@ import 'dart:async'; import 'package:integration_test/integration_test.dart'; import 'package:google_maps/google_maps.dart' as gmaps; +import 'package:google_maps/google_maps_geometry.dart' as geometry; import 'package:google_maps_flutter_web/google_maps_flutter_web.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart' + as interface; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; @@ -87,6 +90,29 @@ void main() { controller.update(options); verify(polygon.options = options); }); + + test('Polygon with hole has a hole', () { + final holedPolygon = interface.Polygon( + polygonId: interface.PolygonId('BermudaTriangle'), + points: [ + interface.LatLng(25.774, -80.19), + interface.LatLng(18.466, -66.118), + interface.LatLng(32.321, -64.757), + ], + holes: [ + [ + interface.LatLng(28.745, -70.579), + interface.LatLng(29.57, -67.514), + interface.LatLng(27.339, -66.668), + ], + ], + ); + final controller = PolygonsController(stream: null) + ..addPolygons({holedPolygon}); + final gmapsPolygon = controller.polygons.values.first.polygon; + final pointInHole = gmaps.LatLng(28.632, -68.401); + expect(geometry.poly.containsLocation(pointInHole, gmapsPolygon), false); + }); }); group('PolylineController', () { diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/web/index.html b/packages/google_maps_flutter/google_maps_flutter_web/test/web/index.html index 3b7e4edc3df1..03feba172d74 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/web/index.html +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/web/index.html @@ -5,7 +5,7 @@ Browser Tests - + From e5e6c6b7bd56b544b7337c79de099319d672eac9 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Thu, 14 Jan 2021 12:50:23 +0100 Subject: [PATCH 07/15] Rename import --- .../test/test_driver/shape_integration.dart | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart index 487f02acbaee..fc12e1caeaa3 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart @@ -11,7 +11,7 @@ import 'package:google_maps/google_maps.dart' as gmaps; import 'package:google_maps/google_maps_geometry.dart' as geometry; import 'package:google_maps_flutter_web/google_maps_flutter_web.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart' - as interface; + as platform; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; @@ -92,18 +92,18 @@ void main() { }); test('Polygon with hole has a hole', () { - final holedPolygon = interface.Polygon( - polygonId: interface.PolygonId('BermudaTriangle'), + final holedPolygon = platform.Polygon( + polygonId: platform.PolygonId('BermudaTriangle'), points: [ - interface.LatLng(25.774, -80.19), - interface.LatLng(18.466, -66.118), - interface.LatLng(32.321, -64.757), + platform.LatLng(25.774, -80.19), + platform.LatLng(18.466, -66.118), + platform.LatLng(32.321, -64.757), ], holes: [ [ - interface.LatLng(28.745, -70.579), - interface.LatLng(29.57, -67.514), - interface.LatLng(27.339, -66.668), + platform.LatLng(28.745, -70.579), + platform.LatLng(29.57, -67.514), + platform.LatLng(27.339, -66.668), ], ], ); From 1cccc8c1a2fda78bbe0c73f950c4cde0ba30a658 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Fri, 15 Jan 2021 09:38:39 +0100 Subject: [PATCH 08/15] Move Test --- .../test/test_driver/shape_integration.dart | 26 ----------------- .../test/test_driver/shapes_integration.dart | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart index fc12e1caeaa3..b1a691d18def 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shape_integration.dart @@ -8,10 +8,7 @@ import 'dart:async'; import 'package:integration_test/integration_test.dart'; import 'package:google_maps/google_maps.dart' as gmaps; -import 'package:google_maps/google_maps_geometry.dart' as geometry; import 'package:google_maps_flutter_web/google_maps_flutter_web.dart'; -import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart' - as platform; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; @@ -90,29 +87,6 @@ void main() { controller.update(options); verify(polygon.options = options); }); - - test('Polygon with hole has a hole', () { - final holedPolygon = platform.Polygon( - polygonId: platform.PolygonId('BermudaTriangle'), - points: [ - platform.LatLng(25.774, -80.19), - platform.LatLng(18.466, -66.118), - platform.LatLng(32.321, -64.757), - ], - holes: [ - [ - platform.LatLng(28.745, -70.579), - platform.LatLng(29.57, -67.514), - platform.LatLng(27.339, -66.668), - ], - ], - ); - final controller = PolygonsController(stream: null) - ..addPolygons({holedPolygon}); - final gmapsPolygon = controller.polygons.values.first.polygon; - final pointInHole = gmaps.LatLng(28.632, -68.401); - expect(geometry.poly.containsLocation(pointInHole, gmapsPolygon), false); - }); }); group('PolylineController', () { diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart index d4c416ae05f3..4d5c2b17cc56 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart @@ -10,6 +10,8 @@ import 'dart:ui'; import 'package:integration_test/integration_test.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:google_maps_flutter_web/google_maps_flutter_web.dart'; +import 'package:google_maps/google_maps.dart' as gmaps; +import 'package:google_maps/google_maps_geometry.dart' as geometry; import 'package:flutter_test/flutter_test.dart'; // This value is used when comparing the results of @@ -216,6 +218,33 @@ void main() { expect(controller.polygons, contains(PolygonId('BermudaTriangle'))); expect(controller.polygons, isNot(contains(PolygonId('66')))); }); + + testWidgets('Polygon with hole has a hole', (WidgetTester tester) async { + final polygons = { + Polygon( + polygonId: PolygonId('BermudaTriangle'), + points: [ + LatLng(25.774, -80.19), + LatLng(18.466, -66.118), + LatLng(32.321, -64.757), + ], + holes: [ + [ + LatLng(28.745, -70.579), + LatLng(29.57, -67.514), + LatLng(27.339, -66.668), + ], + ], + ), + }; + + controller.addPolygons(polygons); + + final polygon = controller.polygons.values.first.polygon; + final pointInHole = gmaps.LatLng(28.632, -68.401); + + expect(geometry.poly.containsLocation(pointInHole, polygon), false); + }); }); group('PolylinesController', () { From af3e94d0eca19d541489ad76cea2de9205a6c192 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Mon, 18 Jan 2021 09:46:32 +0100 Subject: [PATCH 09/15] Reverse Example Holes Make Holes actual Holes on Web Version --- .../example/lib/place_polygon.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/example/lib/place_polygon.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/place_polygon.dart index 5f2a0985b1b9..9589ba973571 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/lib/place_polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/lib/place_polygon.dart @@ -275,17 +275,17 @@ class PlacePolygonBodyState extends State { final double offset = polygonOffsets[selectedPolygon]; final List hole1 = []; - hole1.add(_createLatLng(51.8395 + offset, -3.8814)); - hole1.add(_createLatLng(52.0234 + offset, -3.9914)); - hole1.add(_createLatLng(52.1351 + offset, -4.4435)); hole1.add(_createLatLng(52.0231 + offset, -4.5829)); + hole1.add(_createLatLng(52.1351 + offset, -4.4435)); + hole1.add(_createLatLng(52.0234 + offset, -3.9914)); + hole1.add(_createLatLng(51.8395 + offset, -3.8814)); holes.add(hole1); final List hole2 = []; - hole2.add(_createLatLng(52.2395 + offset, -3.6814)); - hole2.add(_createLatLng(52.4234 + offset, -3.7914)); - hole2.add(_createLatLng(52.5351 + offset, -4.2435)); hole2.add(_createLatLng(52.4231 + offset, -4.3829)); + hole2.add(_createLatLng(52.5351 + offset, -4.2435)); + hole2.add(_createLatLng(52.4234 + offset, -3.7914)); + hole2.add(_createLatLng(52.2395 + offset, -3.6814)); holes.add(hole2); return holes; From a0cba00b99d2d30adc7463a5ddef7ce3fd5c08b0 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Mon, 18 Jan 2021 11:55:33 +0100 Subject: [PATCH 10/15] Add warning if hole is the same direction as the polygon --- .../lib/src/convert.dart | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart index c9fd1cd55d3b..825095812112 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart @@ -482,9 +482,15 @@ gmaps.PolygonOptions _polygonOptionsFromPolygon( polygon.points.forEach((point) { path.add(_latLngToGmLatLng(point)); }); + final polygonDirection = _isPolygonClockwise(path); List> paths = [path]; polygon.holes?.forEach((hole) { - paths.add(hole.map((point) => _latLngToGmLatLng(point)).toList()); + final holePath = hole.map((point) => _latLngToGmLatLng(point)).toList(); + if (_isPolygonClockwise(holePath) == polygonDirection) { + print( + 'Holepath is the same direction as polygon. In order to be displayed properly you should reverse the hole Path. More Info: https://developers.google.com/maps/documentation/javascript/examples/polygon-hole'); + } + paths.add(holePath); }); return gmaps.PolygonOptions() ..paths = paths @@ -498,6 +504,20 @@ gmaps.PolygonOptions _polygonOptionsFromPolygon( ..geodesic = polygon.geodesic; } +/// Calculates the direction of a given Polygon +/// based on: https://stackoverflow.com/a/1165943 +/// +/// returns [true] if clockwise [false] if counterclockwise +bool _isPolygonClockwise(List path) { + var direction = 0.0; + for (var i = 0; i < path.length; i++) { + direction = direction + + ((path[(i + 1) % path.length].lat - path[i].lat) * + (path[(i + 1) % path.length].lng + path[i].lng)); + } + return direction >= 0; +} + gmaps.PolylineOptions _polylineOptionsFromPolyline( gmaps.GMap googleMap, Polyline polyline) { List paths = []; From 2e0502ac83367f5dda4774ef0f6ccf24ee9726e7 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Mon, 18 Jan 2021 11:56:30 +0100 Subject: [PATCH 11/15] Update Changelog and Version --- .../google_maps_flutter/google_maps_flutter_web/CHANGELOG.md | 4 ++++ .../google_maps_flutter/google_maps_flutter_web/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md index 940419a215fc..217f1ce77b7b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.0+11 + +* Add warning if a hole is the same direction as the polygon [Issue](https://github.com/flutter/flutter/issues/74096) + ## 0.1.0+10 * Update `package:google_maps_flutter_platform_interface` to `^1.1.0`. diff --git a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml index bd879553a06d..ac293ebc06d1 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -1,7 +1,7 @@ name: google_maps_flutter_web description: Web platform implementation of google_maps_flutter homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter -version: 0.1.0+10 +version: 0.1.0+11 flutter: plugin: From 218e215e592bf0aef9e7133591e1094d4d78cbd8 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Thu, 21 Jan 2021 09:07:56 +0100 Subject: [PATCH 12/15] Revert Hole Direction in Example --- .../example/lib/place_polygon.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter/example/lib/place_polygon.dart b/packages/google_maps_flutter/google_maps_flutter/example/lib/place_polygon.dart index 9589ba973571..5f2a0985b1b9 100644 --- a/packages/google_maps_flutter/google_maps_flutter/example/lib/place_polygon.dart +++ b/packages/google_maps_flutter/google_maps_flutter/example/lib/place_polygon.dart @@ -275,17 +275,17 @@ class PlacePolygonBodyState extends State { final double offset = polygonOffsets[selectedPolygon]; final List hole1 = []; - hole1.add(_createLatLng(52.0231 + offset, -4.5829)); - hole1.add(_createLatLng(52.1351 + offset, -4.4435)); - hole1.add(_createLatLng(52.0234 + offset, -3.9914)); hole1.add(_createLatLng(51.8395 + offset, -3.8814)); + hole1.add(_createLatLng(52.0234 + offset, -3.9914)); + hole1.add(_createLatLng(52.1351 + offset, -4.4435)); + hole1.add(_createLatLng(52.0231 + offset, -4.5829)); holes.add(hole1); final List hole2 = []; - hole2.add(_createLatLng(52.4231 + offset, -4.3829)); - hole2.add(_createLatLng(52.5351 + offset, -4.2435)); - hole2.add(_createLatLng(52.4234 + offset, -3.7914)); hole2.add(_createLatLng(52.2395 + offset, -3.6814)); + hole2.add(_createLatLng(52.4234 + offset, -3.7914)); + hole2.add(_createLatLng(52.5351 + offset, -4.2435)); + hole2.add(_createLatLng(52.4231 + offset, -4.3829)); holes.add(hole2); return holes; From 40f8a15b29f15f732efbce83eefbf35716a4a767 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Thu, 21 Jan 2021 09:30:26 +0100 Subject: [PATCH 13/15] Reverse Hole Path if direction matches polygon --- .../google_maps_flutter_web/lib/src/convert.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart index 825095812112..ee4a35e66383 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart @@ -485,10 +485,12 @@ gmaps.PolygonOptions _polygonOptionsFromPolygon( final polygonDirection = _isPolygonClockwise(path); List> paths = [path]; polygon.holes?.forEach((hole) { - final holePath = hole.map((point) => _latLngToGmLatLng(point)).toList(); + List holePath = + hole.map((point) => _latLngToGmLatLng(point)).toList(); if (_isPolygonClockwise(holePath) == polygonDirection) { + holePath = holePath.reversed.toList(); print( - 'Holepath is the same direction as polygon. In order to be displayed properly you should reverse the hole Path. More Info: https://developers.google.com/maps/documentation/javascript/examples/polygon-hole'); + 'Holepath was reversed: https://github.com/flutter/flutter/issues/74096'); } paths.add(holePath); }); From 5d3cc87c45e7c7215df8e8846b2c1b295b77dc70 Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Thu, 21 Jan 2021 09:30:35 +0100 Subject: [PATCH 14/15] Add Test --- .../test/test_driver/shapes_integration.dart | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart index 4d5c2b17cc56..26db542c60fe 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/test/test_driver/shapes_integration.dart @@ -245,6 +245,39 @@ void main() { expect(geometry.poly.containsLocation(pointInHole, polygon), false); }); + + testWidgets('Hole Path gets reversed to display correctly', + (WidgetTester tester) async { + final polygons = { + Polygon( + polygonId: PolygonId('BermudaTriangle'), + points: [ + LatLng(25.774, -80.19), + LatLng(18.466, -66.118), + LatLng(32.321, -64.757), + ], + holes: [ + [ + LatLng(27.339, -66.668), + LatLng(29.57, -67.514), + LatLng(28.745, -70.579), + ], + ], + ), + }; + + controller.addPolygons(polygons); + + expect( + controller.polygons.values.first.polygon.paths.getAt(1).getAt(0).lat, + 28.745); + expect( + controller.polygons.values.first.polygon.paths.getAt(1).getAt(1).lat, + 29.57); + expect( + controller.polygons.values.first.polygon.paths.getAt(1).getAt(2).lat, + 27.339); + }); }); group('PolylinesController', () { From f25e4653cb783c68a873f4bc71f0f27b4bfbc6dc Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Thu, 21 Jan 2021 12:29:50 -0800 Subject: [PATCH 15/15] Only warn users if in debug mode. Bump version to 0.1.1 (should have done it with the first holes push :P) --- .../google_maps_flutter_web/CHANGELOG.md | 4 ++-- .../google_maps_flutter_web/lib/src/convert.dart | 10 ++++++++-- .../google_maps_flutter_web/pubspec.yaml | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md index 217f1ce77b7b..caa64ec73088 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -1,6 +1,6 @@ -## 0.1.0+11 +## 0.1.1 -* Add warning if a hole is the same direction as the polygon [Issue](https://github.com/flutter/flutter/issues/74096) +* Auto-reverse holes if they're the same direction as the polygon. [Issue](https://github.com/flutter/flutter/issues/74096). ## 0.1.0+10 diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart index ee4a35e66383..95f481a9bdc5 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart @@ -484,15 +484,21 @@ gmaps.PolygonOptions _polygonOptionsFromPolygon( }); final polygonDirection = _isPolygonClockwise(path); List> paths = [path]; + int holeIndex = 0; polygon.holes?.forEach((hole) { List holePath = hole.map((point) => _latLngToGmLatLng(point)).toList(); if (_isPolygonClockwise(holePath) == polygonDirection) { holePath = holePath.reversed.toList(); - print( - 'Holepath was reversed: https://github.com/flutter/flutter/issues/74096'); + if (kDebugMode) { + print( + 'Hole [$holeIndex] in Polygon [${polygon.polygonId.value}] has been reversed.' + ' Ensure holes in polygons are "wound in the opposite direction to the outer path."' + ' More info: https://github.com/flutter/flutter/issues/74096'); + } } paths.add(holePath); + holeIndex++; }); return gmaps.PolygonOptions() ..paths = paths diff --git a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml index ac293ebc06d1..099a1238be1c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -1,7 +1,7 @@ name: google_maps_flutter_web description: Web platform implementation of google_maps_flutter homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter -version: 0.1.0+11 +version: 0.1.1 flutter: plugin: