aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map
diff options
context:
space:
mode:
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.kt71
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt9
2 files changed, 64 insertions, 16 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 ebd75fb..681a21f 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.Bitmap
-import android.graphics.BitmapFactory
+import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import androidx.core.content.res.ResourcesCompat
+import androidx.core.graphics.drawable.toBitmap
import com.mousebird.maply.*
import java.io.File
import mx.trackermap.TrackerMap.android.R
@@ -25,7 +27,7 @@ class MapFragment : GlobeMapFragment() {
var markerCallback: MarkerCallback? = null
- private val markers = mutableListOf<Pair<ScreenMarker, ComponentObject>>()
+ private val objects = mutableListOf<ComponentObject>()
override fun chooseDisplayType(): MapDisplayType {
return MapDisplayType.Map
@@ -93,35 +95,77 @@ class MapFragment : GlobeMapFragment() {
markerCallback?.let { it(null) }
}
- fun clear() {
+ private fun clear() {
mapControl.removeObjects(
- markers.map { it.second },
+ objects,
ThreadMode.ThreadAny
)
+ objects.clear()
}
- fun display(markers: Array<Marker>) {
+ fun display(markers: Array<Marker>, isReport: Boolean) {
Log.d("MapFragment", "Displaying markers")
clear()
- val screenMarkers = markers.map { marker ->
+ val screenMarkers = markers.mapIndexed { i, marker ->
val screenMarker = ScreenMarker()
val markerSize = Point2d(144.0, 144.0)
screenMarker.loc = Point2d.FromDegrees(marker.longitude, marker.latitude)
- screenMarker.image = getIcon(marker.type)
+ screenMarker.image = if (isReport) {
+ when (i) {
+ 0 -> getIcon(MarkerType.REPORT_START)
+ markers.size - 1 -> getIcon(MarkerType.REPORT_END)
+ else -> getIcon(MarkerType.REPORT_POSITION)
+ }
+ } else getIcon(marker.type)
screenMarker.size = markerSize
screenMarker.userObject = marker.id
screenMarker.selectable = true
screenMarker
}
- mapControl.addScreenMarkers(
+
+ objects.add(mapControl.addScreenMarkers(
screenMarkers,
MarkerInfo(),
ThreadMode.ThreadAny
- )
+ ))
+
+ if (isReport && markers.isNotEmpty()) {
+ Log.d("MapFragment", "Displaying report")
+
+ val points = markers.map { marker ->
+ Point2d.FromDegrees(marker.longitude, marker.latitude)
+ }.toTypedArray()
+
+ // Draw polyline
+ val vector = VectorObject()
+ vector.addAreal(points)
+
+ val vectorInfo = VectorInfo()
+ vectorInfo.setColor(Color.GREEN)
+ vectorInfo.setLineWidth(25.0f)
+
+ objects.add(mapControl.addVector(
+ vector,
+ vectorInfo,
+ ThreadMode.ThreadAny
+ ))
+
+ // Center map to polyline bounds
+ val mbr = Mbr()
+ points.forEach {
+ mbr.addPoint(it)
+ }
+ mbr.expandByFraction(0.1)
+
+ mapControl.addPostSurfaceRunnable {
+ val zoom = mapControl.findHeightToViewBounds(mbr, mbr.middle())
+ mapControl.setPositionGeo(mbr.middle(), zoom)
+ }
+ }
}
fun focusOn(latitude: Double, longitude: Double, zoom: Double = 0.0000144, animated: Boolean = true) {
@@ -135,7 +179,7 @@ class MapFragment : GlobeMapFragment() {
}
private fun getIcon(markerType: MarkerType): Bitmap {
- return BitmapFactory.decodeResource(
+ return ResourcesCompat.getDrawable(
activity!!.resources,
when (markerType) {
MarkerType.ANIMAL -> R.drawable.map_animal
@@ -159,7 +203,10 @@ class MapFragment : GlobeMapFragment() {
MarkerType.TROLLEYBUS -> R.drawable.map_trolleybus
MarkerType.TRUCK -> R.drawable.map_truck
MarkerType.VAN -> R.drawable.map_van
- }
- )
+
+ MarkerType.REPORT_POSITION -> R.drawable.map_report_position
+ MarkerType.REPORT_START -> R.drawable.map_report_start
+ MarkerType.REPORT_END -> R.drawable.map_report_end
+ }, activity!!.theme)!!.toBitmap(144, 144)
}
} \ No newline at end of file
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 427f020..3c34abb 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
@@ -56,7 +56,8 @@ class UnitMapFragment : Fragment() {
Log.d("UnitMapFragment", "Available units: $units")
unitsMapFragment.display(
- units.mapNotNull(MarkerTransformations::unitToMarker).toTypedArray()
+ units.mapNotNull(MarkerTransformations::unitToMarker).toTypedArray(),
+ isReport = false
)
}
@@ -92,9 +93,9 @@ class UnitMapFragment : Fragment() {
engineStopIcon.visibility = View.VISIBLE
engineStopIcon.setImageResource(
when (attributes["out1"].toString()) {
- "true" -> R.drawable.ic_baseline_lock_24
- "false" -> R.drawable.ic_baseline_lock_open_24
- else -> R.drawable.ic_baseline_lock_open_24
+ "true" -> R.drawable.device_unlocked
+ "false" -> R.drawable.device_locked
+ else -> R.drawable.device_locked
}
)
engineStopIcon.contentDescription =