Skip to content

Commit 4ce5122

Browse files
authored
refactor(cluster): Default item rendering to onBeforeClusterItemRendered() (#633)
Refs: 630 Fixes #630
1 parent 39f0c22 commit 4ce5122

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

library/src/main/java/com/google/maps/android/clustering/view/DefaultClusterRenderer.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,10 @@ public void remove(Marker m) {
736736
}
737737

738738
/**
739-
* Called before the marker for a ClusterItem is added to the map.
739+
* Called before the marker for a ClusterItem is added to the map. The default implementation
740+
* sets the marker and snippet text based on the respective item text if they are both
741+
* available, otherwise it will set the title if available, and if not it will set the marker
742+
* title to the item snippet text if that is available.
740743
*
741744
* The first time {@link ClusterManager#cluster()} is invoked on a set of items
742745
* {@link #onBeforeClusterItemRendered(ClusterItem, MarkerOptions)} will be called and
@@ -749,6 +752,14 @@ public void remove(Marker m) {
749752
* @param markerOptions the markerOptions representing the provided item
750753
*/
751754
protected void onBeforeClusterItemRendered(T item, MarkerOptions markerOptions) {
755+
if (item.getTitle() != null && item.getSnippet() != null) {
756+
markerOptions.title(item.getTitle());
757+
markerOptions.snippet(item.getSnippet());
758+
} else if (item.getTitle() != null) {
759+
markerOptions.title(item.getTitle());
760+
} else if (item.getSnippet() != null) {
761+
markerOptions.title(item.getSnippet());
762+
}
752763
}
753764

754765
/**
@@ -952,14 +963,6 @@ private void perform(MarkerModifier markerModifier) {
952963
} else {
953964
markerOptions.position(item.getPosition());
954965
}
955-
if (!(item.getTitle() == null) && !(item.getSnippet() == null)) {
956-
markerOptions.title(item.getTitle());
957-
markerOptions.snippet(item.getSnippet());
958-
} else if (!(item.getSnippet() == null)) {
959-
markerOptions.title(item.getSnippet());
960-
} else if (!(item.getTitle() == null)) {
961-
markerOptions.title(item.getTitle());
962-
}
963966
onBeforeClusterItemRendered(item, markerOptions);
964967
marker = mClusterManager.getMarkerCollection().addMarker(markerOptions);
965968
markerWithPosition = new MarkerWithPosition(marker);

0 commit comments

Comments
 (0)