diff options
Diffstat (limited to 'iosApp/iosApp/Units/UnitsViewModel.swift')
-rw-r--r-- | iosApp/iosApp/Units/UnitsViewModel.swift | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/iosApp/iosApp/Units/UnitsViewModel.swift b/iosApp/iosApp/Units/UnitsViewModel.swift index 04c0436..dc6236f 100644 --- a/iosApp/iosApp/Units/UnitsViewModel.swift +++ b/iosApp/iosApp/Units/UnitsViewModel.swift @@ -49,7 +49,12 @@ class UnitsViewModel: ObservableObject { } @Published var isEditing = false @Published var unitsDisplayMode: UnitsDisplayMode = .list - @Published var units: [UnitInformation] = [] + @Published var units: [UnitInformation] = [] { + didSet { + markers = units.compactMap(Marker.companion.fromUnit) + } + } + @Published var markers: [Marker] = [] @Published var selectedUnit: UnitInformation? = nil @Published var mapLayerType: MapLayer = .companion.defaultLayer @Published var geofences: [Int: Geofence] = [:] @@ -81,6 +86,20 @@ class UnitsViewModel: ObservableObject { self.geofences = geofences } + func selectUnitWith(position id: Int32?) { + if id == nil { + print("Deselecting unit") + selectedUnit = nil + return + } + print("Selecting unit with position id: \(id ?? 0)") + if let unit = units.first(where: { + Int32(truncating: $0.position?.id ?? 0) == id + }) { + selectedUnit = unit + } + } + func toggleDisplayMode() { switch unitsDisplayMode { case .map: |