Skip to content

Commit 53ed5a0

Browse files
authored
[google_maps_flutter_web] Add padding to newLatLngBounds implementation (#3452)
## Description This PR is implementing the `padding` argument to `fitBounds` which is called by `newLatLngBounds`. ## Related Issues [flutter/flutter#122192](flutter/flutter#122192)
1 parent 0ef3938 commit 53ed5a0

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

packages/google_maps_flutter/google_maps_flutter_web/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ Aleksandr Yurkovskiy <[email protected]>
6464
Anton Borries <[email protected]>
6565
6666
Rahul Raj <[email protected]>
67+
Justin Baumann <[email protected]>

packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.1
2+
3+
* Adds padding support to `CameraUpdate.newLatLngBounds`. Issue [#122192](https://github.com/flutter/flutter/issues/122192).
4+
15
## 0.5.0+1
26

37
* Updates the README to mention that this package is the endorsed implementation

packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/projection_test.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,60 @@ void main() {
7272
expect(coords.latitude, closeTo(19, _acceptableLatLngDelta));
7373
expect(coords.longitude, closeTo(26, _acceptableLatLngDelta));
7474
});
75+
76+
testWidgets('addPadding', (WidgetTester tester) async {
77+
const LatLng initialMapCenter = LatLng(0, 0);
78+
const double initialZoomLevel = 5;
79+
const CameraPosition initialCameraPosition =
80+
CameraPosition(target: initialMapCenter, zoom: initialZoomLevel);
81+
final LatLngBounds zeroLatLngBounds = LatLngBounds(
82+
southwest: const LatLng(0, 0), northeast: const LatLng(0, 0));
83+
await tester.pumpWidget(
84+
Directionality(
85+
textDirection: TextDirection.ltr,
86+
child: GoogleMap(
87+
initialCameraPosition: initialCameraPosition,
88+
onMapCreated: onMapCreated,
89+
),
90+
),
91+
);
92+
await tester.pumpAndSettle();
93+
94+
final GoogleMapController controller = await controllerCompleter.future;
95+
96+
final LatLngBounds firstVisibleRegion =
97+
await controller.getVisibleRegion();
98+
99+
expect(firstVisibleRegion, isNotNull);
100+
expect(firstVisibleRegion.southwest, isNotNull);
101+
expect(firstVisibleRegion.northeast, isNotNull);
102+
expect(firstVisibleRegion, isNot(zeroLatLngBounds));
103+
expect(firstVisibleRegion.contains(initialMapCenter), isTrue);
104+
105+
const double padding = 0.1;
106+
await controller.moveCamera(
107+
CameraUpdate.newLatLngBounds(firstVisibleRegion, padding));
108+
await tester.pumpAndSettle(const Duration(seconds: 3));
109+
110+
final LatLngBounds secondVisibleRegion =
111+
await controller.getVisibleRegion();
112+
113+
expect(secondVisibleRegion, isNotNull);
114+
expect(secondVisibleRegion, isNot(zeroLatLngBounds));
115+
expect(
116+
secondVisibleRegion,
117+
isNot(firstVisibleRegion),
118+
);
119+
expect(secondVisibleRegion.contains(initialMapCenter), isTrue);
120+
expect(
121+
secondVisibleRegion.contains(firstVisibleRegion.northeast),
122+
isTrue,
123+
);
124+
expect(
125+
secondVisibleRegion.contains(firstVisibleRegion.southwest),
126+
isTrue,
127+
);
128+
});
75129
});
76130

77131
group('getScreenCoordinate', () {

packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,14 @@ void _applyCameraUpdate(gmaps.GMap map, CameraUpdate update) {
447447
final List<Object?> latLngPair = asJsonList(json[1]);
448448
final List<Object?> latLng1 = asJsonList(latLngPair[0]);
449449
final List<Object?> latLng2 = asJsonList(latLngPair[1]);
450+
final double padding = json[2] as double;
450451
map.fitBounds(
451452
gmaps.LatLngBounds(
452453
gmaps.LatLng(latLng1[0] as num?, latLng1[1] as num?),
453454
gmaps.LatLng(latLng2[0] as num?, latLng2[1] as num?),
454455
),
456+
padding,
455457
);
456-
// padding = json[2];
457-
// Needs package:google_maps ^4.0.0 to adjust the padding in fitBounds
458458
break;
459459
case 'scrollBy':
460460
map.panBy(json[1] as num?, json[2] as num?);

packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_maps_flutter_web
22
description: Web platform implementation of google_maps_flutter
33
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
5-
version: 0.5.0+1
5+
version: 0.5.1
66

77
environment:
88
sdk: ">=2.18.0 <4.0.0"

0 commit comments

Comments
 (0)