Skip to content

Commit 06f1e75

Browse files
author
Achyut Kumar M
committed
check bbox is valid else show alert
1 parent 965639d commit 06f1e75

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct MapView: View {
4949
@State private var navigateToProfile = false
5050

5151
@State private var showManageQuestSheet = false
52+
53+
@State private var showZoomInAlert = false
5254

5355
var body: some View {
5456
NavigationStack {
@@ -145,6 +147,11 @@ struct MapView: View {
145147
.animation(.easeInOut, value: viewModel.selectedAnnotaions.count)
146148
}
147149
}
150+
.alert("Zoom in to download data", isPresented: $showZoomInAlert) {
151+
Button("OK", role: .cancel) { }
152+
} message: {
153+
Text("The map area is too large. Please zoom in and try again.")
154+
}
148155
}
149156
.environmentObject(contextualInfo)
150157
.navigationBarHidden(isPresented)
@@ -222,6 +229,13 @@ struct MapView: View {
222229

223230
case .downloadData:
224231
print("Download data here")
232+
233+
guard let mapView = mapViewRef else { return }
234+
let bbox = viewModel.boundingBoxFromVisibleMapRect(mapView: mapView)
235+
if !isBBoxValid(bbox) {
236+
showZoomInAlert = true
237+
return
238+
}
225239
guard let mapView = mapViewRef else { return }
226240
viewModel.fetchOSMDataFor(from: .visibleRect(mapView: mapView))
227241

@@ -370,6 +384,12 @@ struct MapView: View {
370384
contextualInfo.info = contextualinfo
371385

372386
}
387+
388+
func isBBoxValid(_ bbox: BBox) -> Bool {
389+
let latDelta = bbox.maxLat - bbox.minLat
390+
let lonDelta = bbox.maxLon - bbox.minLon
391+
return latDelta * lonDelta <= 1.0
392+
}
373393
}
374394

375395

GoInfoGame/GoInfoGame/UI/Map/MapViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class MapViewModel: ObservableObject {
176176
return BBox(minLat: minLat, maxLat: maxLat, minLon: minLon, maxLon: maxLon)
177177
}
178178

179-
private func boundingBoxFromVisibleMapRect(mapView: MKMapView) -> BBox {
179+
func boundingBoxFromVisibleMapRect(mapView: MKMapView) -> BBox {
180180
let mapRect = mapView.visibleMapRect
181181
let topLeft = MKMapPoint(x: mapRect.origin.x, y: mapRect.origin.y)
182182
let bottomRight = MKMapPoint(x: mapRect.origin.x + mapRect.size.width,

0 commit comments

Comments
 (0)