Skip to content

Commit 77bb4d9

Browse files
authored
[google_maps_flutter_platform_interface] Add support for cloud-based map styling (#4141)
This PR is sub-PR splitted out from the #3682 containing only the platform_interface package changes. Related to issue flutter/flutter#67631
1 parent 13557d6 commit 77bb4d9

File tree

6 files changed

+65
-24
lines changed

6 files changed

+65
-24
lines changed

packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.0
2+
3+
* Adds a `cloudMapId` parameter to support cloud-based map styling.
4+
15
## 2.2.7
26

37
* Removes obsolete null checks on non-nullable values.

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class MapConfiguration {
3333
this.indoorViewEnabled,
3434
this.trafficEnabled,
3535
this.buildingsEnabled,
36+
this.cloudMapId,
3637
});
3738

3839
/// True if the compass UI should be shown.
@@ -90,6 +91,12 @@ class MapConfiguration {
9091
/// True if 3D building display should be enabled.
9192
final bool? buildingsEnabled;
9293

94+
/// Identifier that's associated with a specific cloud-based map style.
95+
///
96+
/// See https://developers.google.com/maps/documentation/get-map-id
97+
/// for more details.
98+
final String? cloudMapId;
99+
93100
/// Returns a new options object containing only the values of this instance
94101
/// that are different from [other].
95102
MapConfiguration diffFrom(MapConfiguration other) {
@@ -143,6 +150,7 @@ class MapConfiguration {
143150
trafficEnabled != other.trafficEnabled ? trafficEnabled : null,
144151
buildingsEnabled:
145152
buildingsEnabled != other.buildingsEnabled ? buildingsEnabled : null,
153+
cloudMapId: cloudMapId != other.cloudMapId ? cloudMapId : null,
146154
);
147155
}
148156

@@ -171,6 +179,7 @@ class MapConfiguration {
171179
indoorViewEnabled: diff.indoorViewEnabled ?? indoorViewEnabled,
172180
trafficEnabled: diff.trafficEnabled ?? trafficEnabled,
173181
buildingsEnabled: diff.buildingsEnabled ?? buildingsEnabled,
182+
cloudMapId: diff.cloudMapId ?? cloudMapId,
174183
);
175184
}
176185

@@ -193,7 +202,8 @@ class MapConfiguration {
193202
padding == null &&
194203
indoorViewEnabled == null &&
195204
trafficEnabled == null &&
196-
buildingsEnabled == null;
205+
buildingsEnabled == null &&
206+
cloudMapId == null;
197207

198208
@override
199209
bool operator ==(Object other) {
@@ -221,7 +231,8 @@ class MapConfiguration {
221231
padding == other.padding &&
222232
indoorViewEnabled == other.indoorViewEnabled &&
223233
trafficEnabled == other.trafficEnabled &&
224-
buildingsEnabled == other.buildingsEnabled;
234+
buildingsEnabled == other.buildingsEnabled &&
235+
cloudMapId == other.cloudMapId;
225236
}
226237

227238
@override
@@ -244,5 +255,6 @@ class MapConfiguration {
244255
indoorViewEnabled,
245256
trafficEnabled,
246257
buildingsEnabled,
258+
cloudMapId,
247259
);
248260
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ Map<String, Object> jsonForMapConfiguration(MapConfiguration config) {
5858
if (config.trafficEnabled != null) 'trafficEnabled': config.trafficEnabled!,
5959
if (config.buildingsEnabled != null)
6060
'buildingsEnabled': config.buildingsEnabled!,
61+
if (config.cloudMapId != null) 'cloudMapId': config.cloudMapId!,
6162
};
6263
}

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.2.7
7+
version: 2.3.0
88

99
environment:
1010
sdk: ">=2.18.0 <4.0.0"

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
66
import 'package:flutter_test/flutter_test.dart';
77
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
88

9+
const String _kCloudMapId = '000000000000000'; // Dummy map ID.
10+
911
void main() {
1012
group('diffs', () {
1113
// A options instance with every field set, to test diffs against.
@@ -53,6 +55,7 @@ void main() {
5355
expect(updated.liteModeEnabled, isNot(null));
5456
expect(updated.padding, isNot(null));
5557
expect(updated.trafficEnabled, isNot(null));
58+
expect(updated.cloudMapId, null);
5659
});
5760

5861
test('handle compassEnabled', () async {
@@ -281,6 +284,18 @@ void main() {
281284
// A diff applied to non-empty options should update that field.
282285
expect(updated.buildingsEnabled, true);
283286
});
287+
288+
test('handle cloudMapId', () async {
289+
const MapConfiguration diff = MapConfiguration(cloudMapId: _kCloudMapId);
290+
291+
const MapConfiguration empty = MapConfiguration();
292+
final MapConfiguration updated = diffBase.applyDiff(diff);
293+
294+
// A diff applied to empty options should be the diff itself.
295+
expect(empty.applyDiff(diff), diff);
296+
// A diff applied to non-empty options should update that field.
297+
expect(updated.cloudMapId, _kCloudMapId);
298+
});
284299
});
285300

286301
group('isEmpty', () {
@@ -408,5 +423,11 @@ void main() {
408423

409424
expect(diff.isEmpty, false);
410425
});
426+
427+
test('is false with cloudMapId', () async {
428+
const MapConfiguration diff = MapConfiguration(cloudMapId: _kCloudMapId);
429+
430+
expect(diff.isEmpty, false);
431+
});
411432
});
412433
}

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/utils/map_configuration_serialization_test.dart

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'package:flutter_test/flutter_test.dart';
77
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
88
import 'package:google_maps_flutter_platform_interface/src/types/utils/map_configuration_serialization.dart';
99

10+
const String _kCloudMapId = '000000000000000'; // Dummy map ID.
11+
1012
void main() {
1113
test('empty serialization', () async {
1214
const MapConfiguration config = MapConfiguration();
@@ -18,26 +20,26 @@ void main() {
1820

1921
test('complete serialization', () async {
2022
final MapConfiguration config = MapConfiguration(
21-
compassEnabled: false,
22-
mapToolbarEnabled: false,
23-
cameraTargetBounds: CameraTargetBounds(LatLngBounds(
24-
northeast: const LatLng(30, 20), southwest: const LatLng(10, 40))),
25-
mapType: MapType.normal,
26-
minMaxZoomPreference: const MinMaxZoomPreference(1.0, 10.0),
27-
rotateGesturesEnabled: false,
28-
scrollGesturesEnabled: false,
29-
tiltGesturesEnabled: false,
30-
trackCameraPosition: false,
31-
zoomControlsEnabled: false,
32-
zoomGesturesEnabled: false,
33-
liteModeEnabled: false,
34-
myLocationEnabled: false,
35-
myLocationButtonEnabled: false,
36-
padding: const EdgeInsets.all(5.0),
37-
indoorViewEnabled: false,
38-
trafficEnabled: false,
39-
buildingsEnabled: false,
40-
);
23+
compassEnabled: false,
24+
mapToolbarEnabled: false,
25+
cameraTargetBounds: CameraTargetBounds(LatLngBounds(
26+
northeast: const LatLng(30, 20), southwest: const LatLng(10, 40))),
27+
mapType: MapType.normal,
28+
minMaxZoomPreference: const MinMaxZoomPreference(1.0, 10.0),
29+
rotateGesturesEnabled: false,
30+
scrollGesturesEnabled: false,
31+
tiltGesturesEnabled: false,
32+
trackCameraPosition: false,
33+
zoomControlsEnabled: false,
34+
zoomGesturesEnabled: false,
35+
liteModeEnabled: false,
36+
myLocationEnabled: false,
37+
myLocationButtonEnabled: false,
38+
padding: const EdgeInsets.all(5.0),
39+
indoorViewEnabled: false,
40+
trafficEnabled: false,
41+
buildingsEnabled: false,
42+
cloudMapId: _kCloudMapId);
4143

4244
final Map<String, Object> json = jsonForMapConfiguration(config);
4345

@@ -69,7 +71,8 @@ void main() {
6971
'padding': <double>[5.0, 5.0, 5.0, 5.0],
7072
'indoorEnabled': false,
7173
'trafficEnabled': false,
72-
'buildingsEnabled': false
74+
'buildingsEnabled': false,
75+
'cloudMapId': _kCloudMapId
7376
});
7477
});
7578
}

0 commit comments

Comments
 (0)