Skip to content

Commit cc42eb1

Browse files
committed
[google_maps_flutter_ios] Add support for cluster markering
1 parent 268f7d5 commit cc42eb1

31 files changed

+1112
-53
lines changed

packages/google_maps_flutter/google_maps_flutter_ios/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ Anton Borries <[email protected]>
6565
6666
Rahul Raj <[email protected]>
6767
Taha Tesser <[email protected]>
68+
Joonas Kerttula <[email protected]>

packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.6.0
2+
3+
* Adds support for marker clustering.
4+
15
## 2.5.0
26

37
* Adds support for `MapConfiguration.style`.

packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/integration_test/google_maps_test.dart

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,85 @@ void main() {
10401040
},
10411041
);
10421042

1043+
testWidgets('marker clustering', (WidgetTester tester) async {
1044+
final Key key = GlobalKey();
1045+
const int clusterManagersAmount = 2;
1046+
const int markersPerClusterManager = 5;
1047+
final Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
1048+
final Set<ClusterManager> clusterManagers = <ClusterManager>{};
1049+
1050+
for (int i = 0; i < clusterManagersAmount; i++) {
1051+
final ClusterManagerId clusterManagerId =
1052+
ClusterManagerId('cluster_manager_$i');
1053+
final ClusterManager clusterManager =
1054+
ClusterManager(clusterManagerId: clusterManagerId);
1055+
clusterManagers.add(clusterManager);
1056+
}
1057+
1058+
for (final ClusterManager cm in clusterManagers) {
1059+
for (int i = 0; i < markersPerClusterManager; i++) {
1060+
final MarkerId markerId =
1061+
MarkerId('${cm.clusterManagerId.value}_marker_$i');
1062+
final Marker marker = Marker(
1063+
markerId: markerId,
1064+
clusterManagerId: cm.clusterManagerId,
1065+
position: LatLng(
1066+
_kInitialMapCenter.latitude + i, _kInitialMapCenter.longitude));
1067+
markers[markerId] = marker;
1068+
}
1069+
}
1070+
1071+
final Completer<ExampleGoogleMapController> controllerCompleter =
1072+
Completer<ExampleGoogleMapController>();
1073+
1074+
final GoogleMapsInspectorPlatform inspector =
1075+
GoogleMapsInspectorPlatform.instance!;
1076+
1077+
await tester.pumpWidget(Directionality(
1078+
textDirection: TextDirection.ltr,
1079+
child: ExampleGoogleMap(
1080+
key: key,
1081+
initialCameraPosition: _kInitialCameraPosition,
1082+
clusterManagers: clusterManagers,
1083+
markers: Set<Marker>.of(markers.values),
1084+
onMapCreated: (ExampleGoogleMapController googleMapController) {
1085+
controllerCompleter.complete(googleMapController);
1086+
},
1087+
),
1088+
));
1089+
1090+
final ExampleGoogleMapController controller =
1091+
await controllerCompleter.future;
1092+
1093+
for (final ClusterManager cm in clusterManagers) {
1094+
final List<Cluster> clusters = await inspector.getClusters(
1095+
mapId: controller.mapId, clusterManagerId: cm.clusterManagerId);
1096+
final int markersAmountForClusterManager = clusters
1097+
.map<int>((Cluster cluster) => cluster.count)
1098+
.reduce((int value, int element) => value + element);
1099+
expect(markersAmountForClusterManager, markersPerClusterManager);
1100+
}
1101+
1102+
// Remove markers from clusterManagers and test that clusterManagers are empty.
1103+
for (final MapEntry<MarkerId, Marker> entry in markers.entries) {
1104+
markers[entry.key] = _copyMarkerWithClusterManagerId(entry.value, null);
1105+
}
1106+
await tester.pumpWidget(Directionality(
1107+
textDirection: TextDirection.ltr,
1108+
child: ExampleGoogleMap(
1109+
key: key,
1110+
initialCameraPosition: _kInitialCameraPosition,
1111+
clusterManagers: clusterManagers,
1112+
markers: Set<Marker>.of(markers.values)),
1113+
));
1114+
1115+
for (final ClusterManager cm in clusterManagers) {
1116+
final List<Cluster> clusters = await inspector.getClusters(
1117+
mapId: controller.mapId, clusterManagerId: cm.clusterManagerId);
1118+
expect(clusters.length, 0);
1119+
}
1120+
});
1121+
10431122
testWidgets('testSetStyleMapId', (WidgetTester tester) async {
10441123
final Key key = GlobalKey();
10451124

@@ -1145,3 +1224,26 @@ class _DebugTileProvider implements TileProvider {
11451224
return Tile(width, height, byteData);
11461225
}
11471226
}
1227+
1228+
Marker _copyMarkerWithClusterManagerId(
1229+
Marker marker, ClusterManagerId? clusterManagerId) {
1230+
return Marker(
1231+
markerId: marker.markerId,
1232+
alpha: marker.alpha,
1233+
anchor: marker.anchor,
1234+
consumeTapEvents: marker.consumeTapEvents,
1235+
draggable: marker.draggable,
1236+
flat: marker.flat,
1237+
icon: marker.icon,
1238+
infoWindow: marker.infoWindow,
1239+
position: marker.position,
1240+
rotation: marker.rotation,
1241+
visible: marker.visible,
1242+
zIndex: marker.zIndex,
1243+
onTap: marker.onTap,
1244+
onDragStart: marker.onDragStart,
1245+
onDrag: marker.onDrag,
1246+
onDragEnd: marker.onDragEnd,
1247+
clusterManagerId: clusterManagerId,
1248+
);
1249+
}

packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:flutter/material.dart';
66
import 'package:maps_example_dart/animate_camera.dart';
7+
import 'package:maps_example_dart/clustering.dart';
78
import 'package:maps_example_dart/lite_mode.dart';
89
import 'package:maps_example_dart/map_click.dart';
910
import 'package:maps_example_dart/map_coordinates.dart';
@@ -40,6 +41,7 @@ void main() {
4041
SnapshotPage(),
4142
LiteModePage(),
4243
TileOverlayPage(),
44+
ClusteringPage(),
4345
MapIdPage(),
4446
])));
4547
}

packages/google_maps_flutter/google_maps_flutter_ios/example/ios12/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
# The example app is bundled with the plugin so we use a path dependency on
1919
# the parent directory to use the current plugin's version.
2020
path: ../../
21-
google_maps_flutter_platform_interface: ^2.5.0
21+
google_maps_flutter_platform_interface: ^2.6.0
2222
maps_example_dart:
2323
path: ../shared/maps_example_dart/
2424

packages/google_maps_flutter/google_maps_flutter_ios/example/ios13/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:flutter/material.dart';
66
import 'package:maps_example_dart/animate_camera.dart';
7+
import 'package:maps_example_dart/clustering.dart';
78
import 'package:maps_example_dart/lite_mode.dart';
89
import 'package:maps_example_dart/map_click.dart';
910
import 'package:maps_example_dart/map_coordinates.dart';
@@ -39,6 +40,7 @@ void main() {
3940
PaddingPage(),
4041
SnapshotPage(),
4142
LiteModePage(),
43+
ClusteringPage(),
4244
TileOverlayPage(),
4345
MapIdPage(),
4446
])));

packages/google_maps_flutter/google_maps_flutter_ios/example/ios13/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
# The example app is bundled with the plugin so we use a path dependency on
1919
# the parent directory to use the current plugin's version.
2020
path: ../../
21-
google_maps_flutter_platform_interface: ^2.5.0
21+
google_maps_flutter_platform_interface: ^2.6.0
2222
maps_example_dart:
2323
path: ../shared/maps_example_dart/
2424

packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:flutter/material.dart';
66
import 'package:maps_example_dart/animate_camera.dart';
7+
import 'package:maps_example_dart/clustering.dart';
78
import 'package:maps_example_dart/lite_mode.dart';
89
import 'package:maps_example_dart/map_click.dart';
910
import 'package:maps_example_dart/map_coordinates.dart';
@@ -40,6 +41,7 @@ void main() {
4041
SnapshotPage(),
4142
LiteModePage(),
4243
TileOverlayPage(),
44+
ClusteringPage(),
4345
MapIdPage(),
4446
])));
4547
}

packages/google_maps_flutter/google_maps_flutter_ios/example/ios14/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
# The example app is bundled with the plugin so we use a path dependency on
1919
# the parent directory to use the current plugin's version.
2020
path: ../../
21-
google_maps_flutter_platform_interface: ^2.5.0
21+
google_maps_flutter_platform_interface: ^2.6.0
2222
maps_example_dart:
2323
path: ../shared/maps_example_dart/
2424

0 commit comments

Comments
 (0)