From b943ef61c81a230ae0a2e9f47b702b73e8cd1f25 Mon Sep 17 00:00:00 2001 From: Justin Baumann <justin.baumann@t-online.de> Date: Mon, 13 Mar 2023 14:40:41 +0100 Subject: [PATCH 1/4] Add padding to newLatLngBounds implementation Increase version and write changes to changelog Add test for newLatLngBounds --- .../google_maps_flutter_web/AUTHORS | 1 + .../google_maps_flutter_web/CHANGELOG.md | 4 ++ .../integration_test/projection_test.dart | 67 +++++++++++++++++++ .../lib/src/convert.dart | 4 +- .../google_maps_flutter_web/pubspec.yaml | 2 +- 5 files changed, 75 insertions(+), 3 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/AUTHORS b/packages/google_maps_flutter/google_maps_flutter_web/AUTHORS index 493a0b4ef9c..b5b0e84d473 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/AUTHORS +++ b/packages/google_maps_flutter/google_maps_flutter_web/AUTHORS @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy <sanekyy@gmail.com> Anton Borries <mail@antonborri.es> Alex Li <google@alexv525.com> Rahul Raj <64.rahulraj@gmail.com> +Justin Baumann <me@jxstxn.dev> 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 be97166650b..9ce65b13e0f 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.4.0+8 + +* Use padding from newLatLngBounds. Issue [#122192](https://github.com/flutter/flutter/issues/122192) + ## 0.4.0+7 * Clarifies explanation of endorsement in README. diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/projection_test.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/projection_test.dart index 57763d47f93..72ecc583859 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/projection_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/projection_test.dart @@ -72,6 +72,73 @@ void main() { expect(coords.latitude, closeTo(19, _acceptableLatLngDelta)); expect(coords.longitude, closeTo(26, _acceptableLatLngDelta)); }); + + testWidgets('testGetVisibleRegion', (WidgetTester tester) async { + const LatLng initialMapCenter = LatLng(0, 0); + const double initialZoomLevel = 5; + const CameraPosition initialCameraPosition = + CameraPosition(target: initialMapCenter, zoom: initialZoomLevel); + final LatLngBounds zeroLatLngBounds = LatLngBounds( + southwest: const LatLng(0, 0), northeast: const LatLng(0, 0)); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: GoogleMap( + initialCameraPosition: initialCameraPosition, + onMapCreated: onMapCreated, + ), + ), + ); + await tester.pumpAndSettle(); + + final GoogleMapController controller = await controllerCompleter.future; + + final LatLngBounds firstVisibleRegion = + await controller.getVisibleRegion(); + + expect(firstVisibleRegion, isNotNull); + expect(firstVisibleRegion.southwest, isNotNull); + expect(firstVisibleRegion.northeast, isNotNull); + expect(firstVisibleRegion, isNot(zeroLatLngBounds)); + expect(firstVisibleRegion.contains(initialMapCenter), isTrue); + + // Making a new `LatLngBounds` about (10, 10) distance south west to the `firstVisibleRegion`. + // The size of the `LatLngBounds` is 10 by 10. + final LatLng southWest = LatLng( + firstVisibleRegion.southwest.latitude - 20, + firstVisibleRegion.southwest.longitude - 20); + final LatLng northEast = LatLng( + firstVisibleRegion.southwest.latitude - 10, + firstVisibleRegion.southwest.longitude - 10); + final LatLng newCenter = LatLng( + (northEast.latitude + southWest.latitude) / 2, + (northEast.longitude + southWest.longitude) / 2, + ); + + expect(firstVisibleRegion.contains(northEast), isFalse); + expect(firstVisibleRegion.contains(southWest), isFalse); + + final LatLngBounds latLngBounds = + LatLngBounds(southwest: southWest, northeast: northEast); + + // TODO(iskakaushik): non-zero padding is needed for some device configurations + // https://github.com/flutter/flutter/issues/30575 + const double padding = 0; + await controller + .moveCamera(CameraUpdate.newLatLngBounds(latLngBounds, padding)); + await tester.pumpAndSettle(const Duration(seconds: 3)); + + final LatLngBounds secondVisibleRegion = + await controller.getVisibleRegion(); + + expect(secondVisibleRegion, isNotNull); + expect(secondVisibleRegion.southwest, isNotNull); + expect(secondVisibleRegion.northeast, isNotNull); + expect(secondVisibleRegion, isNot(zeroLatLngBounds)); + + expect(firstVisibleRegion, isNot(secondVisibleRegion)); + expect(secondVisibleRegion.contains(newCenter), isTrue); + }); }); group('getScreenCoordinate', () { 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 25cba849475..2693a4dc0fb 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 @@ -458,14 +458,14 @@ void _applyCameraUpdate(gmaps.GMap map, CameraUpdate update) { final List<Object?> latLngPair = asJsonList(json[1]); final List<Object?> latLng1 = asJsonList(latLngPair[0]); final List<Object?> latLng2 = asJsonList(latLngPair[1]); + final double padding = json[2] as double; map.fitBounds( gmaps.LatLngBounds( gmaps.LatLng(latLng1[0] as num?, latLng1[1] as num?), gmaps.LatLng(latLng2[0] as num?, latLng2[1] as num?), ), + padding, ); - // padding = json[2]; - // Needs package:google_maps ^4.0.0 to adjust the padding in fitBounds break; case 'scrollBy': map.panBy(json[1] as num?, json[2] as num?); 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 ac29da6a327..423b7cec08c 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter_web description: Web platform implementation of google_maps_flutter repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 -version: 0.4.0+7 +version: 0.4.0+8 environment: sdk: ">=2.17.0 <3.0.0" From b9eefa56185a2fd9eab4f80ed279157d4341090f Mon Sep 17 00:00:00 2001 From: Justin Baumann <justin.baumann@t-online.de> Date: Mon, 26 Jun 2023 23:09:58 +0200 Subject: [PATCH 2/4] Test with non zero padding --- .../integration_test/projection_test.dart | 47 +++++++------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/projection_test.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/projection_test.dart index 72ecc583859..e64bd43561a 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/projection_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/projection_test.dart @@ -73,7 +73,7 @@ void main() { expect(coords.longitude, closeTo(26, _acceptableLatLngDelta)); }); - testWidgets('testGetVisibleRegion', (WidgetTester tester) async { + testWidgets('addPadding', (WidgetTester tester) async { const LatLng initialMapCenter = LatLng(0, 0); const double initialZoomLevel = 5; const CameraPosition initialCameraPosition = @@ -102,42 +102,29 @@ void main() { expect(firstVisibleRegion, isNot(zeroLatLngBounds)); expect(firstVisibleRegion.contains(initialMapCenter), isTrue); - // Making a new `LatLngBounds` about (10, 10) distance south west to the `firstVisibleRegion`. - // The size of the `LatLngBounds` is 10 by 10. - final LatLng southWest = LatLng( - firstVisibleRegion.southwest.latitude - 20, - firstVisibleRegion.southwest.longitude - 20); - final LatLng northEast = LatLng( - firstVisibleRegion.southwest.latitude - 10, - firstVisibleRegion.southwest.longitude - 10); - final LatLng newCenter = LatLng( - (northEast.latitude + southWest.latitude) / 2, - (northEast.longitude + southWest.longitude) / 2, - ); - - expect(firstVisibleRegion.contains(northEast), isFalse); - expect(firstVisibleRegion.contains(southWest), isFalse); - - final LatLngBounds latLngBounds = - LatLngBounds(southwest: southWest, northeast: northEast); - - // TODO(iskakaushik): non-zero padding is needed for some device configurations - // https://github.com/flutter/flutter/issues/30575 - const double padding = 0; - await controller - .moveCamera(CameraUpdate.newLatLngBounds(latLngBounds, padding)); + const double padding = 0.1; + await controller.moveCamera( + CameraUpdate.newLatLngBounds(firstVisibleRegion, padding)); await tester.pumpAndSettle(const Duration(seconds: 3)); final LatLngBounds secondVisibleRegion = await controller.getVisibleRegion(); expect(secondVisibleRegion, isNotNull); - expect(secondVisibleRegion.southwest, isNotNull); - expect(secondVisibleRegion.northeast, isNotNull); expect(secondVisibleRegion, isNot(zeroLatLngBounds)); - - expect(firstVisibleRegion, isNot(secondVisibleRegion)); - expect(secondVisibleRegion.contains(newCenter), isTrue); + expect( + secondVisibleRegion, + isNot(firstVisibleRegion), + ); + expect(secondVisibleRegion.contains(initialMapCenter), isTrue); + expect( + secondVisibleRegion.contains(firstVisibleRegion.northeast), + isTrue, + ); + expect( + secondVisibleRegion.contains(firstVisibleRegion.southwest), + isTrue, + ); }); }); From 86b91a5c323d567703e99365a27eb3692e0a61b3 Mon Sep 17 00:00:00 2001 From: Justin Baumann <justin.baumann@t-online.de> Date: Mon, 26 Jun 2023 23:13:31 +0200 Subject: [PATCH 3/4] fix version fix build number --- .../google_maps_flutter/google_maps_flutter_web/CHANGELOG.md | 2 +- .../google_maps_flutter/google_maps_flutter_web/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 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 95e14278469..c6d740cfec7 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md +++ b/packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.6.0+10 +## 0.5.1 * Use padding from newLatLngBounds. Issue [#122192](https://github.com/flutter/flutter/issues/122192) 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 1712955c14a..e6afb06eab3 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -2,7 +2,7 @@ name: google_maps_flutter_web description: Web platform implementation of google_maps_flutter repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22 -version: 0.6.0+10 +version: 0.5.1 environment: sdk: ">=2.18.0 <4.0.0" From 173a425ebd7ce9531bc08b1ce5d10762c55fad87 Mon Sep 17 00:00:00 2001 From: Justin Baumann <me@jxstxn.dev> Date: Wed, 28 Jun 2023 12:16:48 +0200 Subject: [PATCH 4/4] Update packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md Co-authored-by: David Iglesias <ditman@gmail.com> --- .../google_maps_flutter/google_maps_flutter_web/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 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 c6d740cfec7..52f288ec7e9 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.5.1 -* Use padding from newLatLngBounds. Issue [#122192](https://github.com/flutter/flutter/issues/122192) +* Adds padding support to `CameraUpdate.newLatLngBounds`. Issue [#122192](https://github.com/flutter/flutter/issues/122192). ## 0.5.0+1