1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/**
* TrackerMap
* Copyright (C) 2021-2022 Iván Ávalos <avalos@disroot.org>, Henoch Ojeda <imhenoch@protonmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mx.trackermap.TrackerMap.client.models
data class Marker(
val id: Int,
val name: String,
val latitude: Double,
val longitude: Double,
val type: Type = Type.DEFAULT
) {
enum class Type {
ANIMAL, BACKHOE, BICYCLE, BOAT, BUS, CAR, CRANE, DEFAULT, HELICOPTER, MOTORCYCLE, OFFROAD, PERSON,
PICKUP, PLANE, SCOOTER, SHIP, TRACTOR, TRAIN, TRAM, TROLLEYBUS, TRUCK, VAN,
REPORT_POSITION, REPORT_START, REPORT_END
}
companion object {
fun fromUnit(unit: UnitInformation): Marker? {
if (unit.position?.latitude == null || unit.position.longitude == null) {
return null
}
return Marker(
unit.position.id!!,
unit.device.name,
unit.position.latitude,
unit.position.longitude,
categoryToMarkerType(unit.device.category ?: "")
)
}
fun fromPosition(position: Position): Marker? {
if (position.latitude == null || position.longitude == null) {
return null
}
return Marker(
position.id!!,
"",
position.latitude,
position.longitude
)
}
fun fromStop(stop: Stop): Marker? {
if (stop.latitude == null || stop.longitude == null) {
return null
}
return Marker(
stop.deviceId!!,
stop.deviceName!!,
stop.latitude,
stop.longitude
)
}
fun categoryToMarkerType(category: String?): Type {
return when (category?.lowercase()) {
"animal" -> Type.ANIMAL
"bicycle" -> Type.BICYCLE
"boat" -> Type.BOAT
"bus" -> Type.BUS
"car" -> Type.CAR
"crane" -> Type.CRANE
"helicopter" -> Type.HELICOPTER
"motorcycle" -> Type.MOTORCYCLE
"offroad" -> Type.OFFROAD
"person" -> Type.PERSON
"pickup" -> Type.PICKUP
"plane" -> Type.PLANE
"scooter" -> Type.SCOOTER
"ship" -> Type.SHIP
"tractor" -> Type.TRACTOR
"train" -> Type.TRAIN
"tram" -> Type.TRAM
"trolleybus" -> Type.TROLLEYBUS
"truck" -> Type.TRUCK
"van" -> Type.VAN
else -> Type.DEFAULT
}
}
}
}
|