Skip to content

Commit 62c5231

Browse files
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 <[email protected]>
1 parent 7a224a9 commit 62c5231

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,9 @@ public boolean onItemSingleTapUp(int index, OverlayItem item) {
782782
}
783783
clickedMarker = nearbyBaseMarker;
784784
passInfoToSheet(place);
785+
786+
//Move the overlay to the top so it can be fully seen.
787+
moveOverlayToTop(getOverlay(item));
785788
return true;
786789
}
787790

@@ -801,6 +804,52 @@ public boolean onItemLongPress(int index, OverlayItem item) {
801804
}
802805
}
803806

807+
/**
808+
* Moves the specified Overlay above all other Overlays. This prevents other Overlays from
809+
* obstructing it. Upon failure, this method returns early.
810+
* @param overlay The Overlay to move.
811+
*/
812+
private void moveOverlayToTop (Overlay overlay) {
813+
if (overlay == null || binding == null || binding.mapView.getOverlays() == null) {
814+
return;
815+
}
816+
817+
boolean successfulRemoval = binding.mapView.getOverlays().remove(overlay);
818+
if (!successfulRemoval) {
819+
return;
820+
}
821+
822+
binding.mapView.getOverlays().add(overlay);
823+
}
824+
825+
/**
826+
* Performs a linear search for the first Overlay which contains the specified OverlayItem.
827+
*
828+
* @param item The OverlayItem contained within the first target Overlay.
829+
* @return The first Overlay which contains the specified OverlayItem or null if the Overlay
830+
* could not be found.
831+
*/
832+
private Overlay getOverlay (OverlayItem item) {
833+
if (item == null || binding == null || binding.mapView.getOverlays() == null) {
834+
return null;
835+
}
836+
837+
for (int i = 0; i < binding.mapView.getOverlays().size(); i++) {
838+
if (binding.mapView.getOverlays().get(i) instanceof ItemizedOverlayWithFocus) {
839+
ItemizedOverlayWithFocus overlay =
840+
(ItemizedOverlayWithFocus)binding.mapView.getOverlays().get(i);
841+
842+
for (int j = 0; j < overlay.size(); j++) {
843+
if (overlay.getItem(j) == item) {
844+
return overlay;
845+
}
846+
}
847+
}
848+
}
849+
850+
return null;
851+
}
852+
804853
/**
805854
* Retrieves the specific Media object from the mediaList field.
806855
* @param url The specific Media's image URL.

0 commit comments

Comments
 (0)