diff options
Diffstat (limited to 'LearnMapKit/ContentView.swift')
-rw-r--r-- | LearnMapKit/ContentView.swift | 85 |
1 files changed, 81 insertions, 4 deletions
diff --git a/LearnMapKit/ContentView.swift b/LearnMapKit/ContentView.swift index 08f4192..13ef64f 100644 --- a/LearnMapKit/ContentView.swift +++ b/LearnMapKit/ContentView.swift @@ -9,6 +9,31 @@ 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() @@ -17,6 +42,7 @@ struct ContentView: View { @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) @@ -53,7 +79,7 @@ struct ContentView: View { } Button("7") { print("Pressed 7") - print(evilClass.update_postions.count) + //print(evilClass.update_postions.count) } } .border(.blue) @@ -61,7 +87,7 @@ struct ContentView: View { //.padding() Map(initialPosition: initialPosition) { - Annotation("plane1", coordinate: position1) { + /*Annotation("plane1", coordinate: position1) { ZStack { RoundedRectangle(cornerRadius: 10) .fill(.background) @@ -104,7 +130,46 @@ struct ContentView: View { .resizable() .frame(width:20,height: 20) } - }.annotationTitles(.hidden) + }.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) @@ -126,13 +191,25 @@ struct ContentView: View { 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 { |