Skip to content

Commit 499b82b

Browse files
committed
Add support for getClusters method to the google_maps_inpector_web
1 parent 7f1a493 commit 499b82b

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

packages/google_maps_flutter/google_maps_flutter/example/integration_test/src/maps_inspector.dart

+9-8
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,9 @@ void runTests() {
565565
final Completer<GoogleMapController> controllerCompleter =
566566
Completer<GoogleMapController>();
567567

568-
await tester.pumpWidget(Directionality(
569-
textDirection: TextDirection.ltr,
570-
child: GoogleMap(
568+
await pumpMap(
569+
tester,
570+
GoogleMap(
571571
key: key,
572572
initialCameraPosition: kInitialCameraPosition,
573573
clusterManagers: clusterManagers,
@@ -576,7 +576,7 @@ void runTests() {
576576
controllerCompleter.complete(googleMapController);
577577
},
578578
),
579-
));
579+
);
580580

581581
final GoogleMapController controller = await controllerCompleter.future;
582582

@@ -596,14 +596,15 @@ void runTests() {
596596
for (final MapEntry<MarkerId, Marker> entry in markers.entries) {
597597
markers[entry.key] = _copyMarkerWithClusterManagerId(entry.value, null);
598598
}
599-
await tester.pumpWidget(Directionality(
600-
textDirection: TextDirection.ltr,
601-
child: GoogleMap(
599+
600+
await pumpMap(
601+
tester,
602+
GoogleMap(
602603
key: key,
603604
initialCameraPosition: kInitialCameraPosition,
604605
clusterManagers: clusterManagers,
605606
markers: Set<Marker>.of(markers.values)),
606-
));
607+
);
607608

608609
for (final ClusterManager cm in clusterManagers) {
609610
final List<Cluster> clusters = await inspector.getClusters(

packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/markers_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ void main() {
353353
expect((event as InfoWindowTapEvent).value, equals(const MarkerId('1')));
354354
});
355355

356-
testWidgets('clustering', (WidgetTester tester) async {
356+
testWidgets('marker clustering', (WidgetTester tester) async {
357357
const ClusterManagerId clusterManagerId = ClusterManagerId('cluster 1');
358358

359359
final Set<ClusterManager> clusterManagers = <ClusterManager>{
@@ -381,7 +381,7 @@ void main() {
381381

382382
expect(clusters.length, 1);
383383

384-
// Update the marker with null clusterManagerId.
384+
// Copy the marker with null clusterManagerId.
385385
final Set<Marker> updatedMarkers = <Marker>{
386386
_copyMarkerWithClusterManagerId(markers.first, null)
387387
};

packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_controller.dart

+5
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ class GoogleMapController {
122122
// Keeps track if the map is moving or not.
123123
bool _mapIsMoving = false;
124124

125+
/// The ClusterManagersController of this Map. Only for integration testing.
126+
@visibleForTesting
127+
ClusterManagersController? get clusterManagersController =>
128+
_clusterManagersController;
129+
125130
/// Overrides certain properties to install mocks defined during testing.
126131
@visibleForTesting
127132
void debugSetOverrides({

packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_flutter_web.dart

+1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ class GoogleMapsPlugin extends GoogleMapsFlutterPlatform {
347347
void enableDebugInspection() {
348348
GoogleMapsInspectorPlatform.instance = GoogleMapsInspectorWeb(
349349
(int mapId) => _map(mapId).configuration,
350+
(int mapId) => _map(mapId).clusterManagersController,
350351
);
351352
}
352353
}

packages/google_maps_flutter/google_maps_flutter_web/lib/src/google_maps_inspector_web.dart

+20-2
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
// found in the LICENSE file.
44

55
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
6+
import '../google_maps_flutter_web.dart';
67

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

11+
/// Function that gets the [ClusterManagersController] for a given `mapId`.
12+
typedef ClusterManagersControllerProvider = ClusterManagersController? Function(
13+
int mapId);
14+
1015
/// This platform implementation allows inspecting the running maps.
1116
class GoogleMapsInspectorWeb extends GoogleMapsInspectorPlatform {
1217
/// Build an "inspector" that is able to look into maps.
13-
GoogleMapsInspectorWeb(ConfigurationProvider configurationProvider)
14-
: _configurationProvider = configurationProvider;
18+
GoogleMapsInspectorWeb(ConfigurationProvider configurationProvider,
19+
ClusterManagersControllerProvider clusterManagersControllerProvider)
20+
: _configurationProvider = configurationProvider,
21+
_clusterManagersControllerProvider = clusterManagersControllerProvider;
1522

1623
final ConfigurationProvider _configurationProvider;
24+
final ClusterManagersControllerProvider _clusterManagersControllerProvider;
1725

1826
@override
1927
Future<bool> areBuildingsEnabled({required int mapId}) async {
@@ -85,4 +93,14 @@ class GoogleMapsInspectorWeb extends GoogleMapsInspectorPlatform {
8593
Future<bool> isTrafficEnabled({required int mapId}) async {
8694
return _configurationProvider(mapId).trafficEnabled ?? false;
8795
}
96+
97+
@override
98+
Future<List<Cluster>> getClusters({
99+
required int mapId,
100+
required ClusterManagerId clusterManagerId,
101+
}) async {
102+
return _clusterManagersControllerProvider(mapId)
103+
?.getClusters(clusterManagerId) ??
104+
<Cluster>[];
105+
}
88106
}

0 commit comments

Comments
 (0)