From 3a2b87982f3579ea0c820f405cf8299e7d655578 Mon Sep 17 00:00:00 2001 From: Rexios Date: Wed, 19 Jul 2023 10:59:12 -0400 Subject: [PATCH 1/4] Cherry pick web changes --- .../google_maps_flutter_web/CHANGELOG.md | 4 ++++ .../google_maps_controller_test.dart | 18 ++++++++++-------- .../lib/src/convert.dart | 17 ++++++++++++++--- .../lib/src/google_maps_controller.dart | 5 +++++ .../google_maps_flutter_web/pubspec.yaml | 5 +++-- 5 files changed, 36 insertions(+), 13 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 52f288ec7e9..0427818ca50 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.2 + +* Adds options for gesture handling and tilt controls. + ## 0.5.1 * Adds padding support to `CameraUpdate.newLatLngBounds`. Issue [#122192](https://github.com/flutter/flutter/issues/122192). diff --git a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.dart b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.dart index 8889e4ba957..00a448a979b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.dart @@ -383,6 +383,7 @@ void main() { mapConfiguration: const MapConfiguration( mapType: MapType.satellite, zoomControlsEnabled: true, + fortyFiveDegreeImageryEnabled: false, )); controller.debugSetOverrides( createMap: (_, gmaps.MapOptions options) { @@ -398,13 +399,16 @@ void main() { expect(capturedOptions!.gestureHandling, 'auto', reason: 'by default the map handles zoom/pan gestures internally'); + expect(capturedOptions!.rotateControl, false); + expect(capturedOptions!.tilt, 0); }); - testWidgets('disables gestureHandling with scrollGesturesEnabled false', + testWidgets('translates fortyFiveDegreeImageryEnabled option', (WidgetTester tester) async { controller = createController( mapConfiguration: const MapConfiguration( scrollGesturesEnabled: false, + fortyFiveDegreeImageryEnabled: true, )); controller.debugSetOverrides( createMap: (_, gmaps.MapOptions options) { @@ -415,16 +419,16 @@ void main() { controller.init(); expect(capturedOptions, isNotNull); - expect(capturedOptions!.gestureHandling, 'none', - reason: - 'disabling scroll gestures disables all gesture handling'); + expect(capturedOptions!.rotateControl, true); + expect(capturedOptions!.tilt, isNull); }); - testWidgets('disables gestureHandling with zoomGesturesEnabled false', + testWidgets('translates webGestureHandling option', (WidgetTester tester) async { controller = createController( mapConfiguration: const MapConfiguration( zoomGesturesEnabled: false, + webGestureHandling: WebGestureHandling.greedy, )); controller.debugSetOverrides( createMap: (_, gmaps.MapOptions options) { @@ -435,9 +439,7 @@ void main() { controller.init(); expect(capturedOptions, isNotNull); - expect(capturedOptions!.gestureHandling, 'none', - reason: - 'disabling scroll gestures disables all gesture handling'); + expect(capturedOptions!.gestureHandling, 'greedy'); }); testWidgets('sets initial position when passed', 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 1e3bcac753e..a88d85cab5f 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 @@ -31,7 +31,7 @@ double _getCssOpacity(Color color) { // myLocationEnabled needs to be built through dart:html navigator.geolocation // See: https://api.dart.dev/stable/2.8.4/dart-html/Geolocation-class.html // trafficEnabled is handled when creating the GMap object, since it needs to be added as a layer. -// trackCameraPosition is just a boolan value that indicates if the map has an onCameraMove handler. +// trackCameraPosition is just a boolean value that indicates if the map has an onCameraMove handler. // indoorViewEnabled seems to not have an equivalent in web // buildingsEnabled seems to not have an equivalent in web // padding seems to behave differently in web than mobile. You can't move UI elements in web. @@ -62,9 +62,20 @@ gmaps.MapOptions _configurationAndStyleToGmapsOptions( if (configuration.scrollGesturesEnabled == false || configuration.zoomGesturesEnabled == false) { - options.gestureHandling = 'none'; + window.console.warn( + '`scrollGesturesEnabled` and `zoomGesturesEnabled` are now ignored on the web.' + ' Use `webGestureHandling: WebGestureHandling.none` instead.', + ); + } + + if (configuration.webGestureHandling != null) { + options.gestureHandling = configuration.webGestureHandling!.name; } else { - options.gestureHandling = 'auto'; + options.gestureHandling = WebGestureHandling.auto.name; + } + + if (configuration.fortyFiveDegreeImageryEnabled != null) { + options.rotateControl = configuration.fortyFiveDegreeImageryEnabled; } // These don't have any configuration entries, but they seem to be off in the diff --git a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart index 41342bf5cff..f49a6878df5 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart +++ b/packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart @@ -169,6 +169,11 @@ class GoogleMapController { // Initial position can only to be set here! options = _applyInitialPosition(_initialCameraPosition, options); + // Fully disable 45 degree imagery if desired + if (options.rotateControl == false) { + options.tilt = 0; + } + // Create the map... final gmaps.GMap map = _createMap(_div, options); _googleMap = map; 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 e6afb06eab3..87d99382f12 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.1 +version: 0.5.2 environment: sdk: ">=2.18.0 <4.0.0" @@ -22,7 +22,7 @@ dependencies: flutter_web_plugins: sdk: flutter google_maps: ^6.1.0 - google_maps_flutter_platform_interface: ^2.2.2 + google_maps_flutter_platform_interface: ^2.4.0 sanitize_html: ^2.0.0 stream_transform: ^2.0.0 @@ -33,3 +33,4 @@ dev_dependencies: # The example deliberately includes limited-use secrets. false_secrets: - /example/web/index.html + From fc27796af02e5edb2fc79e88295e6fe52dca0871 Mon Sep 17 00:00:00 2001 From: Rexios Date: Thu, 20 Jul 2023 09:08:13 -0400 Subject: [PATCH 2/4] Update packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart Co-authored-by: David Iglesias --- .../google_maps_flutter_web/lib/src/convert.dart | 6 ++++++ 1 file changed, 6 insertions(+) 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 a88d85cab5f..d7a05b618b3 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 @@ -70,9 +70,15 @@ gmaps.MapOptions _configurationAndStyleToGmapsOptions( if (configuration.webGestureHandling != null) { options.gestureHandling = configuration.webGestureHandling!.name; + } else if (configuration.scrollGesturesEnabled == false || + configuration.zoomGesturesEnabled == false) { + // Old behavior + options.gestureHandling = 'none'; } else { options.gestureHandling = WebGestureHandling.auto.name; } + options.gestureHandling = WebGestureHandling.auto.name; + } if (configuration.fortyFiveDegreeImageryEnabled != null) { options.rotateControl = configuration.fortyFiveDegreeImageryEnabled; From f71ce51315141b278288f55e15e6f2bdd8254025 Mon Sep 17 00:00:00 2001 From: Rexios Date: Thu, 20 Jul 2023 15:27:05 -0400 Subject: [PATCH 3/4] Fixes --- .../google_maps_flutter_web/lib/src/convert.dart | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) 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 d7a05b618b3..1e5e9192c45 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 @@ -60,25 +60,15 @@ gmaps.MapOptions _configurationAndStyleToGmapsOptions( options.zoomControl = configuration.zoomControlsEnabled; } - if (configuration.scrollGesturesEnabled == false || - configuration.zoomGesturesEnabled == false) { - window.console.warn( - '`scrollGesturesEnabled` and `zoomGesturesEnabled` are now ignored on the web.' - ' Use `webGestureHandling: WebGestureHandling.none` instead.', - ); - } - if (configuration.webGestureHandling != null) { options.gestureHandling = configuration.webGestureHandling!.name; } else if (configuration.scrollGesturesEnabled == false || configuration.zoomGesturesEnabled == false) { - // Old behavior - options.gestureHandling = 'none'; + // Old behavior + options.gestureHandling = WebGestureHandling.none.name; } else { options.gestureHandling = WebGestureHandling.auto.name; } - options.gestureHandling = WebGestureHandling.auto.name; - } if (configuration.fortyFiveDegreeImageryEnabled != null) { options.rotateControl = configuration.fortyFiveDegreeImageryEnabled; From 2800ea31654741cc8263b5c14ed93cfb56186e14 Mon Sep 17 00:00:00 2001 From: Rexios Date: Thu, 20 Jul 2023 15:27:50 -0400 Subject: [PATCH 4/4] Formatting --- .../google_maps_flutter/google_maps_flutter_web/pubspec.yaml | 1 - 1 file changed, 1 deletion(-) 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 87d99382f12..f1eb09c6c57 100644 --- a/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml +++ b/packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml @@ -33,4 +33,3 @@ dev_dependencies: # The example deliberately includes limited-use secrets. false_secrets: - /example/web/index.html -