diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-02-01 02:23:57 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-02-01 02:23:57 -0600 |
commit | 749c239d952474979a884bfa664b9529e7f895f7 (patch) | |
tree | f40169807fe89617d428989949aaa3292982563f /iosApp/iosApp/Units/UnitsViewModel.swift | |
parent | 74b37365645dd61f8c741feedac3be313f155995 (diff) | |
download | etbsa-trackermap-mobile-749c239d952474979a884bfa664b9529e7f895f7.tar.gz etbsa-trackermap-mobile-749c239d952474979a884bfa664b9529e7f895f7.tar.bz2 etbsa-trackermap-mobile-749c239d952474979a884bfa664b9529e7f895f7.zip |
Implemented display units in map + marker callback
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: |