From 5949099d9165208f92bb2d4a54b66fe68ccd33ef Mon Sep 17 00:00:00 2001 From: "Daniele Verducci (Slimpenguin)" Date: Fri, 23 Feb 2024 08:52:32 +0100 Subject: [PATCH] Fixed geopoint deletion and update --- .../fragments/GeofavoriteMapFragment.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java index 8d88e5e..1d6c948 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java @@ -25,6 +25,7 @@ import org.osmdroid.views.CustomZoomButtonsController; import org.osmdroid.views.MapView; import org.osmdroid.views.overlay.MapEventsOverlay; import org.osmdroid.views.overlay.Marker; +import org.osmdroid.views.overlay.Overlay; import org.osmdroid.views.overlay.infowindow.InfoWindow; import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider; import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay; @@ -108,6 +109,7 @@ public class GeofavoriteMapFragment extends GeofavoritesFragment implements Main mGeofavoritesFragmentViewModel.getGeofavorites().observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(List geofavorites) { + clearAllMarkers(); for(Geofavorite gf : geofavorites) addMarker(gf); map.invalidate(); @@ -222,4 +224,15 @@ public class GeofavoriteMapFragment extends GeofavoritesFragment implements Main m.setInfoWindow(iw); map.getOverlays().add(m); } + + private void clearAllMarkers() { + // Close any open infowindow before removing related marker + InfoWindow.closeAllInfoWindowsOn(map); + // Remove all markers, leaving the other overlays (user position and tap listener ones) + for(Overlay o : map.getOverlays()) { + if (o instanceof Marker) { + map.getOverlays().remove(o); + } + } + } }