Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
ditman marked this conversation as resolved.
Outdated
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', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?);
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.4.0+7
version: 0.4.0+8

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down