summaryrefslogtreecommitdiff
path: root/LearnMapKit/ContentView.swift
blob: 08f419221dcb0f6bf4b09bec3770e9c62a48bd40 (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
//
//  ContentView.swift
//  LearnMapKit
//
//  Created by Jacky Jack on 05/06/2024.
//

import SwiftUI
import MapKit
import Collections

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)
            }
            .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)
                }
            }
            
            
        }
        .padding()
        .border(.red)
        .layoutPriority(1)
    }
}

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