diff --git a/Sources/MapLibreSwiftUI/MapViewCoordinator.swift b/Sources/MapLibreSwiftUI/MapViewCoordinator.swift index 9f9ceff..30cbc7f 100644 --- a/Sources/MapLibreSwiftUI/MapViewCoordinator.swift +++ b/Sources/MapLibreSwiftUI/MapViewCoordinator.swift @@ -61,7 +61,11 @@ public class MapViewCoordinator: NSObject { case .trackingUserLocationWithCourse: mapView.userTrackingMode = .followWithCourse mapView.setZoomLevel(camera.zoom, animated: false) - case .rect, .showcase: + case let .rect(northeast, southwest): + let bounds = MLNCoordinateBounds(sw: southwest, ne: northeast) + let padding: UIEdgeInsets = .init(top: 20, left: 20, bottom: 20, right: 20) + (mapView as? MLNMapView)?.setVisibleCoordinateBounds(bounds, edgePadding: padding, animated: animated, completionHandler: nil) + case .showcase: // TODO: Need a method these/or to finalize a goal here. break } diff --git a/Sources/MapLibreSwiftUI/Models/MapCamera/MapViewCamera.swift b/Sources/MapLibreSwiftUI/Models/MapCamera/MapViewCamera.swift index cdaa807..9340b7a 100644 --- a/Sources/MapLibreSwiftUI/Models/MapCamera/MapViewCamera.swift +++ b/Sources/MapLibreSwiftUI/Models/MapCamera/MapViewCamera.swift @@ -117,4 +117,17 @@ public struct MapViewCamera: Hashable { } // TODO: Create init methods for other camera states once supporting materials are understood (e.g. BoundingBox) + + public static func boundingBox(northeast: CLLocationCoordinate2D, + southwest: CLLocationCoordinate2D, + zoom: Double, + pitch: CameraPitch = Defaults.pitch, + direction: CLLocationDirection = Defaults.direction, + reason: CameraChangeReason? = nil) -> MapViewCamera { + return MapViewCamera(state: .rect(northeast: northeast, southwest: southwest), + zoom: zoom, + pitch: pitch, + direction: direction, + lastReasonForChange: reason) + } }