diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt index f56ddcf937..cf4fee42ad 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt @@ -19,22 +19,27 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.lifecycle.lifecycleScope import com.google.android.ground.R import com.google.android.ground.ui.common.AbstractMapFragmentWithControls import com.google.android.ground.ui.common.BaseMapViewModel import com.google.android.ground.ui.datacollection.components.TaskHeaderPopupView +import com.google.android.ground.ui.home.mapcontainer.HomeScreenMapContainerViewModel import com.google.android.ground.ui.map.CameraPosition import com.google.android.ground.ui.map.MapFragment import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.launch @AndroidEntryPoint(AbstractMapFragmentWithControls::class) class DropAPinMapFragment(private val viewModel: DropAPinTaskViewModel) : Hilt_DropAPinMapFragment() { private lateinit var mapViewModel: BaseMapViewModel + private lateinit var mapContainerViewModel: HomeScreenMapContainerViewModel override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + mapContainerViewModel = getViewModel(HomeScreenMapContainerViewModel::class.java) mapViewModel = getViewModel(BaseMapViewModel::class.java) } @@ -55,6 +60,11 @@ class DropAPinMapFragment(private val viewModel: DropAPinTaskViewModel) : override fun getMapViewModel(): BaseMapViewModel = mapViewModel override fun onMapReady(map: MapFragment) { + // Observe events emitted by the ViewModel. + viewLifecycleOwner.lifecycleScope.launch { + mapContainerViewModel.mapLoiFeatures.collect { map.renderFeatures(it) } + } + viewModel.features.observe(this) { map.renderFeatures(it) } } diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/PolygonDrawingMapFragment.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/PolygonDrawingMapFragment.kt index abef943149..fefd798336 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/PolygonDrawingMapFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/PolygonDrawingMapFragment.kt @@ -19,6 +19,7 @@ import android.os.Bundle import androidx.lifecycle.lifecycleScope import com.google.android.ground.ui.common.AbstractMapFragmentWithControls import com.google.android.ground.ui.common.BaseMapViewModel +import com.google.android.ground.ui.home.mapcontainer.HomeScreenMapContainerViewModel import com.google.android.ground.ui.map.CameraPosition import com.google.android.ground.ui.map.Feature import com.google.android.ground.ui.map.MapFragment @@ -30,15 +31,22 @@ class PolygonDrawingMapFragment(private val viewModel: PolygonDrawingViewModel) Hilt_PolygonDrawingMapFragment() { private lateinit var mapViewModel: BaseMapViewModel + private lateinit var mapContainerViewModel: HomeScreenMapContainerViewModel override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + mapContainerViewModel = getViewModel(HomeScreenMapContainerViewModel::class.java) mapViewModel = getViewModel(BaseMapViewModel::class.java) } override fun getMapViewModel(): BaseMapViewModel = mapViewModel override fun onMapReady(map: MapFragment) { + // Observe events emitted by the ViewModel. + viewLifecycleOwner.lifecycleScope.launch { + mapContainerViewModel.mapLoiFeatures.collect { map.renderFeatures(it) } + } + viewLifecycleOwner.lifecycleScope.launch { viewModel.featureValue.collect { feature: Feature? -> map.renderFeatures(if (feature == null) setOf() else setOf(feature)) diff --git a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt index c84a4def9c..662ee1db0e 100644 --- a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt @@ -20,13 +20,16 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.lifecycle.lifecycleScope import com.google.android.ground.databinding.OfflineAreaSelectorFragBinding import com.google.android.ground.ui.common.AbstractMapContainerFragment import com.google.android.ground.ui.common.BaseMapViewModel import com.google.android.ground.ui.common.EphemeralPopups +import com.google.android.ground.ui.home.mapcontainer.HomeScreenMapContainerViewModel import com.google.android.ground.ui.map.MapFragment import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject +import kotlinx.coroutines.launch /** Map UI used to select areas for download and viewing offline. */ @AndroidEntryPoint(AbstractMapContainerFragment::class) @@ -35,11 +38,13 @@ class OfflineAreaSelectorFragment : Hilt_OfflineAreaSelectorFragment() { @Inject lateinit var popups: EphemeralPopups private lateinit var viewModel: OfflineAreaSelectorViewModel + private lateinit var mapContainerViewModel: HomeScreenMapContainerViewModel private var downloadProgressDialogFragment = DownloadProgressDialogFragment() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + mapContainerViewModel = getViewModel(HomeScreenMapContainerViewModel::class.java) viewModel = getViewModel(OfflineAreaSelectorViewModel::class.java) viewModel.isDownloadProgressVisible.observe(this) { downloadProgressDialogFragment.setVisibility(childFragmentManager, it) @@ -59,6 +64,10 @@ class OfflineAreaSelectorFragment : Hilt_OfflineAreaSelectorFragment() { } override fun onMapReady(map: MapFragment) { + // Observe events emitted by the ViewModel. + viewLifecycleOwner.lifecycleScope.launch { + mapContainerViewModel.mapLoiFeatures.collect { map.renderFeatures(it) } + } viewModel.remoteTileSources.forEach { map.addTileOverlay(it) } }