From 0db6ce4a48a64a29001395b9aa27de006c139707 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Thu, 16 Dec 2021 04:40:47 -0600 Subject: Show markers on map --- .../TrackerMap/android/devices/DevicesFragment.kt | 1 + .../TrackerMap/android/map/MapFragment.kt | 64 +++++++++++++++------ androidApp/src/main/res/drawable/map_animal.png | Bin 0 -> 1074 bytes androidApp/src/main/res/drawable/map_bicycle.png | Bin 0 -> 1121 bytes androidApp/src/main/res/drawable/map_boat.png | Bin 0 -> 1066 bytes androidApp/src/main/res/drawable/map_bus.png | Bin 0 -> 1012 bytes androidApp/src/main/res/drawable/map_car.png | Bin 0 -> 1025 bytes androidApp/src/main/res/drawable/map_crane.png | Bin 0 -> 1106 bytes .../src/main/res/drawable/map_helicopter.png | Bin 0 -> 1042 bytes .../src/main/res/drawable/map_motorcycle.png | Bin 0 -> 1123 bytes androidApp/src/main/res/drawable/map_offroad.png | Bin 0 -> 1031 bytes androidApp/src/main/res/drawable/map_person.png | Bin 0 -> 957 bytes androidApp/src/main/res/drawable/map_pickup.png | Bin 0 -> 989 bytes androidApp/src/main/res/drawable/map_plane.png | Bin 0 -> 1011 bytes androidApp/src/main/res/drawable/map_scooter.png | Bin 0 -> 973 bytes androidApp/src/main/res/drawable/map_ship.png | Bin 0 -> 934 bytes androidApp/src/main/res/drawable/map_tractor.png | Bin 0 -> 1131 bytes androidApp/src/main/res/drawable/map_train.png | Bin 0 -> 1031 bytes androidApp/src/main/res/drawable/map_tram.png | Bin 0 -> 1028 bytes .../src/main/res/drawable/map_trolleybus.png | Bin 0 -> 986 bytes androidApp/src/main/res/drawable/map_truck.png | Bin 0 -> 996 bytes androidApp/src/main/res/drawable/map_van.png | Bin 0 -> 921 bytes 22 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 androidApp/src/main/res/drawable/map_animal.png create mode 100644 androidApp/src/main/res/drawable/map_bicycle.png create mode 100644 androidApp/src/main/res/drawable/map_boat.png create mode 100644 androidApp/src/main/res/drawable/map_bus.png create mode 100644 androidApp/src/main/res/drawable/map_car.png create mode 100644 androidApp/src/main/res/drawable/map_crane.png create mode 100644 androidApp/src/main/res/drawable/map_helicopter.png create mode 100644 androidApp/src/main/res/drawable/map_motorcycle.png create mode 100644 androidApp/src/main/res/drawable/map_offroad.png create mode 100644 androidApp/src/main/res/drawable/map_person.png create mode 100644 androidApp/src/main/res/drawable/map_pickup.png create mode 100644 androidApp/src/main/res/drawable/map_plane.png create mode 100644 androidApp/src/main/res/drawable/map_scooter.png create mode 100644 androidApp/src/main/res/drawable/map_ship.png create mode 100644 androidApp/src/main/res/drawable/map_tractor.png create mode 100644 androidApp/src/main/res/drawable/map_train.png create mode 100644 androidApp/src/main/res/drawable/map_tram.png create mode 100644 androidApp/src/main/res/drawable/map_trolleybus.png create mode 100644 androidApp/src/main/res/drawable/map_truck.png create mode 100644 androidApp/src/main/res/drawable/map_van.png (limited to 'androidApp') 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 diff --git a/androidApp/src/main/res/drawable/map_animal.png b/androidApp/src/main/res/drawable/map_animal.png new file mode 100644 index 0000000..c6b1043 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_animal.png differ diff --git a/androidApp/src/main/res/drawable/map_bicycle.png b/androidApp/src/main/res/drawable/map_bicycle.png new file mode 100644 index 0000000..12956f1 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_bicycle.png differ diff --git a/androidApp/src/main/res/drawable/map_boat.png b/androidApp/src/main/res/drawable/map_boat.png new file mode 100644 index 0000000..392f903 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_boat.png differ diff --git a/androidApp/src/main/res/drawable/map_bus.png b/androidApp/src/main/res/drawable/map_bus.png new file mode 100644 index 0000000..5bade66 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_bus.png differ diff --git a/androidApp/src/main/res/drawable/map_car.png b/androidApp/src/main/res/drawable/map_car.png new file mode 100644 index 0000000..17c97a2 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_car.png differ diff --git a/androidApp/src/main/res/drawable/map_crane.png b/androidApp/src/main/res/drawable/map_crane.png new file mode 100644 index 0000000..44d22bc Binary files /dev/null and b/androidApp/src/main/res/drawable/map_crane.png differ diff --git a/androidApp/src/main/res/drawable/map_helicopter.png b/androidApp/src/main/res/drawable/map_helicopter.png new file mode 100644 index 0000000..4c602f1 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_helicopter.png differ diff --git a/androidApp/src/main/res/drawable/map_motorcycle.png b/androidApp/src/main/res/drawable/map_motorcycle.png new file mode 100644 index 0000000..01e50cc Binary files /dev/null and b/androidApp/src/main/res/drawable/map_motorcycle.png differ diff --git a/androidApp/src/main/res/drawable/map_offroad.png b/androidApp/src/main/res/drawable/map_offroad.png new file mode 100644 index 0000000..38a99ce Binary files /dev/null and b/androidApp/src/main/res/drawable/map_offroad.png differ diff --git a/androidApp/src/main/res/drawable/map_person.png b/androidApp/src/main/res/drawable/map_person.png new file mode 100644 index 0000000..ed15d09 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_person.png differ diff --git a/androidApp/src/main/res/drawable/map_pickup.png b/androidApp/src/main/res/drawable/map_pickup.png new file mode 100644 index 0000000..20c49dd Binary files /dev/null and b/androidApp/src/main/res/drawable/map_pickup.png differ diff --git a/androidApp/src/main/res/drawable/map_plane.png b/androidApp/src/main/res/drawable/map_plane.png new file mode 100644 index 0000000..f5840c6 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_plane.png differ diff --git a/androidApp/src/main/res/drawable/map_scooter.png b/androidApp/src/main/res/drawable/map_scooter.png new file mode 100644 index 0000000..61995ae Binary files /dev/null and b/androidApp/src/main/res/drawable/map_scooter.png differ diff --git a/androidApp/src/main/res/drawable/map_ship.png b/androidApp/src/main/res/drawable/map_ship.png new file mode 100644 index 0000000..1e5e48b Binary files /dev/null and b/androidApp/src/main/res/drawable/map_ship.png differ diff --git a/androidApp/src/main/res/drawable/map_tractor.png b/androidApp/src/main/res/drawable/map_tractor.png new file mode 100644 index 0000000..57d2f05 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_tractor.png differ diff --git a/androidApp/src/main/res/drawable/map_train.png b/androidApp/src/main/res/drawable/map_train.png new file mode 100644 index 0000000..94ef26c Binary files /dev/null and b/androidApp/src/main/res/drawable/map_train.png differ diff --git a/androidApp/src/main/res/drawable/map_tram.png b/androidApp/src/main/res/drawable/map_tram.png new file mode 100644 index 0000000..9daf131 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_tram.png differ diff --git a/androidApp/src/main/res/drawable/map_trolleybus.png b/androidApp/src/main/res/drawable/map_trolleybus.png new file mode 100644 index 0000000..c0db490 Binary files /dev/null and b/androidApp/src/main/res/drawable/map_trolleybus.png differ diff --git a/androidApp/src/main/res/drawable/map_truck.png b/androidApp/src/main/res/drawable/map_truck.png new file mode 100644 index 0000000..319f76e Binary files /dev/null and b/androidApp/src/main/res/drawable/map_truck.png differ diff --git a/androidApp/src/main/res/drawable/map_van.png b/androidApp/src/main/res/drawable/map_van.png new file mode 100644 index 0000000..7be109e Binary files /dev/null and b/androidApp/src/main/res/drawable/map_van.png differ -- cgit v1.2.3