@@ -28,10 +28,12 @@ import androidx.compose.ui.platform.LocalContext
28
28
import androidx.compose.ui.platform.LocalLifecycleOwner
29
29
import androidx.compose.ui.viewinterop.AndroidView
30
30
import androidx.lifecycle.LifecycleOwner
31
+ import androidx.lifecycle.lifecycleScope
31
32
import com.arcgismaps.geometry.GeometryEngine
32
33
import com.arcgismaps.geometry.Point
33
34
import com.arcgismaps.geometry.SpatialReference
34
35
import com.arcgismaps.mapping.view.MapView
36
+ import com.arcgismaps.mapping.view.SingleTapConfirmedEvent
35
37
import com.esri.arcgismaps.sample.showcallout.R
36
38
import kotlinx.coroutines.launch
37
39
@@ -42,7 +44,7 @@ import kotlinx.coroutines.launch
42
44
fun ComposeMapView (
43
45
modifier : Modifier = Modifier ,
44
46
mapViewModel : MapViewModel ,
45
- application : Application
47
+ onSingleTap : ( SingleTapConfirmedEvent ) -> Unit = {}
46
48
) {
47
49
// get an instance of the current lifecycle owner
48
50
val lifecycleOwner = LocalLifecycleOwner .current
@@ -60,6 +62,12 @@ fun ComposeMapView(
60
62
mapView.apply {
61
63
map = mapViewState.arcGISMap
62
64
setViewpoint(mapViewState.viewpoint)
65
+ // show callout at the tapped location using the set View
66
+ mapView.callout.show(mapViewState.calloutContent, mapViewState.latLongPoint)
67
+ lifecycleOwner.lifecycleScope.launch {
68
+ // center the map on the tapped location
69
+ setViewpointCenter(mapViewState.latLongPoint)
70
+ }
63
71
}
64
72
}
65
73
)
@@ -68,20 +76,7 @@ fun ComposeMapView(
68
76
LaunchedEffect (Unit ) {
69
77
launch {
70
78
mapView.onSingleTapConfirmed.collect {
71
- // get map point from the Single tap event
72
- it.mapPoint?.let { mapPoint ->
73
- // convert the point to WGS84 for obtaining lat/lon format
74
- val wgs84Point =
75
- GeometryEngine .projectOrNull(mapPoint, SpatialReference .wgs84()) as Point
76
- // create a textview for the callout
77
- val calloutView = TextView (application).apply {
78
- text = application.getString(R .string.callout_text, wgs84Point.y, wgs84Point.x)
79
- }
80
- // show callout at the tapped location using the set View
81
- mapView.callout.show(calloutView, wgs84Point)
82
- // center the map on the tapped location
83
- mapView.setViewpointCenter(mapPoint)
84
- }
79
+ onSingleTap(it)
85
80
}
86
81
}
87
82
}
0 commit comments