/** * TrackerMap * Copyright (C) 2021-2022 Iván Ávalos , Henoch Ojeda * * 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 . */ 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 } } } }