-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Camera.swift
43 lines (38 loc) · 1.28 KB
/
Camera.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
import CoreLocation
import SwiftUI
struct CameraDirectManipulationPreview: View {
@State private var camera = MapViewCamera.center(switzerland, zoom: 4)
let styleURL: URL
var onStyleLoaded: (() -> Void)? = nil
var targetCameraAfterDelay: MapViewCamera? = nil
var body: some View {
MapView(styleURL: styleURL, camera: $camera)
.onStyleLoaded { _ in
onStyleLoaded?()
}
.overlay(alignment: .bottom, content: {
Text("\(String(describing: camera.state))")
.padding()
.foregroundColor(.white)
.background(
Rectangle()
.foregroundColor(.black)
.cornerRadius(8)
)
.padding(.bottom, 42)
})
.task {
if let targetCameraAfterDelay {
try? await Task.sleep(nanoseconds: 3 * NSEC_PER_SEC)
camera = targetCameraAfterDelay
}
}
}
}
#Preview("Camera Zoom after delay") {
CameraDirectManipulationPreview(
styleURL: demoTilesURL,
targetCameraAfterDelay: .center(switzerland, zoom: 6)
)
.ignoresSafeArea(.all)
}