67 lines
1.7 KiB
Swift
67 lines
1.7 KiB
Swift
//
|
|
// MapScreen.swift
|
|
// AutoCat
|
|
//
|
|
// Created by Selim Mustafaev on 13.04.2025.
|
|
// Copyright © 2025 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import MapKit
|
|
import ClusterMapSwiftUI
|
|
import AutoCatCore
|
|
|
|
struct MapScreen: View {
|
|
|
|
@Environment(\.dismiss) var dismiss
|
|
@Environment(\.horizontalSizeClass) var horizontalSizeClass
|
|
|
|
@State var viewModel: MapViewModel
|
|
|
|
init(mapInput: MapInput) {
|
|
|
|
self.viewModel = MapViewModel(
|
|
apiService: ServiceContainer.shared.resolve(ApiServiceProtocol.self),
|
|
mapInput: mapInput
|
|
)
|
|
}
|
|
|
|
var body: some View {
|
|
Map {
|
|
ForEach(viewModel.markers) {
|
|
Marker($0.title, coordinate: $0.coordinate)
|
|
}
|
|
ForEach(viewModel.clusters) {
|
|
Marker($0.title, coordinate: $0.coordinate)
|
|
}
|
|
}
|
|
.onAppear {
|
|
Task { await viewModel.onAppear() }
|
|
}
|
|
.hud($viewModel.hud)
|
|
.navigationTitle(viewModel.title)
|
|
.titleModeInline()
|
|
.readSize { newValue in
|
|
viewModel.mapSize = newValue
|
|
}
|
|
.onMapCameraChange { context in
|
|
viewModel.currentRegion = context.region
|
|
}
|
|
.onMapCameraChange(frequency: .onEnd) { context in
|
|
Task.detached {
|
|
await viewModel.reloadMarkers()
|
|
}
|
|
}
|
|
.toolbar {
|
|
if horizontalSizeClass == .regular {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
Button("Close") {
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.hideTabBar()
|
|
}
|
|
}
|