Skip to content

Commit dc48f5c

Browse files
[google_maps_flutter] Add cameraControl enable/disable & position on web (#9089)
Add support to camera control button on web. Fixes flutter/flutter#167137 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 7dc6d9a commit dc48f5c

File tree

6 files changed

+90
-5
lines changed

6 files changed

+90
-5
lines changed

packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.13.0
22

3+
* Adds support for camera control button on web.
34
* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7.
45

56
## 2.12.3

packages/google_maps_flutter/google_maps_flutter/example/lib/map_ui.dart

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class MapUiBodyState extends State<MapUiBody> {
6161
late GoogleMapController _controller;
6262
bool _nightMode = false;
6363
String _mapStyle = '';
64+
bool _webCameraControlEnabled = true;
65+
WebCameraControlPosition? _webCameraControlPosition;
6466

6567
@override
6668
void initState() {
@@ -72,6 +74,64 @@ class MapUiBodyState extends State<MapUiBody> {
7274
super.dispose();
7375
}
7476

77+
Widget _webCameraControlToggler() {
78+
return TextButton(
79+
child: Text(
80+
'${_webCameraControlEnabled ? 'disable' : 'enable'} web camera control',
81+
),
82+
onPressed: () {
83+
setState(() {
84+
_webCameraControlEnabled = !_webCameraControlEnabled;
85+
});
86+
},
87+
);
88+
}
89+
90+
Widget _webCameraControlPositionToggler() {
91+
return TextButton(
92+
onPressed:
93+
() => showDialog<void>(
94+
context: context,
95+
builder: (BuildContext context) {
96+
return AlertDialog(
97+
title: const Text('Web camera control position'),
98+
content: Column(
99+
mainAxisSize: MainAxisSize.min,
100+
children: <Widget>[
101+
DropdownButton<WebCameraControlPosition>(
102+
hint: const Text('Web camera control position'),
103+
value: _webCameraControlPosition,
104+
items:
105+
WebCameraControlPosition.values
106+
.map(
107+
(WebCameraControlPosition e) =>
108+
DropdownMenuItem<WebCameraControlPosition>(
109+
value: e,
110+
child: Text(e.name),
111+
),
112+
)
113+
.toList(),
114+
onChanged: (WebCameraControlPosition? value) {
115+
setState(() {
116+
_webCameraControlPosition = value;
117+
});
118+
},
119+
),
120+
TextButton(
121+
onPressed: () {
122+
Navigator.pop(context);
123+
},
124+
child: const Text('Ok'),
125+
),
126+
],
127+
),
128+
);
129+
},
130+
),
131+
child: const Text('change web camera control position'),
132+
);
133+
}
134+
75135
Widget _compassToggler() {
76136
return TextButton(
77137
child: Text('${_compassEnabled ? 'disable' : 'enable'} compass'),
@@ -269,6 +329,8 @@ class MapUiBodyState extends State<MapUiBody> {
269329
@override
270330
Widget build(BuildContext context) {
271331
final GoogleMap googleMap = GoogleMap(
332+
webCameraControlEnabled: _webCameraControlEnabled,
333+
webCameraControlPosition: _webCameraControlPosition,
272334
onMapCreated: onMapCreated,
273335
initialCameraPosition: _kInitialPosition,
274336
compassEnabled: _compassEnabled,
@@ -326,6 +388,11 @@ class MapUiBodyState extends State<MapUiBody> {
326388
_myLocationButtonToggler(),
327389
_myTrafficToggler(),
328390
_nightModeToggler(),
391+
if (kIsWeb) ...<Widget>[
392+
_webCameraControlToggler(),
393+
if (_webCameraControlEnabled)
394+
_webCameraControlPositionToggler(),
395+
],
329396
],
330397
),
331398
),

packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies:
1919
# the parent directory to use the current plugin's version.
2020
path: ../
2121
google_maps_flutter_android: ^2.16.1
22-
google_maps_flutter_platform_interface: ^2.12.1
22+
google_maps_flutter_platform_interface: ^2.14.0
2323

2424
dev_dependencies:
2525
build_runner: ^2.1.10

packages/google_maps_flutter/google_maps_flutter/lib/google_maps_flutter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
5656
TileOverlay,
5757
TileOverlayId,
5858
TileProvider,
59+
WebCameraControlPosition,
5960
WebGestureHandling,
6061
WeightedLatLng;
6162

packages/google_maps_flutter/google_maps_flutter/lib/src/google_map.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class GoogleMap extends StatefulWidget {
9999
this.onMapCreated,
100100
this.gestureRecognizers = const <Factory<OneSequenceGestureRecognizer>>{},
101101
this.webGestureHandling,
102+
this.webCameraControlPosition,
103+
this.webCameraControlEnabled = true,
102104
this.compassEnabled = true,
103105
this.mapToolbarEnabled = true,
104106
this.cameraTargetBounds = CameraTargetBounds.unbounded,
@@ -353,6 +355,18 @@ class GoogleMap extends StatefulWidget {
353355
/// See [WebGestureHandling] for more details.
354356
final WebGestureHandling? webGestureHandling;
355357

358+
/// This setting controls how the API handles cameraControl button position on the map. Web only.
359+
///
360+
/// If null, the Google Maps API will use its default camera control position.
361+
///
362+
/// See [WebCameraControlPosition] for more details.
363+
final WebCameraControlPosition? webCameraControlPosition;
364+
365+
/// Enables or disables the Camera controls. Web only.
366+
///
367+
/// See https://developers.google.com/maps/documentation/javascript/controls for more details.
368+
final bool webCameraControlEnabled;
369+
356370
/// Identifier that's associated with a specific cloud-based map style.
357371
///
358372
/// See https://developers.google.com/maps/documentation/get-map-id
@@ -684,6 +698,8 @@ class _GoogleMapState extends State<GoogleMap> {
684698
/// Builds a [MapConfiguration] from the given [map].
685699
MapConfiguration _configurationFromMapWidget(GoogleMap map) {
686700
return MapConfiguration(
701+
webCameraControlPosition: map.webCameraControlPosition,
702+
webCameraControlEnabled: map.webCameraControlEnabled,
687703
webGestureHandling: map.webGestureHandling,
688704
compassEnabled: map.compassEnabled,
689705
mapToolbarEnabled: map.mapToolbarEnabled,

packages/google_maps_flutter/google_maps_flutter/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_maps_flutter
22
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
5-
version: 2.12.3
5+
version: 2.13.0
66

77
environment:
88
sdk: ^3.7.0
@@ -23,8 +23,8 @@ dependencies:
2323
sdk: flutter
2424
google_maps_flutter_android: ^2.16.1
2525
google_maps_flutter_ios: ^2.15.4
26-
google_maps_flutter_platform_interface: ^2.12.1
27-
google_maps_flutter_web: ^0.5.12
26+
google_maps_flutter_platform_interface: ^2.14.0
27+
google_maps_flutter_web: ^0.5.14
2828

2929
dev_dependencies:
3030
flutter_test:

0 commit comments

Comments
 (0)