diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-18 00:34:38 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-18 00:34:38 -0600 |
commit | 5b6ad3dd226c28475a657638b6d883c72aca2255 (patch) | |
tree | 4187bfd89986b5b2d226190e84dcc776490ba2cf /androidApp/src/main/java/mx/trackermap/TrackerMap/android/map | |
parent | 31af6d69a7bb8a513a7bb9b1633cc015088384d3 (diff) | |
parent | e679a7d019391fce98a8a30458d09759733d60b1 (diff) | |
download | etbsa-trackermap-mobile-5b6ad3dd226c28475a657638b6d883c72aca2255.tar.gz etbsa-trackermap-mobile-5b6ad3dd226c28475a657638b6d883c72aca2255.tar.bz2 etbsa-trackermap-mobile-5b6ad3dd226c28475a657638b6d883c72aca2255.zip |
Merge branch 'main' of https://git.sr.ht/~avalos/trackermap-mobile
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/map')
3 files changed, 37 insertions, 9 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt index 87fb44a..37956c1 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt @@ -344,7 +344,7 @@ open class MapFragment : GlobeMapFragment() { fun focusOn( latitude: Double, longitude: Double, - height: Double = 0.00001, + height: Double = 0.0000264, animated: Boolean = true ) { val lat = latitude * Math.PI / 180 diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt index 01587ae..c8ef688 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapWrapperFragment.kt @@ -130,7 +130,7 @@ class MapWrapperFragment: Fragment() { fun focusOn( latitude: Double, longitude: Double, - height: Double = 0.00001, + height: Double = 0.0000264, animated: Boolean = true ) { Log.d("MapWrapperFragment", "Focusing on $latitude, $longitude") diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt index 768c0f0..e64afd3 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt @@ -9,6 +9,7 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.commit import androidx.fragment.app.viewModels +import com.mousebird.maply.Point2d import kotlin.time.ExperimentalTime import kotlinx.coroutines.DelicateCoroutinesApi import mx.trackermap.TrackerMap.android.R @@ -30,7 +31,7 @@ class UnitMapFragment : Fragment() { private val binding get() = _binding!! private lateinit var mapFragment: MapWrapperFragment - private var shouldCenter = true + private var shouldCenterMap = true override fun onCreateView( inflater: LayoutInflater, @@ -60,7 +61,7 @@ class UnitMapFragment : Fragment() { } private fun initializeMap() { - shouldCenter = true + shouldCenterMap = true mapFragment = MapWrapperFragment.newInstance( overlayMarginTop = resources.getDimensionPixelSize(R.dimen.nav_height) ) @@ -78,10 +79,12 @@ class UnitMapFragment : Fragment() { mapFragment.display( units.toTypedArray(), isReport = false, - center = shouldCenter && unitsViewModel.selectedUnit.value == null + center = shouldCenterMap + && unitsViewModel.selectedUnit.value == null + && unitsViewModel.camera.value == null ) if (units.isNotEmpty()) { - shouldCenter = false + shouldCenterMap = false } } @@ -90,8 +93,13 @@ class UnitMapFragment : Fragment() { binding.mapUnitCard.visibility = if (selectedUnit == null) View.GONE else View.VISIBLE + if (selectedUnit == null) { + unitsViewModel.clearCamera() + } + selectedUnit?.let { unit -> - if (unit.position == null || unit.position!!.latitude == null || unit.position!!.longitude == null) { + if (unit.position == null || unit.position?.latitude == null || unit.position?.longitude == null) { + binding.mapUnitCard.visibility = View.GONE return@let } @@ -107,7 +115,14 @@ class UnitMapFragment : Fragment() { ), binding.mapUnitCard.context, unit, this::itemAction ) - mapFragment.focusOn(unit.position!!.latitude!!, unit.position!!.longitude!!) + unitsViewModel.moveCamera( + UnitsViewModel.Camera( + point = Point2d( + unit.position!!.longitude!!, unit.position!!.latitude!! + ), + animated = true + ) + ) } } @@ -115,13 +130,26 @@ class UnitMapFragment : Fragment() { Log.d("UnitMapFragment", "Loading layer!") mapFragment.updateLayer(type) unitsViewModel.selectedUnit.value?.let { - mapFragment.focusOn(it.position!!.latitude!!, it.position!!.longitude!!) + unitsViewModel.moveCamera( + UnitsViewModel.Camera( + point = Point2d( + it.position!!.longitude!!, it.position!!.latitude!! + ), + animated = false + ) + ) } } unitsViewModel.geofences.observe(viewLifecycleOwner) { geofences -> mapFragment.display(geofences.values.toTypedArray()) } + + unitsViewModel.camera.observe(viewLifecycleOwner) { camera -> + camera?.let { + mapFragment.focusOn(camera.point.y, camera.point.x) + } + } } private fun removeObservers() { |