Mercurial > public > geoquiz
comparison 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 |
comparison
equal
deleted
inserted
replaced
19:f140bb277c96 | 20:e281791e0494 |
---|---|
1 // | |
2 // CityMap.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 4/10/22. | |
6 // | |
7 | |
8 import SwiftUI | |
9 import MapKit | |
10 | |
11 struct CityMap: View { | |
12 @ObservedObject var game: CityGameController | |
13 | |
14 @StateObject var mapController: MapController | |
15 | |
16 init(game: CityGameController) { | |
17 self.game = game | |
18 self._mapController = StateObject(wrappedValue: MapController()) | |
19 } | |
20 | |
21 var body: some View { | |
22 VStack { | |
23 if let mapImage = mapController.image { | |
24 Image(uiImage: mapImage) | |
25 .resizable() | |
26 .scaledToFit() | |
27 .clipShape(Circle()) | |
28 .overlay { | |
29 Circle() | |
30 .strokeBorder(.white, lineWidth: 4) | |
31 } | |
32 .shadow(radius: 10) | |
33 } else { | |
34 ProgressView() | |
35 } | |
36 } | |
37 .onChange(of: game.correctAnswer.value) { _ in | |
38 mapController.getMapImage(lat: game.correctAnswer.value.lat, lon: game.correctAnswer.value.lon) | |
39 } | |
40 | |
41 .onAppear { | |
42 mapController.getMapImage(lat: game.correctAnswer.value.lat, lon: game.correctAnswer.value.lon) | |
43 } | |
44 } | |
45 } | |
46 | |
47 struct CityMap_Previews: PreviewProvider { | |
48 static var previews: some View { | |
49 CityMap(game: CityGameController()) | |
50 } | |
51 } |