summaryrefslogtreecommitdiff
path: root/LearnMapKit/ContentView.swift
blob: cbe178f6b5592f1f9dba395376a2628010e97267 (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
//
//  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 net_config: NetworkConfigure
    @EnvironmentObject var flightState: FlightState
    @Environment(\.openWindow) private var openWindow
    
    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 {
            Map(initialPosition: initialPosition) {
                ForEach(flightState.flight) { flight in
                    Annotation(flight.ICAOName,
                               coordinate: CLLocationCoordinate2D(
                                latitude: flight.lat,
                                longitude:flight.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("\(flight.ICAOName)").font(.body)
                            }*/
                            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("\(flight.ICAOName)").font(.body)
                        }
                    }.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")
                    }
                }*//*
                ToolbarItem {
                    Button {
                        openWindow(id: "net-config")
                    } label: {
                        Label("Network config", systemImage: "network")
                    }
                }
            }*/ /*.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)
    }
    
    func mapAction() {
        print("This is called")
    }
    
}

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