diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-06-12 08:06:30 +0100 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2024-06-12 08:06:30 +0100 |
commit | de4f742388002e5b8307903369727300dd3e6049 (patch) | |
tree | fda333de6620849b5c12556f5022a4722da02f76 /LearnMapKit/ContentView.swift | |
parent | 86c489c3c8ab1fa46fdcae022289f414f2de04cd (diff) | |
download | ADSBDecoder-de4f742388002e5b8307903369727300dd3e6049.tar.gz ADSBDecoder-de4f742388002e5b8307903369727300dd3e6049.zip |
Add MapKit demo code
Diffstat (limited to 'LearnMapKit/ContentView.swift')
-rw-r--r-- | LearnMapKit/ContentView.swift | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/LearnMapKit/ContentView.swift b/LearnMapKit/ContentView.swift new file mode 100644 index 0000000..d9e3377 --- /dev/null +++ b/LearnMapKit/ContentView.swift @@ -0,0 +1,119 @@ +// +// ContentView.swift +// LearnMapKit +// +// Created by Jacky Jack on 05/06/2024. +// + +import SwiftUI +import MapKit + +struct ContentView: View { + + + @State private var region = MKCoordinateRegion() + + 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") + } + } + .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)) + + + } + .padding() + .border(.red) + .layoutPriority(1) + } +} + +#Preview { + ContentView() +} |