@@ -25,7 +25,6 @@ class MapViewModel: ObservableObject {
2525 @Published var region = MKCoordinateRegion ( )
2626 let viewSpanDelta = 0.005 // Delta lat/lng to show to the user
2727 // var userlocation = CLLocationCoordinate2D(latitude: 17.4700, longitude: 78.3534)
28- @Published var userlocation : CLLocationCoordinate2D ? = nil
2928 @Published var refreshMap = UUID ( )
3029 @Published var items : [ DisplayUnitWithCoordinate ] = [ ]
3130 @Published var selectedQuest : DisplayUnit ?
@@ -41,14 +40,13 @@ class MapViewModel: ObservableObject {
4140 locationManagerDelegate. locationUpdateHandler = { [ weak self] location in
4241 guard let self = self else { return }
4342
44- DispatchQueue . main. async {
45- self . userlocation = location
43+ DispatchQueue . main. async { [ unowned self] in
4644 self . region = MKCoordinateRegion (
4745 center: location,
4846 span: MKCoordinateSpan ( latitudeDelta: self . viewSpanDelta, longitudeDelta: self . viewSpanDelta)
4947 )
50- self . fetchOSMDataFor ( from: . currentLocation( location: location) )
5148 }
49+ self . fetchOSMDataFor ( from: . currentLocation( location: location) )
5250 }
5351
5452 locationManagerDelegate. requestLocationAuthorization ( )
@@ -115,24 +113,26 @@ class MapViewModel: ObservableObject {
115113 }
116114
117115 if let workspaceID = KeychainManager . load ( key: " workspaceID " ) {
118-
116+ debugPrint ( " requested: start \( Date ( ) ) " )
119117 ApiManager . shared. performRequest ( to: . fetchOSMElements( bBox. minLon, bBox. minLat, bBox. maxLon, bBox. maxLat, workspaceID) , setupType: . osm, modelType: OSMMapDataResponse . self) { [ unowned self] result in
120118 switch result {
121119 case . success( let success) :
120+ debugPrint ( " response sucess: start \( Date ( ) ) " )
122121 let osmElements = success. getOSMElements ( )
123122 // print("OSM ELEMENTS ??? \(osmElements)")
124-
123+ debugPrint ( " saveOSMElements: start \( Date ( ) ) " )
125124 let response = Array ( osmElements. values)
126- let allValues = response
127-
128- DispatchQueue . main . async { [ unowned self , allValues ] in
129- self . dbInstance . saveOSMElements ( allValues ) // Save all where there are tags
130- autoreleasepool { [ unowned self ] in
131- self . items = AppQuestManager . shared . fetchQuestsFromDB ( )
132- }
125+ self . dbInstance . saveOSMElements ( response ) // Save all where there are tags
126+ debugPrint ( " saveOSMElements: end \( Date ( ) ) " )
127+ debugPrint ( " fetchQuestsFromDB: start \( Date ( ) ) " )
128+ let items = AppQuestManager . shared . fetchQuestsFromDB ( )
129+ debugPrint ( " fetchQuestsFromDB: end \( Date ( ) ) " )
130+ DispatchQueue . main . async { [ unowned self, items] in
131+ self . items = items
133132 self . isLoading = false
134133 if self . items. count == 0 { self . refreshMap = UUID ( ) }
135134 }
135+ debugPrint ( " response sucess: end \( Date ( ) ) " )
136136 case . failure( let failure) :
137137 print ( failure)
138138 }
0 commit comments