diff GeoQuiz/Components/CityMap.swift @ 20:e281791e0494

finish implementation
author Dennis C. M. <dennis@denniscm.com>
date Sun, 23 Oct 2022 11:48:39 +0100
parents GeoQuiz/Components/CityMapHelper.swift@f140bb277c96
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GeoQuiz/Components/CityMap.swift	Sun Oct 23 11:48:39 2022 +0100
@@ -0,0 +1,51 @@
+//
+//  CityMap.swift
+//  GeoQuiz
+//
+//  Created by Dennis Concepción Martín on 4/10/22.
+//
+
+import SwiftUI
+import MapKit
+
+struct CityMap: View {
+    @ObservedObject var game: CityGameController
+    
+    @StateObject var mapController: MapController
+    
+    init(game: CityGameController) {
+        self.game = game
+        self._mapController = StateObject(wrappedValue: MapController())
+    }
+    
+    var body: some View {
+        VStack {
+            if let mapImage = mapController.image {
+                Image(uiImage: mapImage)
+                    .resizable()
+                    .scaledToFit()
+                    .clipShape(Circle())
+                    .overlay {
+                        Circle()
+                            .strokeBorder(.white, lineWidth: 4)
+                    }
+                    .shadow(radius: 10)
+            } else {
+                ProgressView()
+            }
+        }
+        .onChange(of: game.correctAnswer.value) { _ in
+            mapController.getMapImage(lat: game.correctAnswer.value.lat, lon: game.correctAnswer.value.lon)
+        }
+        
+        .onAppear {
+            mapController.getMapImage(lat: game.correctAnswer.value.lat, lon: game.correctAnswer.value.lon)
+        }
+    }
+}
+
+struct CityMap_Previews: PreviewProvider {
+    static var previews: some View {
+        CityMap(game: CityGameController())
+    }
+}