Fixed geopoint deletion and update

This commit is contained in:
Daniele Verducci (Slimpenguin) 2024-02-23 08:52:32 +01:00
parent 13287f5b05
commit 5949099d91

View File

@ -25,6 +25,7 @@ import org.osmdroid.views.CustomZoomButtonsController;
import org.osmdroid.views.MapView; import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.MapEventsOverlay; import org.osmdroid.views.overlay.MapEventsOverlay;
import org.osmdroid.views.overlay.Marker; import org.osmdroid.views.overlay.Marker;
import org.osmdroid.views.overlay.Overlay;
import org.osmdroid.views.overlay.infowindow.InfoWindow; import org.osmdroid.views.overlay.infowindow.InfoWindow;
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider; import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay; import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
@ -108,6 +109,7 @@ public class GeofavoriteMapFragment extends GeofavoritesFragment implements Main
mGeofavoritesFragmentViewModel.getGeofavorites().observe(getViewLifecycleOwner(), new Observer<List<Geofavorite>>() { mGeofavoritesFragmentViewModel.getGeofavorites().observe(getViewLifecycleOwner(), new Observer<List<Geofavorite>>() {
@Override @Override
public void onChanged(List<Geofavorite> geofavorites) { public void onChanged(List<Geofavorite> geofavorites) {
clearAllMarkers();
for(Geofavorite gf : geofavorites) for(Geofavorite gf : geofavorites)
addMarker(gf); addMarker(gf);
map.invalidate(); map.invalidate();
@ -222,4 +224,15 @@ public class GeofavoriteMapFragment extends GeofavoritesFragment implements Main
m.setInfoWindow(iw); m.setInfoWindow(iw);
map.getOverlays().add(m); 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);
}
}
}
} }