Skip to content

Commit

Permalink
proof of concept, adjust camera to bounding box
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-Kladek committed Feb 25, 2024
1 parent a41e1b9 commit 1649514
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions Sources/MapLibreSwiftUI/Models/MapCamera/MapViewCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 1649514

Please sign in to comment.