Karten: zentriert auf Standort + Re-Center-Button

- GiftkoederView: Map.position als State (war initialPosition, einmalig),
  Re-Center-Button rechts oben (location.fill in Capsule auf material),
  bei Standort-Update wird Kamera mit easeInOut animiert auf Position
- VerloreneHundeView: dieselbe Map-Struktur ergänzt, fehlte komplett.
  Pins als magnifyingglass.circle.fill in Akzentfarbe, tappable → öffnet
  LostDogDetailView als Sheet (mit eigenem 'Schließen'-Button)
This commit is contained in:
rene 2026-05-30 13:37:42 +02:00
parent fb00468c8c
commit a6ea7b5b8f
2 changed files with 147 additions and 44 deletions

View file

@ -7,6 +7,7 @@ struct GiftkoederView: View {
@State private var isLoading = false
@State private var errorMessage: String?
@State private var showReport = false
@State private var cameraPosition: MapCameraPosition = .automatic
var body: some View {
Group {
@ -37,6 +38,7 @@ struct GiftkoederView: View {
}
.task { location.request() }
.onChange(of: location.coordinate?.latitude) { _, _ in
if let c = location.coordinate { centerOn(c) }
Task { await load() }
}
.sheet(isPresented: $showReport) {
@ -48,10 +50,7 @@ struct GiftkoederView: View {
private func content(at coord: CLLocationCoordinate2D) -> some View {
VStack(spacing: 0) {
Map(initialPosition: .region(MKCoordinateRegion(
center: coord,
span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
))) {
Map(position: $cameraPosition) {
UserAnnotation()
ForEach(alerts) { alert in
Annotation(alert.typ ?? "Giftköder",
@ -67,6 +66,20 @@ struct GiftkoederView: View {
}
.frame(height: 260)
.ignoresSafeArea(edges: .top)
.overlay(alignment: .topTrailing) {
Button {
centerOn(coord)
} label: {
Image(systemName: "location.fill")
.font(.callout.bold())
.foregroundStyle(Color.accentColor)
.padding(10)
.background(.thinMaterial, in: Circle())
.shadow(radius: 2)
}
.padding(.top, 60)
.padding(.trailing, 12)
}
if alerts.isEmpty && !isLoading {
ContentUnavailableView(
@ -85,6 +98,15 @@ struct GiftkoederView: View {
}
}
private func centerOn(_ coord: CLLocationCoordinate2D) {
withAnimation(.easeInOut(duration: 0.4)) {
cameraPosition = .region(MKCoordinateRegion(
center: coord,
span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
))
}
}
private func load() async {
guard let coord = location.coordinate else { return }
isLoading = true