Skip to content

Commit

Permalink
[google_maps_flutter_web] Add padding to newLatLngBounds implementati…
Browse files Browse the repository at this point in the history
…on (#3452)

## Description
This PR is implementing the `padding` argument to `fitBounds` which is called by `newLatLngBounds`.

## Related Issues
[#122192](#122192)
  • Loading branch information
jxstxn1 committed Jun 30, 2023
1 parent 0ef3938 commit 53ed5a0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,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?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 53ed5a0

Please sign in to comment.