Skip to content

[google_maps_flutter_platform_interface] Add support for cloud-based map styling #4141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,3 +1,7 @@
## 2.3.0

* Adds a `cloudMapId` parameter to support cloud-based map styling.

## 2.2.7

* Removes obsolete null checks on non-nullable values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MapConfiguration {
this.indoorViewEnabled,
this.trafficEnabled,
this.buildingsEnabled,
this.cloudMapId,
});

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

/// Identifier that's associated with a specific cloud-based map style.
///
/// See https://developers.google.com/maps/documentation/get-map-id
/// for more details.
final String? cloudMapId;

/// Returns a new options object containing only the values of this instance
/// that are different from [other].
MapConfiguration diffFrom(MapConfiguration other) {
Expand Down Expand Up @@ -143,6 +150,7 @@ class MapConfiguration {
trafficEnabled != other.trafficEnabled ? trafficEnabled : null,
buildingsEnabled:
buildingsEnabled != other.buildingsEnabled ? buildingsEnabled : null,
cloudMapId: cloudMapId != other.cloudMapId ? cloudMapId : null,
);
}

Expand Down Expand Up @@ -171,6 +179,7 @@ class MapConfiguration {
indoorViewEnabled: diff.indoorViewEnabled ?? indoorViewEnabled,
trafficEnabled: diff.trafficEnabled ?? trafficEnabled,
buildingsEnabled: diff.buildingsEnabled ?? buildingsEnabled,
cloudMapId: diff.cloudMapId ?? cloudMapId,
);
}

Expand All @@ -193,7 +202,8 @@ class MapConfiguration {
padding == null &&
indoorViewEnabled == null &&
trafficEnabled == null &&
buildingsEnabled == null;
buildingsEnabled == null &&
cloudMapId == null;

@override
bool operator ==(Object other) {
Expand Down Expand Up @@ -221,7 +231,8 @@ class MapConfiguration {
padding == other.padding &&
indoorViewEnabled == other.indoorViewEnabled &&
trafficEnabled == other.trafficEnabled &&
buildingsEnabled == other.buildingsEnabled;
buildingsEnabled == other.buildingsEnabled &&
cloudMapId == other.cloudMapId;
}

@override
Expand All @@ -244,5 +255,6 @@ class MapConfiguration {
indoorViewEnabled,
trafficEnabled,
buildingsEnabled,
cloudMapId,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ Map<String, Object> jsonForMapConfiguration(MapConfiguration config) {
if (config.trafficEnabled != null) 'trafficEnabled': config.trafficEnabled!,
if (config.buildingsEnabled != null)
'buildingsEnabled': config.buildingsEnabled!,
if (config.cloudMapId != null) 'cloudMapId': config.cloudMapId!,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/google_maps_f
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.2.7
version: 2.3.0

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';

const String _kCloudMapId = '000000000000000'; // Dummy map ID.

void main() {
group('diffs', () {
// A options instance with every field set, to test diffs against.
Expand Down Expand Up @@ -53,6 +55,7 @@ void main() {
expect(updated.liteModeEnabled, isNot(null));
expect(updated.padding, isNot(null));
expect(updated.trafficEnabled, isNot(null));
expect(updated.cloudMapId, null);
});

test('handle compassEnabled', () async {
Expand Down Expand Up @@ -281,6 +284,18 @@ void main() {
// A diff applied to non-empty options should update that field.
expect(updated.buildingsEnabled, true);
});

test('handle cloudMapId', () async {
const MapConfiguration diff = MapConfiguration(cloudMapId: _kCloudMapId);

const MapConfiguration empty = MapConfiguration();
final MapConfiguration updated = diffBase.applyDiff(diff);

// A diff applied to empty options should be the diff itself.
expect(empty.applyDiff(diff), diff);
// A diff applied to non-empty options should update that field.
expect(updated.cloudMapId, _kCloudMapId);
});
});

group('isEmpty', () {
Expand Down Expand Up @@ -408,5 +423,11 @@ void main() {

expect(diff.isEmpty, false);
});

test('is false with cloudMapId', () async {
const MapConfiguration diff = MapConfiguration(cloudMapId: _kCloudMapId);

expect(diff.isEmpty, false);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import 'package:google_maps_flutter_platform_interface/src/types/utils/map_configuration_serialization.dart';

const String _kCloudMapId = '000000000000000'; // Dummy map ID.

void main() {
test('empty serialization', () async {
const MapConfiguration config = MapConfiguration();
Expand All @@ -18,26 +20,26 @@ void main() {

test('complete serialization', () async {
final MapConfiguration config = MapConfiguration(
compassEnabled: false,
mapToolbarEnabled: false,
cameraTargetBounds: CameraTargetBounds(LatLngBounds(
northeast: const LatLng(30, 20), southwest: const LatLng(10, 40))),
mapType: MapType.normal,
minMaxZoomPreference: const MinMaxZoomPreference(1.0, 10.0),
rotateGesturesEnabled: false,
scrollGesturesEnabled: false,
tiltGesturesEnabled: false,
trackCameraPosition: false,
zoomControlsEnabled: false,
zoomGesturesEnabled: false,
liteModeEnabled: false,
myLocationEnabled: false,
myLocationButtonEnabled: false,
padding: const EdgeInsets.all(5.0),
indoorViewEnabled: false,
trafficEnabled: false,
buildingsEnabled: false,
);
compassEnabled: false,
mapToolbarEnabled: false,
cameraTargetBounds: CameraTargetBounds(LatLngBounds(
northeast: const LatLng(30, 20), southwest: const LatLng(10, 40))),
mapType: MapType.normal,
minMaxZoomPreference: const MinMaxZoomPreference(1.0, 10.0),
rotateGesturesEnabled: false,
scrollGesturesEnabled: false,
tiltGesturesEnabled: false,
trackCameraPosition: false,
zoomControlsEnabled: false,
zoomGesturesEnabled: false,
liteModeEnabled: false,
myLocationEnabled: false,
myLocationButtonEnabled: false,
padding: const EdgeInsets.all(5.0),
indoorViewEnabled: false,
trafficEnabled: false,
buildingsEnabled: false,
cloudMapId: _kCloudMapId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a trailing comma here.


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

Expand Down Expand Up @@ -69,7 +71,8 @@ void main() {
'padding': <double>[5.0, 5.0, 5.0, 5.0],
'indoorEnabled': false,
'trafficEnabled': false,
'buildingsEnabled': false
'buildingsEnabled': false,
'cloudMapId': _kCloudMapId
});
});
}