Skip to content

Commit

Permalink
Add support for getClusters method to the google_maps_inpector_web
Browse files Browse the repository at this point in the history
  • Loading branch information
jokerttu committed Jun 27, 2023
1 parent 7f1a493 commit 499b82b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,9 @@ void runTests() {
final Completer<GoogleMapController> controllerCompleter =
Completer<GoogleMapController>();

await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: GoogleMap(
await pumpMap(
tester,
GoogleMap(
key: key,
initialCameraPosition: kInitialCameraPosition,
clusterManagers: clusterManagers,
Expand All @@ -576,7 +576,7 @@ void runTests() {
controllerCompleter.complete(googleMapController);
},
),
));
);

final GoogleMapController controller = await controllerCompleter.future;

Expand All @@ -596,14 +596,15 @@ void runTests() {
for (final MapEntry<MarkerId, Marker> entry in markers.entries) {
markers[entry.key] = _copyMarkerWithClusterManagerId(entry.value, null);
}
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: GoogleMap(

await pumpMap(
tester,
GoogleMap(
key: key,
initialCameraPosition: kInitialCameraPosition,
clusterManagers: clusterManagers,
markers: Set<Marker>.of(markers.values)),
));
);

for (final ClusterManager cm in clusterManagers) {
final List<Cluster> clusters = await inspector.getClusters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void main() {
expect((event as InfoWindowTapEvent).value, equals(const MarkerId('1')));
});

testWidgets('clustering', (WidgetTester tester) async {
testWidgets('marker clustering', (WidgetTester tester) async {
const ClusterManagerId clusterManagerId = ClusterManagerId('cluster 1');

final Set<ClusterManager> clusterManagers = <ClusterManager>{
Expand Down Expand Up @@ -381,7 +381,7 @@ void main() {

expect(clusters.length, 1);

// Update the marker with null clusterManagerId.
// Copy the marker with null clusterManagerId.
final Set<Marker> updatedMarkers = <Marker>{
_copyMarkerWithClusterManagerId(markers.first, null)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ class GoogleMapController {
// Keeps track if the map is moving or not.
bool _mapIsMoving = false;

/// The ClusterManagersController of this Map. Only for integration testing.
@visibleForTesting
ClusterManagersController? get clusterManagersController =>
_clusterManagersController;

/// Overrides certain properties to install mocks defined during testing.
@visibleForTesting
void debugSetOverrides({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform {
void enableDebugInspection() {
GoogleMapsInspectorPlatform.instance = GoogleMapsInspectorWeb(
(int mapId) => _map(mapId).configuration,
(int mapId) => _map(mapId).clusterManagersController,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
// found in the LICENSE file.

import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
import '../google_maps_flutter_web.dart';

/// Function that gets the [MapConfiguration] for a given `mapId`.
typedef ConfigurationProvider = MapConfiguration Function(int mapId);

/// Function that gets the [ClusterManagersController] for a given `mapId`.
typedef ClusterManagersControllerProvider = ClusterManagersController? Function(
int mapId);

/// This platform implementation allows inspecting the running maps.
class GoogleMapsInspectorWeb extends GoogleMapsInspectorPlatform {
/// Build an "inspector" that is able to look into maps.
GoogleMapsInspectorWeb(ConfigurationProvider configurationProvider)
: _configurationProvider = configurationProvider;
GoogleMapsInspectorWeb(ConfigurationProvider configurationProvider,
ClusterManagersControllerProvider clusterManagersControllerProvider)
: _configurationProvider = configurationProvider,
_clusterManagersControllerProvider = clusterManagersControllerProvider;

final ConfigurationProvider _configurationProvider;
final ClusterManagersControllerProvider _clusterManagersControllerProvider;

@override
Future<bool> areBuildingsEnabled({required int mapId}) async {
Expand Down Expand Up @@ -85,4 +93,14 @@ class GoogleMapsInspectorWeb extends GoogleMapsInspectorPlatform {
Future<bool> isTrafficEnabled({required int mapId}) async {
return _configurationProvider(mapId).trafficEnabled ?? false;
}

@override
Future<List<Cluster>> getClusters({
required int mapId,
required ClusterManagerId clusterManagerId,
}) async {
return _clusterManagersControllerProvider(mapId)
?.getClusters(clusterManagerId) ??
<Cluster>[];
}
}

0 comments on commit 499b82b

Please sign in to comment.