Skip to content

Commit 37bafd4

Browse files
[google_maps_flutter_platform_interface] Add cameraControl enable/disable & position on web (#9897)
Platform interface portion of #9089. Part of flutter/flutter#167137 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^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 141d8e3 commit 37bafd4

File tree

6 files changed

+208
-3
lines changed

6 files changed

+208
-3
lines changed

packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md

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

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

56
## 2.13.0
@@ -247,4 +248,4 @@
247248

248249
## 1.0.0 ... 1.0.0+5
249250

250-
* Development.
251+
* Development.

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_configuration.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class MapConfiguration {
1515
/// as either a full configuration selection, or an update to an existing
1616
/// configuration where only non-null values are updated.
1717
const MapConfiguration({
18+
this.webCameraControlPosition,
19+
this.webCameraControlEnabled,
1820
this.webGestureHandling,
1921
this.compassEnabled,
2022
this.mapToolbarEnabled,
@@ -47,6 +49,18 @@ class MapConfiguration {
4749
/// See [WebGestureHandling] for more details.
4850
final WebGestureHandling? webGestureHandling;
4951

52+
/// This setting controls how the API handles cameraControl button position on the map. Web only.
53+
///
54+
/// If null, the Google Maps API will use its default camera control position.
55+
///
56+
/// See [WebCameraControlPosition] for more details.
57+
final WebCameraControlPosition? webCameraControlPosition;
58+
59+
/// This setting controls how the API handles cameraControl button on the map. Web only.
60+
///
61+
/// See https://developers.google.com/maps/documentation/javascript/controls for more details.
62+
final bool? webCameraControlEnabled;
63+
5064
/// True if the compass UI should be shown.
5165
final bool? compassEnabled;
5266

@@ -142,6 +156,14 @@ class MapConfiguration {
142156
/// that are different from [other].
143157
MapConfiguration diffFrom(MapConfiguration other) {
144158
return MapConfiguration(
159+
webCameraControlPosition:
160+
webCameraControlPosition != other.webCameraControlPosition
161+
? webCameraControlPosition
162+
: null,
163+
webCameraControlEnabled:
164+
webCameraControlEnabled != other.webCameraControlEnabled
165+
? webCameraControlEnabled
166+
: null,
145167
webGestureHandling:
146168
webGestureHandling != other.webGestureHandling
147169
? webGestureHandling
@@ -218,6 +240,10 @@ class MapConfiguration {
218240
/// replacing the previous values.
219241
MapConfiguration applyDiff(MapConfiguration diff) {
220242
return MapConfiguration(
243+
webCameraControlPosition:
244+
diff.webCameraControlPosition ?? webCameraControlPosition,
245+
webCameraControlEnabled:
246+
diff.webCameraControlEnabled ?? webCameraControlEnabled,
221247
webGestureHandling: diff.webGestureHandling ?? webGestureHandling,
222248
compassEnabled: diff.compassEnabled ?? compassEnabled,
223249
mapToolbarEnabled: diff.mapToolbarEnabled ?? mapToolbarEnabled,
@@ -250,6 +276,8 @@ class MapConfiguration {
250276

251277
/// True if no options are set.
252278
bool get isEmpty =>
279+
webCameraControlPosition == null &&
280+
webCameraControlEnabled == null &&
253281
webGestureHandling == null &&
254282
compassEnabled == null &&
255283
mapToolbarEnabled == null &&
@@ -283,6 +311,8 @@ class MapConfiguration {
283311
return false;
284312
}
285313
return other is MapConfiguration &&
314+
webCameraControlPosition == other.webCameraControlPosition &&
315+
webCameraControlEnabled == other.webCameraControlEnabled &&
286316
webGestureHandling == other.webGestureHandling &&
287317
compassEnabled == other.compassEnabled &&
288318
mapToolbarEnabled == other.mapToolbarEnabled &&
@@ -311,6 +341,8 @@ class MapConfiguration {
311341
@override
312342
int get hashCode => Object.hashAll(<Object?>[
313343
webGestureHandling,
344+
webCameraControlPosition,
345+
webCameraControlEnabled,
314346
compassEnabled,
315347
mapToolbarEnabled,
316348
cameraTargetBounds,

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/types.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ export 'utils/marker.dart';
4545
export 'utils/polygon.dart';
4646
export 'utils/polyline.dart';
4747
export 'utils/tile_overlay.dart';
48+
export 'web_camera_control_position.dart';
4849
export 'web_gesture_handling.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// This setting controls how the API handles camera control button on the map.
6+
///
7+
/// See https://developers.google.com/maps/documentation/javascript/reference/control#ControlPosition
8+
/// for more details.
9+
enum WebCameraControlPosition {
10+
/// Equivalent to BOTTOM_CENTER in both LTR and RTL.
11+
blockEndInlineCenter,
12+
13+
/// Equivalent to BOTTOM_LEFT in LTR, or BOTTOM_RIGHT in RTL.
14+
blockEndInlineStart,
15+
16+
/// Equivalent to BOTTOM_RIGHT in LTR, or BOTTOM_LEFT in RTL.
17+
blockEndInlineEnd,
18+
19+
/// Equivalent to TOP_CENTER in both LTR and RTL.
20+
blockStartInlineCenter,
21+
22+
/// Equivalent to TOP_LEFT in LTR, or TOP_RIGHT in RTL.
23+
blockStartInlineStart,
24+
25+
/// Equivalent to TOP_RIGHT in LTR, or TOP_LEFT in RTL.
26+
blockStartInlineEnd,
27+
28+
/// Elements are positioned in the center of the bottom row.
29+
///
30+
/// Consider using BLOCK_END_INLINE_CENTER instead.
31+
bottomCenter,
32+
33+
/// Elements are positioned in the bottom left and flow towards the middle.
34+
///
35+
/// Elements are positioned to the right of the Google logo.
36+
///
37+
/// Consider using BLOCK_END_INLINE_START instead.
38+
bottomLeft,
39+
40+
/// Elements are positioned in the bottom right and flow towards the middle.
41+
///
42+
/// Elements are positioned to the left of the copyrights.
43+
///
44+
/// Consider using BLOCK_END_INLINE_END instead.
45+
bottomRight,
46+
47+
/// Equivalent to RIGHT_CENTER in LTR, or LEFT_CENTER in RTL.
48+
inlineEndBlockCenter,
49+
50+
/// Equivalent to RIGHT_BOTTOM in LTR, or LEFT_BOTTOM in RTL.
51+
inlineEndBlockEnd,
52+
53+
/// Equivalent to RIGHT_TOP in LTR, or LEFT_TOP in RTL.
54+
inlineEndBlockStart,
55+
56+
/// Equivalent to LEFT_CENTER in LTR, or RIGHT_CENTER in RTL.
57+
inlineStartBlockCenter,
58+
59+
/// Equivalent to LEFT_BOTTOM in LTR, or RIGHT_BOTTOM in RTL.
60+
inlineStartBlockEnd,
61+
62+
/// Equivalent to LEFT_TOP in LTR, or RIGHT_TOP in RTL.
63+
inlineStartBlockStart,
64+
65+
/// Elements are positioned on the left, above bottom-left elements,
66+
/// and flow upwards.
67+
///
68+
/// Consider using INLINE_START_BLOCK_END instead.
69+
leftBottom,
70+
71+
/// Elements are positioned in the center of the left side.
72+
/// Consider using INLINE_START_BLOCK_CENTER instead.
73+
leftCenter,
74+
75+
/// Elements are positioned on the left, below top-left elements,
76+
/// and flow downwards.
77+
///
78+
/// Consider using INLINE_START_BLOCK_START instead.
79+
leftTop,
80+
81+
/// Elements are positioned on the right, above bottom-right elements,
82+
/// and flow upwards.
83+
///
84+
/// Consider using INLINE_END_BLOCK_END instead.
85+
rightBottom,
86+
87+
/// Elements are positioned in the center of the right side.
88+
///
89+
/// Consider using INLINE_END_BLOCK_CENTER instead.
90+
rightCenter,
91+
92+
/// Elements are positioned on the right, below top-right elements,
93+
/// and flow downwards.
94+
///
95+
/// Consider using INLINE_END_BLOCK_START instead.
96+
rightTop,
97+
98+
/// Elements are positioned in the center of the top row.
99+
///
100+
/// Consider using BLOCK_START_INLINE_CENTER instead.
101+
topCenter,
102+
103+
/// Elements are positioned in the top left and flow towards the middle.
104+
///
105+
/// Consider using BLOCK_START_INLINE_START instead.
106+
topLeft,
107+
108+
/// Elements are positioned in the top right and flow towards the middle.
109+
///
110+
/// Consider using BLOCK_START_INLINE_END instead.
111+
topRight,
112+
}

packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/google_maps_f
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.13.0
7+
version: 2.14.0
88

99
environment:
1010
sdk: ^3.7.0

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/map_configuration_test.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ void main() {
1212
group('diffs', () {
1313
// A options instance with every field set, to test diffs against.
1414
final MapConfiguration diffBase = MapConfiguration(
15+
webCameraControlPosition: WebCameraControlPosition.topRight,
16+
webCameraControlEnabled: false,
1517
webGestureHandling: WebGestureHandling.auto,
1618
compassEnabled: false,
1719
mapToolbarEnabled: false,
@@ -62,6 +64,8 @@ void main() {
6264
expect(updated.liteModeEnabled, isNot(null));
6365
expect(updated.padding, isNot(null));
6466
expect(updated.trafficEnabled, isNot(null));
67+
expect(updated.cloudMapId, null);
68+
expect(updated.webCameraControlPosition, isNot(null));
6569
expect(updated.mapId, null);
6670
});
6771

@@ -83,6 +87,45 @@ void main() {
8387
expect(empty.hashCode, isNot(diff.hashCode));
8488
});
8589

90+
test('handle webCameraControlPosition', () async {
91+
const MapConfiguration diff = MapConfiguration(
92+
webCameraControlPosition: WebCameraControlPosition.blockEndInlineEnd,
93+
);
94+
95+
const MapConfiguration empty = MapConfiguration();
96+
final MapConfiguration updated = diffBase.applyDiff(diff);
97+
98+
// A diff applied to empty options should be the diff itself.
99+
expect(empty.applyDiff(diff), diff);
100+
// The diff from empty options should be the diff itself.
101+
expect(diff.diffFrom(empty), diff);
102+
// A diff applied to non-empty options should update that field.
103+
expect(
104+
updated.webCameraControlPosition,
105+
WebCameraControlPosition.blockEndInlineEnd,
106+
);
107+
// The hash code should change.
108+
expect(empty.hashCode, isNot(diff.hashCode));
109+
});
110+
111+
test('handle webCameraControlEnabled', () async {
112+
const MapConfiguration diff = MapConfiguration(
113+
webCameraControlEnabled: true,
114+
);
115+
116+
const MapConfiguration empty = MapConfiguration();
117+
final MapConfiguration updated = diffBase.applyDiff(diff);
118+
119+
// A diff applied to empty options should be the diff itself.
120+
expect(empty.applyDiff(diff), diff);
121+
// The diff from empty options should be the diff itself.
122+
expect(diff.diffFrom(empty), diff);
123+
// A diff applied to non-empty options should update that field.
124+
expect(updated.webCameraControlEnabled, true);
125+
// The hash code should change.
126+
expect(empty.hashCode, isNot(diff.hashCode));
127+
});
128+
86129
test('handle compassEnabled', () async {
87130
const MapConfiguration diff = MapConfiguration(compassEnabled: true);
88131

@@ -470,6 +513,22 @@ void main() {
470513
expect(nullOptions.isEmpty, true);
471514
});
472515

516+
test('is false with webCameraControlEnabled', () async {
517+
const MapConfiguration diff = MapConfiguration(
518+
webCameraControlEnabled: true,
519+
);
520+
521+
expect(diff.isEmpty, false);
522+
});
523+
524+
test('is false with webCameraControlPosition', () async {
525+
const MapConfiguration diff = MapConfiguration(
526+
webCameraControlPosition: WebCameraControlPosition.blockEndInlineCenter,
527+
);
528+
529+
expect(diff.isEmpty, false);
530+
});
531+
473532
test('is false with compassEnabled', () async {
474533
const MapConfiguration diff = MapConfiguration(compassEnabled: true);
475534

0 commit comments

Comments
 (0)