Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show features on other map views #1950

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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