summaryrefslogtreecommitdiff
path: root/LearnMapKit/ContentView.swift
blob: 13ef64fa7a2445d9bb2f3d3a1ec32d214e1d75d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//
//  ContentView.swift
//  LearnMapKit
//
//  Created by Jacky Jack on 05/06/2024.
//

import SwiftUI
import MapKit
import Collections

struct FlightView: View {
    
    var evilClass: FlightState
    
    var body: some View {
        //let i = evilClass.flight.count
        let pos = CLLocationCoordinate2D(latitude: 55.80159, longitude:-3.13154)
        Map() {
            ForEach(0..<10, id:\.self) {i in
                Annotation("plane\(i)", coordinate: pos) {
                ZStack {
                 RoundedRectangle(cornerRadius: 10)
                 .fill(.background)
                 RoundedRectangle(cornerRadius: 10)
                 .stroke(.secondary,lineWidth: 5)
                 Image(systemName:"airplane.circle.fill")
                 .resizable()
                 .frame(width:20,height: 20)
                 }
                }//.annotationTitles(.hidden)
            }
        }
    }
}

struct ContentView: View {
    
    @State private var region = MKCoordinateRegion()
    @State private var isImporting = false
    
    @Binding var pos_queue: Deque<ADSBLocation>
    @EnvironmentObject var evilClass: FlightState
    
    
    let initialPosition: MapCameraPosition = {
        let center = CLLocationCoordinate2D(latitude: 55.90159, longitude:-3.53154)
        let span = MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
        let region = MKCoordinateRegion(center: center, span: span)
        return .region(region)
    }()
    
    let position1 = CLLocationCoordinate2D(latitude: 55.80159, longitude:-3.53154)
    let position2 = CLLocationCoordinate2D(latitude: 55.99159, longitude:-3.53154)
    let position3 = CLLocationCoordinate2D(latitude: 55.80159, longitude:-3.43154)
    let position4 = CLLocationCoordinate2D(latitude: 55.80159, longitude:-3.63154)
    
    var body: some View {
        
        VStack {
            HStack(alignment: .top) {
                Button("1") {
                    print("Pressed 1")
                }
                Button("2") {
                    print("Pressed 2")
                }
                Button("3") {
                    print("Pressed 3")
                }
                Button("4") {
                    print("Pressed 4")
                }
                Button("5") {
                    print("Pressed 5")
                }
                Button("6") {
                    print("Pressed 6")
                }
                Button("7") {
                    print("Pressed 7")
                    //print(evilClass.update_postions.count)
                }
            }
            .border(.blue)
            //.frame(maxWidth:.infinity)
            //.padding()
            
            Map(initialPosition: initialPosition) {
                /*Annotation("plane1", coordinate: position1) {
                    ZStack {
                        RoundedRectangle(cornerRadius: 10)
                            .fill(.background)
                        RoundedRectangle(cornerRadius: 10)
                            .stroke(.secondary,lineWidth: 5)
                        Image(systemName:"airplane.circle.fill")
                            .resizable()
                            .frame(width:20,height: 20)
                    }
                }.annotationTitles(.hidden)
                Annotation("plane2", coordinate: position2) {
                    ZStack {
                        RoundedRectangle(cornerRadius: 10)
                            .fill(.background)
                        RoundedRectangle(cornerRadius: 10)
                            .stroke(.secondary,lineWidth: 5)
                        Image(systemName:"airplane.circle.fill")
                            .resizable()
                            .frame(width:20,height: 20)
                    }
                }.annotationTitles(.hidden)
                Annotation("plane3", coordinate: position3) {
                    ZStack {
                        RoundedRectangle(cornerRadius: 10)
                            .fill(.background)
                        RoundedRectangle(cornerRadius: 10)
                            .stroke(.secondary,lineWidth: 5)
                        Image(systemName:"airplane.circle.fill")
                            .resizable()
                            .frame(width:20,height: 20)
                    }
                }.annotationTitles(.hidden)
                Annotation("plane4", coordinate: position4) {
                    ZStack {
                        RoundedRectangle(cornerRadius: 10)
                            .fill(.background)
                        RoundedRectangle(cornerRadius: 10)
                            .stroke(.secondary,lineWidth: 5)
                        Image(systemName:"airplane.circle.fill")
                            .resizable()
                            .frame(width:20,height: 20)
                    }
                }.annotationTitles(.hidden)*//*
                ForEach(0..<evilClass.flight.count, id:\.self) { _ in
                    Annotation("plane\(0)", coordinate: CLLocationCoordinate2D(latitude: evilClass.flight[0]?.lat!, longitude: evilClass.flight[0]?.long!)) {
                        ZStack {
                            RoundedRectangle(cornerRadius: 10)
                                .fill(.background)
                            RoundedRectangle(cornerRadius: 10)
                                .stroke(.secondary,lineWidth: 5)
                            Image(systemName:"airplane.circle.fill")
                                .resizable()
                                .frame(width:20,height: 20)
                        }
                    }.annotationTitles(.hidden)
                }*/
                //let c = self.evilClass.flight.count
                /*ForEach(0..<self.evilClass.flight.count, id:\.self) { exp in
                    //print("Draw annotation")
                    //Annotation("plane\(exp+4)", coordinate: CLLocationCoordinate2D(latitude: 55.80159, longitude:-3.53154+Double(exp)*0.1)) {
                    Annotation("plane\(exp+4)", coordinate: CLLocationCoordinate2D(latitude: self.evilClass.flight[exp]!.lat, longitude:self.evilClass.flight[exp]!.long)) {
                            Image(systemName:"airplane.circle.fill")
                            .resizable()
                            .frame(width:20,height: 20)
                        }
                }*/
                ForEach(self.evilClass.flight.sorted(by: { $0.key < $1.key} ), id:\.key) { k in
                    Annotation("\(k.key)", coordinate: CLLocationCoordinate2D(latitude: self.evilClass.flight[k.key]!.lat, longitude:self.evilClass.flight[k.key]!.long)) {
                            VStack {
                                ZStack {
                                    RoundedRectangle(cornerRadius: 10)
                                        .fill(.background)
                                    RoundedRectangle(cornerRadius: 10)
                                        .stroke(.secondary,lineWidth: 5)
                                    Image(systemName:"airplane.circle.fill")
                                        .resizable()
                                        .frame(width:20,height: 20)
                                }
                                Text("\(k.value.ICAOName)")
                            }
                        }.annotationTitles(.hidden)
                }
            }
            .padding()
            .border(.green)
            .layoutPriority(1)
            .mapStyle(.hybrid(elevation: .realistic))
            .toolbar {
                ToolbarItem() {
                    Button {
                        isImporting = true
                    } label: {
                        Label("Import file", systemImage: "square.and.arrow.down")
                    }
                }
            } .fileImporter(isPresented: $isImporting, allowedContentTypes: [.text], allowsMultipleSelection: false) {
                result in switch result {
                case .success(let files):
                    print(files)
                case .failure(let error):
                    print(error)
                }
            }
            drawFlights()
            
        }
        .padding()
        .border(.red)
        .layoutPriority(1)
    }
    
    func mapAction() {
        print("This is called")
    }
    
    @ViewBuilder
    func drawFlights() -> some View {
        let c = self.evilClass.flight.count
        ForEach(0..<c, id:\.self) { exp in
            //Annotation("plane4", coordinate: position4)
        }
    }
}

//#Preview {
    //ContentView(pos_queue: pos_queue)
//}