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 Anton Borries Alex Li Rahul Raj <64.rahulraj@gmail.com> +Justin Baumann 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 4f9eed77d63..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,3 +1,7 @@ +## 0.5.1 + +* Adds padding support to `CameraUpdate.newLatLngBounds`. Issue [#122192](https://github.com/flutter/flutter/issues/122192). + ## 0.5.0+1 * Updates the README to mention that this package is the endorsed implementation 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..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 @@ -72,6 +72,60 @@ void main() { expect(coords.latitude, closeTo(19, _acceptableLatLngDelta)); expect(coords.longitude, closeTo(26, _acceptableLatLngDelta)); }); + + testWidgets('addPadding', (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); + + 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, isNot(zeroLatLngBounds)); + expect( + secondVisibleRegion, + isNot(firstVisibleRegion), + ); + expect(secondVisibleRegion.contains(initialMapCenter), isTrue); + expect( + secondVisibleRegion.contains(firstVisibleRegion.northeast), + isTrue, + ); + expect( + secondVisibleRegion.contains(firstVisibleRegion.southwest), + 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 fb656a135ff..1e3bcac753e 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 @@ -447,14 +447,14 @@ void _applyCameraUpdate(gmaps.GMap map, CameraUpdate update) { final List latLngPair = asJsonList(json[1]); final List latLng1 = asJsonList(latLngPair[0]); final List 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 9372beb0c8e..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.5.0+1 +version: 0.5.1 environment: sdk: ">=2.18.0 <4.0.0"