diff options
author | Iván Ávalos <avalos@disroot.org> | 2021-12-30 16:46:21 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2021-12-30 16:46:21 -0600 |
commit | a0e16d47a97c27cb84d6e4d5e626b99c0e08081a (patch) | |
tree | 98765f1353e0c092a219132d742328f5b5daa2b5 /androidApp/src/main/java/mx/trackermap/TrackerMap/android/map | |
parent | 0c8576a60e59f9d7a2fb2044752d10e564237a4f (diff) | |
download | etbsa-trackermap-mobile-a0e16d47a97c27cb84d6e4d5e626b99c0e08081a.tar.gz etbsa-trackermap-mobile-a0e16d47a97c27cb84d6e4d5e626b99c0e08081a.tar.bz2 etbsa-trackermap-mobile-a0e16d47a97c27cb84d6e4d5e626b99c0e08081a.zip |
Center map on device click
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/map')
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt | 15 |
1 files changed, 15 insertions, 0 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 f3d7cac..f0ec769 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 @@ -13,6 +13,7 @@ import kotlinx.coroutines.DelicateCoroutinesApi import mx.trackermap.TrackerMap.android.R import mx.trackermap.TrackerMap.android.databinding.MapFragmentBinding import mx.trackermap.TrackerMap.android.units.UnitsViewModel +import mx.trackermap.TrackerMap.client.models.UnitInformation import org.koin.androidx.viewmodel.ext.android.viewModel import java.io.File @@ -23,6 +24,8 @@ class MapFragment: GlobeMapFragment() { private val unitsViewModel: UnitsViewModel by viewModel() + private val markers = mutableListOf<ScreenMarker>() + override fun chooseDisplayType(): MapDisplayType { return MapDisplayType.Map } @@ -116,11 +119,23 @@ class MapFragment: GlobeMapFragment() { marker.image = icon marker.size = markerSize marker.userObject = unit + markers.add(marker) mapControl.addScreenMarker(marker, markerInfo, ThreadMode.ThreadAny) } } } } + unitsViewModel.selectedUnit.observe(this) { + it?.let { unit -> + Log.d("MapFragment", "Centering map on ${it.position?.latitude}, ${it.position?.longitude}") + unit.position?.let { position -> + val latitude = position.latitude!! * Math.PI / 180 + val longitude = position.longitude!! * Math.PI / 180 + val zoom = 0.000008 + mapControl.animatePositionGeo(longitude, latitude, zoom, 1.0) + } + } + } } }
\ No newline at end of file |