-
Notifications
You must be signed in to change notification settings - Fork 1
/
Navigate.swift
62 lines (55 loc) · 3.17 KB
/
Navigate.swift
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
import SwiftUI
struct Navigate: View {
@ObservedObject var places: Places
var item: Session.Item
private var formatter: MeasurementFormatter {
let formatter = MeasurementFormatter()
formatter.unitStyle = .short
formatter.unitOptions = .naturalScale
formatter.numberFormatter.maximumFractionDigits = 1
return formatter
}
var body: some View {
ZStack {
GeometryReader { geo in
ZStack {
ForEach((2...142), id: \.self) { p in
Path {
let side = min(geo.size.width, geo.size.height) * 0.47
$0.move(to: .init(x: geo.size.width / 2, y: (geo.size.height / 2) - side - 2))
$0.addLine(to: .init(x: geo.size.width / 2, y: (geo.size.height / 2) - side + 2))
}
.stroke(Color("halo"), style: .init(lineWidth: 1, lineCap: .round)).rotationEffect(.degrees(Double(p) * 2.5))
}
Path {
let side = min(geo.size.width, geo.size.height) * 0.47
$0.addArc(center: .init(x: geo.size.width / 2, y: (geo.size.height / 2) - side), radius: 4, startAngle: .degrees(0), endAngle: .degrees(360), clockwise: true)
}
.stroke(Color("halo"), style: .init(lineWidth: 1, lineCap: .round))
Path {
let x = CGFloat(self.item.longitude - self.places.coordinate.1)
let y = CGFloat(self.places.coordinate.0 - self.item.latitude)
let side = min(geo.size.width, geo.size.height) * 0.27
let rate = max(abs(x), abs(y)) / side
$0.move(to: .init(x: geo.size.width / 2, y: geo.size.height / 2))
$0.addLine(to: .init(x: (geo.size.width / 2) + (x / rate), y: (geo.size.height / 2) + (y / rate)))
}
.stroke(Color(white: 0.1), style: .init(lineWidth: 12, lineCap: .round))
Path {
let x = CGFloat(self.item.longitude - self.places.coordinate.1)
let y = CGFloat(self.places.coordinate.0 - self.item.latitude)
let side = min(geo.size.width, geo.size.height) * 0.27
let rate = max(abs(x), abs(y)) / side
$0.addArc(center: .init(x: (geo.size.width / 2) + (x / rate), y: (geo.size.height / 2) + (y / rate)), radius: 8, startAngle: .degrees(0), endAngle: .degrees(360), clockwise: true)
}
.fill(Color("halo"))
}
}
.rotationEffect(.degrees(places.heading))
.navigationBarTitle(item.name)
Image("heading")
Text(formatter.string(from: .init(value: CLLocation(latitude: item.latitude, longitude: item.longitude).distance(from: .init(latitude: places.coordinate.0, longitude: places.coordinate.1)), unit: UnitLength.meters)))
.offset(x: 0, y: 25)
}
}
}