-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add support for camera bounding box #23
Changes from 3 commits
1649514
2b72fe7
9c78e13
004ce94
dfc7526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ public enum CameraState: Hashable { | |
case trackingUserLocationWithCourse | ||
|
||
/// Centered on a bounding box/rectangle. | ||
case rect(northeast: CLLocationCoordinate2D, southwest: CLLocationCoordinate2D) // TODO: make a bounding box? | ||
case rect(boundingBox: MLNCoordinateBounds, edgePadding: UIEdgeInsets = .init(top: 20, left: 20, bottom: 20, right: 20)) | ||
|
||
/// Showcasing GeoJSON, Polygons, etc. | ||
case showcase(shapeCollection: MLNShapeCollection) | ||
|
@@ -44,10 +44,32 @@ extension CameraState: CustomDebugStringConvertible { | |
return "CameraState.trackingUserLocationWithHeading" | ||
case .trackingUserLocationWithCourse: | ||
return "CameraState.trackingUserLocationWithCourse" | ||
case .rect(northeast: let northeast, southwest: let southwest): | ||
return "CameraState.rect(northeast: \(northeast), southwest: \(southwest))" | ||
case .rect(boundingBox: let boundingBox, _): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now merged @Patrick-Kladek. Can you merge with the main branch and then run |
||
return "CameraState.rect(northeast: \(boundingBox.ne), southwest: \(boundingBox.sw))" | ||
case .showcase(shapeCollection: let shapeCollection): | ||
return "CameraState.showcase(shapeCollection: \(shapeCollection))" | ||
} | ||
} | ||
} | ||
|
||
extension MLNCoordinateBounds: Equatable, Hashable { | ||
|
||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(self.ne) | ||
hasher.combine(self.sw) | ||
} | ||
|
||
public static func == (lhs: MLNCoordinateBounds, rhs: MLNCoordinateBounds) -> Bool { | ||
return lhs.ne == rhs.ne && lhs.sw == rhs.sw | ||
} | ||
} | ||
|
||
extension UIEdgeInsets: Hashable { | ||
|
||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(self.left) | ||
hasher.combine(self.right) | ||
hasher.combine(self.top) | ||
hasher.combine(self.bottom) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,21 @@ public struct MapViewCamera: Hashable { | |
direction: Defaults.direction, | ||
lastReasonForChange: .programmatic) | ||
} | ||
|
||
// TODO: Create init methods for other camera states once supporting materials are understood (e.g. BoundingBox) | ||
|
||
/// Positions the camera to show a specific region in the MapView. | ||
/// | ||
/// - Parameters: | ||
/// - box: Set the desired bounding box. This is a one time event and the user can manipulate by moving the map. | ||
/// - edgePadding: Set the edge insets that should be applied before positioning the map. | ||
/// - Returns: The MapViewCamera representing the scenario | ||
public static func boundingBox(_ box: MLNCoordinateBounds, edgePadding: UIEdgeInsets = .init(top: 20, left: 20, bottom: 20, right: 20)) -> MapViewCamera { | ||
// zoom, pitch & direction are ignored. | ||
return MapViewCamera(state: .rect(boundingBox: box, edgePadding: edgePadding), | ||
zoom: 1, | ||
pitch: Defaults.pitch, | ||
direction: Defaults.direction, | ||
lastReasonForChange: .programmatic) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit unsure about this: 1st how do we pass the edge padding to the camera? This works but I don't know if it's the best solution. 2nd and more importantly: zoom, pitch & direction are ignored for this camera setup. Wouldn't it make more sense to add these parameters as associated values to the respective (CameraState) enum cases? Otherwise adding parameters that are ignored might cause some confusion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EdgeInsets PaddingI think we're on the right track here, but this presents an interesting trade off we need to discuss:
This same discussion applies to the bounding box definition type as well Zoom, Pitch & DirectionThis is a good question. We had a similar issue deciding how to handle the I think the boundingBox case suggests we should do the same for Any additional thoughts @ianthetechie? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// TODO: Create init methods for other camera states once supporting materials are understood (e.g. BoundingBox) | ||
} |
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.
Once we decide on the right option for padding discussed in my large comment below, we can update this and put the defaults in the
Defaults
struct.