Skip to content

Commit

Permalink
Show features on other map views (#1950)
Browse files Browse the repository at this point in the history
* Show features on other map views

* Add missing imports

* Format OfflineAreaSelectorFragment
  • Loading branch information
JSunde authored Oct 2, 2023
1 parent 5cf918c commit c765e70
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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) }
}

Expand Down

0 comments on commit c765e70

Please sign in to comment.