Skip to content

Commit 042ab9c

Browse files
RkarekoFikriMilano
andauthored
Fix failure to open bottom sheet dialog when a newly added location is clicked (#3798)
* Fix failure to open bottom sheet dialog when a newly added location is clicked * Update clearMarker logic * Update kdoc Co-authored-by: Fikri Milano <fikrimilano1@gmail.com> * Run sptoless Apply --------- Co-authored-by: Fikri Milano <fikrimilano1@gmail.com>
1 parent 3813786 commit 042ab9c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

android/geowidget/src/main/java/org/smartregister/fhircore/geowidget/screens/GeoWidgetFragment.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import com.mapbox.mapboxsdk.Mapbox
3737
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
3838
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException
3939
import com.mapbox.mapboxsdk.geometry.LatLngBounds
40+
import com.mapbox.mapboxsdk.maps.MapboxMap
4041
import com.mapbox.mapboxsdk.maps.Style
4142
import com.mapbox.mapboxsdk.style.expressions.Expression
4243
import com.mapbox.mapboxsdk.style.layers.PropertyFactory
@@ -313,6 +314,7 @@ class GeoWidgetFragment : Fragment() {
313314
mapboxMap.getStyle { style ->
314315
style.getSourceAs<GeoJsonSource>(DATA_SET)?.setGeoJson(featureCollection)
315316
}
317+
clearMarkers(mapboxMap)
316318
val bbox = TurfMeasurement.bbox(MultiPoint.fromLngLats(locationPoints))
317319
val paddedBbox = CoordinateUtils.getPaddedBbox(bbox, PADDING_IN_METRES)
318320
val bounds = LatLngBounds.from(paddedBbox[3], paddedBbox[2], paddedBbox[1], paddedBbox[0])
@@ -378,6 +380,22 @@ class GeoWidgetFragment : Fragment() {
378380
}
379381
}
380382

383+
/**
384+
* Removes all map markers to prevent click event conflicts.
385+
*
386+
* Red markers are automatically added when new points are placed on the map, but they're
387+
* redundant since FHIRCore renders custom location icons. More critically, these markers block
388+
* click events on newly added locations due to how Kujaku's gesture detector handles tap events
389+
* in [com.mapbox.mapboxsdk.maps.MapGestureDetector.StandardGestureDetector.onSingleTapConfirmed].
390+
*
391+
* @param mapboxMap The MapboxMap instance to clear markers from
392+
*/
393+
fun clearMarkers(mapboxMap: MapboxMap) {
394+
if (mapboxMap.markers.isNotEmpty()) {
395+
mapboxMap.markers.forEach { mapboxMap.removeMarker(it) }
396+
}
397+
}
398+
381399
companion object {
382400
const val MAP_FEATURES_LIMIT = 1000
383401
const val PADDING_IN_METRES = 1000.0

0 commit comments

Comments
 (0)