Skip to content
Open
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.19.6

* Fixes the onTap callback for clustered pin info window taps.

## 2.19.5

* Fixes a crash when using the legacy map renderer by adding the `org.apache.http.legacy` library.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class ClusterManagersController
@Nullable
private ClusterManager.OnClusterItemClickListener<MarkerBuilder> clusterItemClickListener;

@Nullable
private ClusterManager.OnClusterItemInfoWindowClickListener<MarkerBuilder>
clusterItemInfoWindowClickListener;

@Nullable
private ClusterManagersController.OnClusterItemRendered<MarkerBuilder>
clusterItemRenderedListener;
Expand All @@ -71,6 +75,12 @@ void setClusterItemClickListener(
initListenersForClusterManagers();
}

void setClusterItemInfoWindowClickListener(
@Nullable ClusterManager.OnClusterItemInfoWindowClickListener<MarkerBuilder> listener) {
clusterItemInfoWindowClickListener = listener;
initListenersForClusterManagers();
}

void setClusterItemRenderedListener(
@Nullable ClusterManagersController.OnClusterItemRendered<MarkerBuilder> listener) {
clusterItemRenderedListener = listener;
Expand All @@ -79,16 +89,21 @@ void setClusterItemRenderedListener(
private void initListenersForClusterManagers() {
for (Map.Entry<String, ClusterManager<MarkerBuilder>> entry :
clusterManagerIdToManager.entrySet()) {
initListenersForClusterManager(entry.getValue(), this, clusterItemClickListener);
initListenersForClusterManager(
entry.getValue(), this, clusterItemClickListener, clusterItemInfoWindowClickListener);
}
}

private void initListenersForClusterManager(
ClusterManager<MarkerBuilder> clusterManager,
@Nullable ClusterManager.OnClusterClickListener<MarkerBuilder> clusterClickListener,
@Nullable ClusterManager.OnClusterItemClickListener<MarkerBuilder> clusterItemClickListener) {
@Nullable ClusterManager.OnClusterItemClickListener<MarkerBuilder> clusterItemClickListener,
@Nullable
ClusterManager.OnClusterItemInfoWindowClickListener<MarkerBuilder>
clusterItemInfoWindowClickListener) {
clusterManager.setOnClusterClickListener(clusterClickListener);
clusterManager.setOnClusterItemClickListener(clusterItemClickListener);
clusterManager.setOnClusterItemInfoWindowClickListener(clusterItemInfoWindowClickListener);
}

/** Adds new ClusterManagers to the controller. */
Expand Down Expand Up @@ -123,7 +138,8 @@ private void initializeRenderer(ClusterManager<MarkerBuilder> clusterManager) {
break;
}
clusterManager.setRenderer(clusterRenderer);
initListenersForClusterManager(clusterManager, this, clusterItemClickListener);
initListenersForClusterManager(
clusterManager, this, clusterItemClickListener, clusterItemInfoWindowClickListener);
}

/** Removes ClusterManagers by given cluster manager IDs from the controller. */
Expand All @@ -145,7 +161,7 @@ private void removeClusterManager(Object clusterManagerId) {
if (clusterManager == null) {
return;
}
initListenersForClusterManager(clusterManager, null, null);
initListenersForClusterManager(clusterManager, null, null, null);
clusterManager.clearItems();
clusterManager.cluster();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
class GoogleMapController
implements ActivityPluginBinding.OnSaveInstanceStateListener,
ClusterManager.OnClusterItemClickListener<MarkerBuilder>,
ClusterManager.OnClusterItemInfoWindowClickListener<MarkerBuilder>,
ClusterManagersController.OnClusterItemRendered<MarkerBuilder>,
DefaultLifecycleObserver,
GoogleMapListener,
Expand Down Expand Up @@ -223,6 +224,7 @@ public void onMapReady(@NonNull GoogleMap googleMap) {
groundOverlaysController.setGoogleMap(googleMap);
setMarkerCollectionListener(this);
setClusterItemClickListener(this);
setClusterItemInfoWindowClickListener(this);
setClusterItemRenderedListener(this);
updateInitialClusterManagers();
updateInitialMarkers();
Expand Down Expand Up @@ -398,6 +400,7 @@ public void dispose() {
setGoogleMapListener(null);
setMarkerCollectionListener(null);
setClusterItemClickListener(null);
setClusterItemInfoWindowClickListener(null);
setClusterItemRenderedListener(null);
destroyMapViewIfNecessary();
Lifecycle lifecycle = lifecycleProvider.getLifecycle();
Expand Down Expand Up @@ -445,6 +448,17 @@ public void setClusterItemClickListener(
clusterManagersController.setClusterItemClickListener(listener);
}

@VisibleForTesting
public void setClusterItemInfoWindowClickListener(
@Nullable ClusterManager.OnClusterItemInfoWindowClickListener<MarkerBuilder> listener) {
if (googleMap == null) {
Log.v(TAG, "Controller was disposed before GoogleMap was ready.");
return;
}

clusterManagersController.setClusterItemInfoWindowClickListener(listener);
}

@VisibleForTesting
public void setClusterItemRenderedListener(
@Nullable ClusterManagersController.OnClusterItemRendered<MarkerBuilder> listener) {
Expand Down Expand Up @@ -827,6 +841,11 @@ public boolean onClusterItemClick(MarkerBuilder item) {
return markersController.onMarkerTap(item.markerId());
}

@Override
public void onClusterItemInfoWindowClick(MarkerBuilder item) {
markersController.onClusterItemInfoWindowTap(item.markerId());
}

public void setMapStyle(@Nullable String style) {
if (googleMap == null) {
initialMapStyle = style;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ void onInfoWindowTap(String googleMarkerId) {
flutterApi.onInfoWindowTap(markerId, new NoOpVoidResult());
}

/**
* Called when a cluster-managed marker's info window is tapped. Takes the Dart marker ID
* directly.
*/
void onClusterItemInfoWindowTap(String markerId) {
flutterApi.onInfoWindowTap(markerId, new NoOpVoidResult());
}
Comment on lines +310 to +316
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To improve maintainability and reduce code duplication, you could refactor this new method and the existing onInfoWindowTap to share a common private method. The current implementation duplicates the call to flutterApi.onInfoWindowTap.

For example, you could introduce a private method that takes the Dart markerId and makes the API call. Then, both onInfoWindowTap (after resolving the googleMarkerId) and this new onClusterItemInfoWindowTap method could call that private method.


/**
* Called each time clusterManager adds new visible marker to the map. Creates markerController
* for marker for realtime marker updates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ public void OnMapReadySetsClusterItemClickListener() {
verify(spyGoogleMapController, times(1)).setClusterItemClickListener(null);
}

@Test
@SuppressWarnings("unchecked")
public void OnMapReadySetsClusterItemInfoWindowClickListener() {
GoogleMapController googleMapController = getGoogleMapController();
GoogleMapController spyGoogleMapController = spy(googleMapController);
spyGoogleMapController.onMapReady(mockGoogleMap);

verify(spyGoogleMapController, times(1))
.setClusterItemInfoWindowClickListener(
any(ClusterManager.OnClusterItemInfoWindowClickListener.class));

spyGoogleMapController.dispose();
verify(spyGoogleMapController, times(1)).setClusterItemInfoWindowClickListener(null);
}

@Test
@SuppressWarnings("unchecked")
public void OnMapReadySetsClusterItemRenderedListener() {
Expand Down Expand Up @@ -235,6 +250,15 @@ public void OnClusterItemClickCallsMarkersController() {
verify(mockMarkersController, times(1)).onMarkerTap(markerBuilder.markerId());
}

@Test
public void OnClusterItemInfoWindowClickCallsMarkersController() {
GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies();
MarkerBuilder markerBuilder = new MarkerBuilder("m_1", "cm_1", PlatformMarkerType.MARKER);

googleMapController.onClusterItemInfoWindowClick(markerBuilder);
verify(mockMarkersController, times(1)).onClusterItemInfoWindowTap(markerBuilder.markerId());
}

@Test
public void SetInitialHeatmaps() {
GoogleMapController googleMapController = getGoogleMapControllerWithMockedDependencies();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter_android
description: Android implementation of the google_maps_flutter plugin.
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 2.19.5
version: 2.19.6

environment:
sdk: ^3.9.0
Expand Down