Skip to content

Commit

Permalink
run swiftformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-Kladek committed Mar 12, 2024
1 parent 004ce94 commit dfc7526
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ protocol MLNMapViewCameraUpdating: AnyObject {
direction: CLLocationDirection,
animated: Bool)
func setZoomLevel(_ zoomLevel: Double, animated: Bool)
func setVisibleCoordinateBounds(_ bounds: MLNCoordinateBounds, edgePadding: UIEdgeInsets, animated: Bool, completionHandler: (() -> Void)?)
func setVisibleCoordinateBounds(
_ bounds: MLNCoordinateBounds,
edgePadding: UIEdgeInsets,
animated: Bool,
completionHandler: (() -> Void)?
)
}

extension MLNMapView: MLNMapViewCameraUpdating {
Expand Down
10 changes: 5 additions & 5 deletions Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public class MapViewCoordinator: NSObject {
case .trackingUserLocationWithCourse:
mapView.userTrackingMode = .followWithCourse
mapView.setZoomLevel(camera.zoom, animated: false)
case let .rect(boundingBox, padding):
mapView.setVisibleCoordinateBounds(boundingBox,
edgePadding: padding,
animated: animated,
completionHandler: nil)
case let .rect(boundingBox, padding):
mapView.setVisibleCoordinateBounds(boundingBox,
edgePadding: padding,
animated: animated,
completionHandler: nil)
case .showcase:
// TODO: Need a method these/or to finalize a goal here.
break
Expand Down
41 changes: 21 additions & 20 deletions Sources/MapLibreSwiftUI/Models/MapCamera/CameraState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public enum CameraState: Hashable {
case trackingUserLocationWithCourse

/// Centered on a bounding box/rectangle.
case rect(boundingBox: MLNCoordinateBounds, edgePadding: UIEdgeInsets = .init(top: 20, left: 20, bottom: 20, right: 20))
case rect(
boundingBox: MLNCoordinateBounds,
edgePadding: UIEdgeInsets = .init(top: 20, left: 20, bottom: 20, right: 20)
)

/// Showcasing GeoJSON, Polygons, etc.
case showcase(shapeCollection: MLNShapeCollection)
Expand All @@ -42,32 +45,30 @@ extension CameraState: CustomDebugStringConvertible {
"CameraState.trackingUserLocationWithHeading"
case .trackingUserLocationWithCourse:
"CameraState.trackingUserLocationWithCourse"
case .rect(boundingBox: let boundingBox, _):
"CameraState.rect(northeast: \(boundingBox.ne), southwest: \(boundingBox.sw))"
case .showcase(shapeCollection: let shapeCollection):
case let .rect(boundingBox: boundingBox, _):
"CameraState.rect(northeast: \(boundingBox.ne), southwest: \(boundingBox.sw))"
case let .showcase(shapeCollection: shapeCollection):
"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
}
public func hash(into hasher: inout Hasher) {
hasher.combine(ne)
hasher.combine(sw)
}

public static func == (lhs: MLNCoordinateBounds, rhs: MLNCoordinateBounds) -> Bool {
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)
}
public func hash(into hasher: inout Hasher) {
hasher.combine(left)
hasher.combine(right)
hasher.combine(top)
hasher.combine(bottom)
}
}
33 changes: 18 additions & 15 deletions Sources/MapLibreSwiftUI/Models/MapCamera/MapViewCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,22 @@ public struct MapViewCamera: Hashable {
direction: Defaults.direction,
lastReasonForChange: .programmatic)
}

/// 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)
}

/// 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.
MapViewCamera(state: .rect(boundingBox: box, edgePadding: edgePadding),
zoom: 1,
pitch: Defaults.pitch,
direction: Defaults.direction,
lastReasonForChange: .programmatic)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ final class CameraStateTests: XCTestCase {
func testRect() {
let northeast = CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4)
let southwest = CLLocationCoordinate2D(latitude: 34.5, longitude: 45.6)
let state: CameraState = .rect(boundingBox: .init(sw: southwest, ne: northeast))
XCTAssertEqual(state, .rect(boundingBox: .init(sw: southwest, ne: northeast)))

let state: CameraState = .rect(boundingBox: .init(sw: southwest, ne: northeast))
XCTAssertEqual(state, .rect(boundingBox: .init(sw: southwest, ne: northeast)))

XCTAssertEqual(
String(describing: state),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ final class MapViewCameraTests: XCTestCase {
XCTAssertEqual(camera.pitch, .free)
XCTAssertEqual(camera.direction, 0)
}

func testBoundingBox() {
let southwest = CLLocationCoordinate2D(latitude: 24.6056011, longitude: 46.67369842529297)
let northeast = CLLocationCoordinate2D(latitude: 24.6993808, longitude: 46.7709285)
let bounds = MLNCoordinateBounds(sw: southwest, ne: northeast)
let camera = MapViewCamera.boundingBox(bounds)

XCTAssertEqual(camera.state, .rect(boundingBox: bounds, edgePadding: .init(top: 20, left: 20, bottom: 20, right: 20)))
XCTAssertEqual(camera.zoom, 1)
XCTAssertEqual(camera.pitch, .free)
XCTAssertEqual(camera.direction, 0)
}

func testBoundingBox() {
let southwest = CLLocationCoordinate2D(latitude: 24.6056011, longitude: 46.67369842529297)
let northeast = CLLocationCoordinate2D(latitude: 24.6993808, longitude: 46.7709285)
let bounds = MLNCoordinateBounds(sw: southwest, ne: northeast)
let camera = MapViewCamera.boundingBox(bounds)

XCTAssertEqual(
camera.state,
.rect(boundingBox: bounds, edgePadding: .init(top: 20, left: 20, bottom: 20, right: 20))
)
XCTAssertEqual(camera.zoom, 1)
XCTAssertEqual(camera.pitch, .free)
XCTAssertEqual(camera.direction, 0)
}

// TODO: Add additional camera tests once behaviors are added (e.g. rect)
}

0 comments on commit dfc7526

Please sign in to comment.