- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 16
Feat/mapviewcamera ops update #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -18,46 +18,82 @@ import MapLibre | |
| @MainActor | ||
| public struct MapViewProxy: Hashable, Equatable { | ||
| /// The current center coordinate of the MapView | ||
| public var centerCoordinate: CLLocationCoordinate2D { | ||
| mapView.centerCoordinate | ||
| } | ||
| public let centerCoordinate: CLLocationCoordinate2D | ||
|          | ||
|  | ||
| /// The current zoom value of the MapView | ||
| public var zoomLevel: Double { | ||
| mapView.zoomLevel | ||
| } | ||
| public let zoomLevel: Double | ||
|  | ||
| /// The current compass direction of the MapView | ||
| public var direction: CLLocationDirection { | ||
| mapView.direction | ||
| } | ||
| public let direction: CLLocationDirection | ||
|  | ||
| public var visibleCoordinateBounds: MLNCoordinateBounds { | ||
| mapView.visibleCoordinateBounds | ||
| } | ||
| /// The visible coordinate bounds of the MapView | ||
| public let visibleCoordinateBounds: MLNCoordinateBounds | ||
|  | ||
| public var mapViewSize: CGSize { | ||
| mapView.frame.size | ||
| } | ||
| /// The size of the MapView | ||
| public let mapViewSize: CGSize | ||
|  | ||
| public var contentInset: UIEdgeInsets { | ||
| mapView.contentInset | ||
| } | ||
| /// The content inset of the MapView | ||
| public let contentInset: UIEdgeInsets | ||
|  | ||
| /// The reason the view port was changed. | ||
| public let lastReasonForChange: CameraChangeReason? | ||
|  | ||
| private let mapView: MLNMapView | ||
| /// The underlying MLNMapView (only used for functions that require it) | ||
| private let mapView: MLNMapView? | ||
|  | ||
| public func convert(_ coordinate: CLLocationCoordinate2D, toPointTo: UIView?) -> CGPoint { | ||
| mapView.convert(coordinate, toPointTo: toPointTo) | ||
| /// Convert a coordinate to a point in the MapView | ||
| /// - Parameters: | ||
| /// - coordinate: The coordinate to convert | ||
| /// - toPointTo: The view to convert the point to (usually nil for the MapView itself) | ||
| /// - Returns: The CGPoint representation of the coordinate | ||
| public func convert(_ coordinate: CLLocationCoordinate2D, toPointTo: UIView?) -> CGPoint? { | ||
| guard let mapView else { | ||
| return nil | ||
| } | ||
| return mapView.convert(coordinate, toPointTo: toPointTo) | ||
| } | ||
|  | ||
| public init(mapView: MLNMapView, | ||
| lastReasonForChange: CameraChangeReason?) | ||
| { | ||
| /// Initialize with an MLNMapView (captures current values) | ||
| /// - Parameters: | ||
| /// - mapView: The MLNMapView to capture values from | ||
| /// - lastReasonForChange: The reason for the last camera change | ||
| public init(mapView: MLNMapView, lastReasonForChange: CameraChangeReason?) { | ||
| centerCoordinate = mapView.centerCoordinate | ||
| zoomLevel = mapView.zoomLevel | ||
| direction = mapView.direction | ||
| visibleCoordinateBounds = mapView.visibleCoordinateBounds | ||
| mapViewSize = mapView.frame.size | ||
| contentInset = mapView.contentInset | ||
| self.lastReasonForChange = lastReasonForChange | ||
| self.mapView = mapView | ||
| } | ||
|  | ||
| /// Initialize with explicit values (useful for testing) | ||
| /// - Parameters: | ||
| /// - centerCoordinate: The center coordinate | ||
| /// - zoomLevel: The zoom level | ||
| /// - direction: The compass direction | ||
| /// - visibleCoordinateBounds: The visible coordinate bounds | ||
| /// - mapViewSize: The size of the map view | ||
| /// - contentInset: The content inset | ||
| /// - lastReasonForChange: The reason for the last camera change | ||
| public init( | ||
| centerCoordinate: CLLocationCoordinate2D, | ||
| zoomLevel: Double, | ||
| direction: CLLocationDirection, | ||
| visibleCoordinateBounds: MLNCoordinateBounds, | ||
| mapViewSize: CGSize = CGSize(width: 320, height: 568), | ||
| contentInset: UIEdgeInsets = .zero, | ||
| lastReasonForChange: CameraChangeReason? = nil | ||
| ) { | ||
| self.centerCoordinate = centerCoordinate | ||
| self.zoomLevel = zoomLevel | ||
| self.direction = direction | ||
| self.visibleCoordinateBounds = visibleCoordinateBounds | ||
| self.mapViewSize = mapViewSize | ||
| self.contentInset = contentInset | ||
| self.lastReasonForChange = lastReasonForChange | ||
| mapView = nil | ||
| } | ||
| } | ||
|  | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create our own direction enum here, but I figured CarPlay is always available to import. Thoughts?