diff options
author | Isidro Henoch <imhenoch@protonmail.com> | 2022-01-04 01:49:21 -0600 |
---|---|---|
committer | Isidro Henoch <imhenoch@protonmail.com> | 2022-01-04 01:49:21 -0600 |
commit | 3e209110761b6ec3578675cbdfe4fdbdf5a10f91 (patch) | |
tree | 618fd345889b8b5fc5ce9e765e1f5a1c990324ef /androidApp/src | |
parent | 28ce12043342ec830437ef87169ebee4168e99c4 (diff) | |
download | etbsa-trackermap-mobile-3e209110761b6ec3578675cbdfe4fdbdf5a10f91.tar.gz etbsa-trackermap-mobile-3e209110761b6ec3578675cbdfe4fdbdf5a10f91.tar.bz2 etbsa-trackermap-mobile-3e209110761b6ec3578675cbdfe4fdbdf5a10f91.zip |
Finishes the markers functionality
Diffstat (limited to 'androidApp/src')
3 files changed, 47 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 bd17013..106a2d9 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 @@ -8,7 +8,9 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.mousebird.maply.ComponentObject +import com.mousebird.maply.GlobeController import com.mousebird.maply.GlobeMapFragment +import com.mousebird.maply.MapController import com.mousebird.maply.MarkerInfo import com.mousebird.maply.Point2d import com.mousebird.maply.QuadImageLoader @@ -17,11 +19,14 @@ import com.mousebird.maply.RenderController import com.mousebird.maply.RenderControllerInterface import com.mousebird.maply.SamplingParams import com.mousebird.maply.ScreenMarker +import com.mousebird.maply.SelectedObject import com.mousebird.maply.SphericalMercatorCoordSystem import java.io.File import kotlinx.coroutines.DelicateCoroutinesApi import mx.trackermap.TrackerMap.android.R +typealias MarkerCallback = (Int?) -> Unit + @DelicateCoroutinesApi class MapFragment : GlobeMapFragment() { @@ -37,6 +42,8 @@ class MapFragment : GlobeMapFragment() { val type: MarkerType = MarkerType.DEFAULT ) + var markerCallback: MarkerCallback? = null + private val markers = mutableListOf<Pair<ScreenMarker, ComponentObject>>() override fun chooseDisplayType(): MapDisplayType { @@ -81,6 +88,31 @@ class MapFragment : GlobeMapFragment() { mapControl.setPositionGeo(longitude, latitude, zoom) } + override fun userDidSelect( + mapControl: MapController?, + selObjs: Array<out SelectedObject>?, + loc: Point2d?, + screenLoc: Point2d? + ) { + super.userDidSelect(mapControl, selObjs, loc, screenLoc) + + selObjs?.forEach { selectedObject -> + if (selectedObject.selObj is ScreenMarker) { + val screenMarker = selectedObject.selObj as ScreenMarker + val markerId = screenMarker.userObject as Int + Log.d("MapFragment", "Selected marker with id: $markerId") + + markerCallback?.let { it(markerId) } + } + } + } + + override fun userDidTap(mapControl: MapController?, loc: Point2d?, screenLoc: Point2d?) { + super.userDidTap(mapControl, loc, screenLoc) + + markerCallback?.let { it(null) } + } + fun clear() { mapControl.removeObjects( markers.map { it.second }, @@ -101,6 +133,7 @@ class MapFragment : GlobeMapFragment() { screenMarker.image = getIcon(marker.type) screenMarker.size = markerSize screenMarker.userObject = marker.id + screenMarker.selectable = true screenMarker } 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 4a0fab2..b8f79dd 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 @@ -40,6 +40,7 @@ class UnitMapFragment : Fragment() { private fun initializeMap() { unitsMapFragment = childFragmentManager.findFragmentById(R.id.unitsMap) as MapFragment + unitsMapFragment.markerCallback = unitsViewModel::selectUnitWith } private fun setupObservers() { diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt index d8d7ea1..ca05736 100644 --- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt @@ -51,6 +51,18 @@ class UnitsViewModel( setDisplayMode(UnitsDisplayMode.MAP) } + fun selectUnitWith(positionId: Int?) { + if (positionId == null) { + Log.d("UnitsViewModel", "Deselecting unit") + _selectedUnit.postValue(null) + return + } + + Log.d("UnitsViewModel", "Selecting unit with position id: $positionId") + val unit = _units.value?.find { it.position?.id == positionId } + _selectedUnit.postValue(unit) + } + fun setDisplayMode(displayMode: UnitsDisplayMode) { Log.d("UnitsViewModel", "Setting Display mode to $displayMode") _unitsDisplayMode.postValue(displayMode) @@ -60,6 +72,7 @@ class UnitsViewModel( Log.d("UnitsViewModel", "Toggling Display mode") val newDisplayMode = if (unitsDisplayMode.value == UnitsDisplayMode.MAP) { + _selectedUnit.postValue(null) UnitsDisplayMode.LIST } else { UnitsDisplayMode.MAP |