Skip to content

Commit 53bfc3f

Browse files
committed
feat: passing ClusterManager List to addClusterManagers, removing dummy id generation
1 parent 0832625 commit 53bfc3f

7 files changed

Lines changed: 27 additions & 31 deletions

File tree

android/src/main/kotlin/com/google/maps/flutter/navigation/messages.g.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,6 @@ data class MarkerOptionsDto(
900900
val visible: Boolean,
901901
val zIndex: Double,
902902
val icon: ImageDescriptorDto,
903-
/**
904-
* Optional cluster manager ID. If provided, this marker will be managed by the cluster manager.
905-
*/
906903
val clusterManagerId: String? = null,
907904
) {
908905
companion object {

example/lib/pages/clustering.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ class _ClusteringPageState extends ExamplePageState<ClusteringPage> {
119119
final clusterManagerId = 'cluster_manager_id_$_clusterManagerIdCounter';
120120
_clusterManagerIdCounter++;
121121

122+
final clusterManager = ClusterManager(clusterManagerId: clusterManagerId);
122123
final List<ClusterManager> addedClusterManagers =
123-
await _navigationViewController!.addClusterManagers(<String>[
124-
clusterManagerId,
124+
await _navigationViewController!.addClusterManagers(<ClusterManager>[
125+
clusterManager,
125126
]);
126127

127128
if (addedClusterManagers.isNotEmpty) {
128-
final clusterManager = addedClusterManagers.first;
129129
setState(() {
130130
_clusterManagers[clusterManagerId] = clusterManager;
131131
});

ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@ struct MarkerOptionsDto: Hashable {
763763
var visible: Bool
764764
var zIndex: Double
765765
var icon: ImageDescriptorDto
766-
/// Optional cluster manager ID. If provided, this marker will be managed by the cluster manager.
767766
var clusterManagerId: String? = nil
768767

769768
// swift-format-ignore: AlwaysUseLowerCamelCase

lib/src/google_maps_map_view_controller.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,11 @@ class GoogleMapViewController {
317317
/// Cluster managers group nearby markers into clusters at different zoom levels.
318318
/// Markers can be assigned to a cluster manager by setting their [MarkerOptions.clusterManagerId].
319319
Future<List<ClusterManager>> addClusterManagers(
320-
List<String> clusterManagerIds,
320+
List<ClusterManager> clusterManagers,
321321
) {
322322
return GoogleMapsNavigationPlatform.instance.viewAPI.addClusterManagers(
323323
viewId: _viewId,
324-
clusterManagerIds: clusterManagerIds,
324+
clusterManagers: clusterManagers,
325325
);
326326
}
327327

lib/src/method_channel/convert/clustering.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@
1515
import '../../../google_navigation_flutter.dart';
1616
import '../method_channel.dart';
1717

18+
/// [ClusterManager] convert extension.
19+
/// @nodoc
20+
extension ConvertClusterManager on ClusterManager {
21+
/// Converts [ClusterManager] to [ClusterManagerDto]
22+
ClusterManagerDto toDto() {
23+
return ClusterManagerDto(clusterManagerId: clusterManagerId);
24+
}
25+
}
26+
27+
/// [ClusterManagerDto] convert extension.
28+
/// @nodoc
29+
extension ConvertClusterManagerDto on ClusterManagerDto {
30+
/// Converts [ClusterManagerDto] to [ClusterManager]
31+
ClusterManager toClusterManager() {
32+
return ClusterManager(clusterManagerId: clusterManagerId);
33+
}
34+
}
35+
1836
/// [ClusterEventTypeDto] convert extension.
1937
/// @nodoc
2038
extension ConvertClusterEventType on ClusterEventTypeDto {

lib/src/method_channel/map_view_api.dart

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ class MapViewAPIImpl {
6868
return circleId;
6969
}
7070

71-
/// Keep track of cluster manager count, used to generate cluster manager ID's.
72-
int _clusterManagerCounter = 0;
73-
String _createClusterManagerId() {
74-
final String clusterManagerId = 'ClusterManager_$_clusterManagerCounter';
75-
_clusterManagerCounter += 1;
76-
return clusterManagerId;
77-
}
78-
7971
Stream<T> _unwrapEventStream<T>({required int viewId}) {
8072
// If event that does not
8173
return _viewEventStreamController.stream
@@ -890,28 +882,19 @@ class MapViewAPIImpl {
890882

891883
return clusterManagers
892884
.whereType<ClusterManagerDto>()
893-
.map(
894-
(ClusterManagerDto cm) =>
895-
ClusterManager(clusterManagerId: cm.clusterManagerId),
896-
)
885+
.map((ClusterManagerDto cm) => cm.toClusterManager())
897886
.toList();
898887
}
899888

900889
/// Add cluster managers to map view.
901890
Future<List<ClusterManager>> addClusterManagers({
902891
required int viewId,
903-
required List<String> clusterManagerIds,
892+
required List<ClusterManager> clusterManagers,
904893
}) async {
905-
// Create cluster manager objects with provided or generated ID's
906-
final List<ClusterManagerDto> clusterManagersToAdd = clusterManagerIds
907-
.map(
908-
(String id) => ClusterManagerDto(
909-
clusterManagerId: id.isEmpty ? _createClusterManagerId() : id,
910-
),
911-
)
894+
final List<ClusterManagerDto> clusterManagersToAdd = clusterManagers
895+
.map((cm) => cm.toDto())
912896
.toList();
913897

914-
// Add cluster managers to map
915898
final List<ClusterManagerDto?> clusterManagersAdded = await _viewApi
916899
.addClusterManagers(viewId, clusterManagersToAdd);
917900

lib/src/method_channel/messages.g.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,6 @@ class MarkerOptionsDto {
821821

822822
ImageDescriptorDto icon;
823823

824-
/// Optional cluster manager ID. If provided, this marker will be managed by the cluster manager.
825824
String? clusterManagerId;
826825

827826
List<Object?> _toList() {

0 commit comments

Comments
 (0)