File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,21 @@ extension MKMapView {
6262 func isZoomedIn( maxLatitudeDelta: CLLocationDegrees = 0.005 ) -> Bool {
6363 return self . region. span. latitudeDelta <= maxLatitudeDelta
6464 }
65+
66+ func distanceForZoom( zoomLevel: Int ) -> CLLocationDistance {
67+ // Earth's circumference in meters
68+ let earthCircumference : Double = 40075016.686
69+ // Standard tile size (pixels)
70+ let tileSize : Double = 256
71+ // Get the width of the map in points and scale by screen
72+ let scale = UIScreen . main. scale
73+ let mapWidthInPixels = Double ( self . frame. size. width) * scale
74+ // Calculate meters per pixel at equator for the given zoom
75+ let metersPerPixel = earthCircumference / ( tileSize * pow( 2.0 , Double ( zoomLevel) ) )
76+ // The distance (in meters) visible in the current map width
77+ return metersPerPixel * mapWidthInPixels
78+ }
79+
6580}
6681
6782extension CLLocationCoordinate2D : CustomPersistable {
Original file line number Diff line number Diff line change @@ -265,6 +265,11 @@ struct MapView: View {
265265 selected: $viewModel. selectedOption,
266266 onSelect: { selected in
267267 viewModel. selectedOption = selected
268+ if case . wmts( let wmts) = selected {
269+ mapViewRef? . setCameraZoomRange ( MKMapView . CameraZoomRange ( minCenterCoordinateDistance: mapViewRef? . distanceForZoom ( zoomLevel: wmts. extent. maxZoom) ?? 0.0 ) , animated: true )
270+ } else {
271+ mapViewRef? . setCameraZoomRange ( nil , animated: true )
272+ }
268273 viewModel. showSatellitePicker = false
269274 addOverlay ( selectedSatilliteOption: selected)
270275 }
You can’t perform that action at this time.
0 commit comments