diff --git a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt index 82ec6a540..dd3942019 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/explore/map/ExploreMapFragment.kt @@ -963,13 +963,17 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi if (geoPoint != null) { binding!!.mapView.controller.setCenter(geoPoint) val overlays = binding!!.mapView.overlays + // colllects the indices of items to remove + val indicesToRemove = mutableListOf() for (i in overlays.indices) { - if (overlays[i] is Marker) { - binding!!.mapView.overlays.removeAt(i) - } else if (overlays[i] is ScaleDiskOverlay) { - binding!!.mapView.overlays.removeAt(i) + if (overlays[i] is Marker || overlays[i] is ScaleDiskOverlay) { + indicesToRemove.add(i) } } + // removes tha items in reverse order to avoid index shifting + indicesToRemove.sortedDescending().forEach { index -> + binding!!.mapView.overlays.removeAt(index) + } val diskOverlay = ScaleDiskOverlay( requireContext(), geoPoint, 2000, GeoConstants.UnitOfMeasure.foot @@ -979,7 +983,6 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi this.style = Paint.Style.STROKE this.strokeWidth = 2f }) - setCirclePaint1(Paint().apply { setColor(Color.argb(40, 128, 128, 128)) this.style = Paint.Style.FILL_AND_STROKE @@ -988,7 +991,6 @@ class ExploreMapFragment : CommonsDaggerSupportFragment(), ExploreMapContract.Vi setDisplaySizeMax(1700) } binding!!.mapView.overlays.add(diskOverlay) - val startMarker = Marker( binding!!.mapView ).apply {