Skip to content

Commit 8be3c4f

Browse files
authored
Merge pull request #231 from TaskarCenterAtUW/fix-download-data-zoom-restriction
check bbox is valid else show alert
2 parents 965639d + 57f615b commit 8be3c4f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 19 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,7 +229,13 @@ struct MapView: View {
222229

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

228241
}
@@ -370,6 +383,12 @@ struct MapView: View {
370383
contextualInfo.info = contextualinfo
371384

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

375394

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)