ExploreMapFragment.java: modify Overlay onItemSingleTapUp code to place Overlay above other Overlays (#6334)

Before these changes, when a user tapped on an icon in the Explore Map, the icon and label would often
appear underneath other icons, making it difficult or impossible to read the text on the label.

These changes add two methods that search for and move the icon/label Overlays above all other icons and overlays.
These two methods are called when the user taps on an icon.

Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
Jason-Whitmore 2025-06-05 01:06:55 -07:00 committed by Nishthajain7
parent b8c392fb5e
commit c325895733

View file

@ -782,6 +782,9 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
}
clickedMarker = nearbyBaseMarker;
passInfoToSheet(place);
//Move the overlay to the top so it can be fully seen.
moveOverlayToTop(getOverlay(item));
return true;
}
@ -801,6 +804,52 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
}
}
/**
* Moves the specified Overlay above all other Overlays. This prevents other Overlays from
* obstructing it. Upon failure, this method returns early.
* @param overlay The Overlay to move.
*/
private void moveOverlayToTop (Overlay overlay) {
if (overlay == null || binding == null || binding.mapView.getOverlays() == null) {
return;
}
boolean successfulRemoval = binding.mapView.getOverlays().remove(overlay);
if (!successfulRemoval) {
return;
}
binding.mapView.getOverlays().add(overlay);
}
/**
* Performs a linear search for the first Overlay which contains the specified OverlayItem.
*
* @param item The OverlayItem contained within the first target Overlay.
* @return The first Overlay which contains the specified OverlayItem or null if the Overlay
* could not be found.
*/
private Overlay getOverlay (OverlayItem item) {
if (item == null || binding == null || binding.mapView.getOverlays() == null) {
return null;
}
for (int i = 0; i < binding.mapView.getOverlays().size(); i++) {
if (binding.mapView.getOverlays().get(i) instanceof ItemizedOverlayWithFocus) {
ItemizedOverlayWithFocus overlay =
(ItemizedOverlayWithFocus)binding.mapView.getOverlays().get(i);
for (int j = 0; j < overlay.size(); j++) {
if (overlay.getItem(j) == item) {
return overlay;
}
}
}
}
return null;
}
/**
* Retrieves the specific Media object from the mediaList field.
* @param url The specific Media's image URL.