aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2021-12-16 04:40:47 -0600
committerIván Ávalos <avalos@disroot.org>2021-12-16 04:40:47 -0600
commit11d65c96a409b07ef8270cea2984109fffd04a8d (patch)
tree1b4c2fef97af4e9f88fb5f5924077bf78dd4db47 /androidApp/src/main/java
parentd2698848d94c89555fd6c31a69e56d5aecceddb2 (diff)
downloadetbsa-trackermap-mobile-11d65c96a409b07ef8270cea2984109fffd04a8d.tar.gz
etbsa-trackermap-mobile-11d65c96a409b07ef8270cea2984109fffd04a8d.tar.bz2
etbsa-trackermap-mobile-11d65c96a409b07ef8270cea2984109fffd04a8d.zip
Show markers on map
Diffstat (limited to 'androidApp/src/main/java')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt1
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt64
2 files changed, 49 insertions, 16 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
index 6beacec..a8782cc 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesFragment.kt
@@ -15,6 +15,7 @@ import mx.trackermap.TrackerMap.android.units.UnitsViewModel
import mx.trackermap.TrackerMap.client.models.UnitInformation
import org.koin.androidx.viewmodel.ext.android.viewModel
+@DelicateCoroutinesApi
class DevicesFragment : Fragment() {
private var _binding: DevicesFragmentBinding? = null
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 125d525..f3d7cac 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
@@ -1,12 +1,14 @@
package mx.trackermap.TrackerMap.android.map
import android.graphics.BitmapFactory
+import android.graphics.Point
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.mousebird.maply.*
+import io.ktor.util.*
import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.R
import mx.trackermap.TrackerMap.android.databinding.MapFragmentBinding
@@ -57,21 +59,6 @@ class MapFragment: GlobeMapFragment() {
val longitude = -100.36 * Math.PI / 180
val zoom = 0.4
mapControl.animatePositionGeo(longitude, latitude, zoom, 1.0)
-
- insertMarkers()
- }
-
- private fun insertMarkers() {
- val markerInfo = MarkerInfo()
- val icon = BitmapFactory.decodeResource(activity!!.resources, R.drawable.map_default)
- val markerSize = Point2d(80.0, 80.0)
-
- val moscow = ScreenMarker()
- moscow.loc = Point2d.FromDegrees(37.616667, 55.75)
- moscow.image = icon
- moscow.size = markerSize
-
- mapControl.addScreenMarker(moscow, markerInfo, ThreadMode.ThreadAny)
}
override fun onDestroyView() {
@@ -88,7 +75,52 @@ class MapFragment: GlobeMapFragment() {
@DelicateCoroutinesApi
private fun setupObservers() {
unitsViewModel.units.observe(this) { units ->
- Log.d("MapFragment", "Success $units")
+ units.forEach { unit ->
+ unit.position?.let { position ->
+ if (position.longitude != null && position.longitude != null) {
+
+ /* Add marker */
+ val markerInfo = MarkerInfo()
+ val icon =
+ BitmapFactory.decodeResource(
+ activity!!.resources,
+ when (unit.device.category?.lowercase()) {
+ "animal" -> R.drawable.map_animal
+ "bicycle" -> R.drawable.map_bicycle
+ "boat" -> R.drawable.map_boat
+ "bus" -> R.drawable.map_bus
+ "car" -> R.drawable.map_car
+ "crane" -> R.drawable.map_crane
+ "default" -> R.drawable.map_default
+ "helicopter" -> R.drawable.map_helicopter
+ "motorcycle" -> R.drawable.map_motorcycle
+ "offroad" -> R.drawable.map_offroad
+ "person" -> R.drawable.map_person
+ "pickup" -> R.drawable.map_pickup
+ "plane" -> R.drawable.map_plane
+ "scooter" -> R.drawable.map_scooter
+ "ship" -> R.drawable.map_ship
+ "tractor" -> R.drawable.map_tractor
+ "train" -> R.drawable.map_train
+ "tram" -> R.drawable.map_tram
+ "trolleybus" -> R.drawable.map_trolleybus
+ "truck" -> R.drawable.map_truck
+ "van" -> R.drawable.map_van
+ else -> R.drawable.map_default
+ }
+ )
+ val markerSize = Point2d(144.0, 144.0)
+
+ val marker = ScreenMarker()
+ marker.loc = Point2d.FromDegrees(position.longitude!!, position.latitude!!)
+ marker.image = icon
+ marker.size = markerSize
+ marker.userObject = unit
+
+ mapControl.addScreenMarker(marker, markerInfo, ThreadMode.ThreadAny)
+ }
+ }
+ }
}
}
} \ No newline at end of file