diff options
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt')
-rw-r--r-- | androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt new file mode 100644 index 0000000..fcde58d --- /dev/null +++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MarkerTransformations.kt @@ -0,0 +1,71 @@ +package mx.trackermap.TrackerMap.android.map + +import mx.trackermap.TrackerMap.client.models.Position +import mx.trackermap.TrackerMap.client.models.Stop +import mx.trackermap.TrackerMap.client.models.UnitInformation +import mx.trackermap.TrackerMap.utils.MarkerType + +object MarkerTransformations { + fun unitToMarker(unit: UnitInformation): MapFragment.Marker? { + if (unit.position == null || unit.position!!.latitude == null || unit.position!!.longitude == null) { + return null + } + + return MapFragment.Marker( + unit.position!!.id!!, + unit.position!!.latitude!!, + unit.position!!.longitude!!, + categoryToMarkerType(unit.device.category ?: "") + ) + } + + fun positionToMarker(position: Position): MapFragment.Marker? { + if (position.latitude == null || position.longitude == null) { + return null + } + + return MapFragment.Marker( + position.id!!, + position.latitude!!, + position.longitude!! + ) + } + + fun stopToMarker(stop: Stop): MapFragment.Marker? { + if (stop.lat == null || stop.lon == null) { + return null + } + + return MapFragment.Marker( + stop.deviceId!!, + stop.lat!!, + stop.lon!! + ) + } + + private fun categoryToMarkerType(category: String): MarkerType { + return when (category.lowercase()) { + "animal" -> MarkerType.ANIMAL + "bicycle" -> MarkerType.BICYCLE + "boat" -> MarkerType.BOAT + "bus" -> MarkerType.BUS + "car" -> MarkerType.CAR + "crane" -> MarkerType.CRANE + "helicopter" -> MarkerType.HELICOPTER + "motorcycle" -> MarkerType.MOTORCYCLE + "offroad" -> MarkerType.OFFROAD + "person" -> MarkerType.PERSON + "pickup" -> MarkerType.PICKUP + "plane" -> MarkerType.PLANE + "scooter" -> MarkerType.SCOOTER + "ship" -> MarkerType.SHIP + "tractor" -> MarkerType.TRACTOR + "train" -> MarkerType.TRAIN + "tram" -> MarkerType.TRAM + "trolleybus" -> MarkerType.TROLLEYBUS + "truck" -> MarkerType.TRUCK + "van" -> MarkerType.VAN + else -> MarkerType.DEFAULT + } + } +}
\ No newline at end of file |