Skip to content

Commit

Permalink
Updated version to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Archdoog committed Feb 8, 2024
1 parent d3d0ec8 commit ad561ea
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
10 changes: 8 additions & 2 deletions Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@ public class MapViewCoordinator: NSObject {
}

// MARK: - Coordinator API - Camera + Manipulation


/// Update the camera based on the MapViewCamera binding change.
///
/// - Parameters:
/// - mapView: This is the camera updating protocol representation of the MLNMapView. This allows mockable testing for camera related MLNMapView functionality.
/// - camera: The new camera from the binding.
/// - animated: Whether to animate.
func updateCamera(mapView: MLNMapViewCameraUpdating, camera: MapViewCamera, animated: Bool) {
guard camera != snapshotCamera else {
// No action - camera has not changed.
return
}

switch camera.state {
case .coordinate(let coordinate):
case .centered(onCoordinate: let coordinate):
mapView.userTrackingMode = .none
mapView.setCenter(coordinate,
zoomLevel: camera.zoom,
Expand Down
6 changes: 3 additions & 3 deletions Sources/MapLibreSwiftUI/Models/MapCamera/CameraState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import MapLibre
public enum CameraState: Hashable {

/// Centered on a coordinate
case coordinate(onCenter: CLLocationCoordinate2D)
case centered(onCoordinate: CLLocationCoordinate2D)

/// Follow the user's location using the MapView's internal camera.
///
Expand Down Expand Up @@ -36,8 +36,8 @@ extension CameraState: CustomDebugStringConvertible {
public var debugDescription: String {
switch self {

case .coordinate(onCenter: let onCenter):
return "CameraState.coordinate(onCenter: \(onCenter)"
case .centered(onCoordinate: let onCoordinate):
return "CameraState.centered(onCoordinate: \(onCoordinate)"
case .trackingUserLocation:
return "CameraState.trackingUserLocation"
case .trackingUserLocationWithHeading:
Expand Down
4 changes: 2 additions & 2 deletions Sources/MapLibreSwiftUI/Models/MapCamera/MapViewCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public struct MapViewCamera: Hashable {
///
/// - Returns: The constructed MapViewCamera.
public static func `default`() -> MapViewCamera {
return MapViewCamera(state: .coordinate(onCenter: Defaults.coordinate),
return MapViewCamera(state: .centered(onCoordinate: Defaults.coordinate),
zoom: Defaults.zoom,
pitch: Defaults.pitch,
direction: Defaults.direction,
Expand All @@ -52,7 +52,7 @@ public struct MapViewCamera: Hashable {
direction: CLLocationDirection = Defaults.direction,
reason: CameraChangeReason? = nil) -> MapViewCamera {

return MapViewCamera(state: .coordinate(onCenter: coordinate),
return MapViewCamera(state: .centered(onCoordinate: coordinate),
zoom: zoom,
pitch: pitch,
direction: direction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ final class CameraStateTests: XCTestCase {

func testCenterCameraState() {
let expectedCoordinate = CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4)
let state: CameraState = .coordinate(onCenter: expectedCoordinate)
XCTAssertEqual(state, .coordinate(onCenter: CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4)))
XCTAssertEqual(String(describing: state), "CameraState.coordinate(onCenter: CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4)")
let state: CameraState = .centered(onCoordinate: expectedCoordinate)
XCTAssertEqual(state, .centered(onCoordinate: CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4)))
XCTAssertEqual(String(describing: state), "CameraState.centered(onCoordinate: CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4)")
}

func testTrackingUserLocation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class MapViewCameraTests: XCTestCase {

let camera = MapViewCamera.center(expectedCoordinate, zoom: 12, pitch: pitch, direction: direction)

XCTAssertEqual(camera.state, .coordinate(onCenter: expectedCoordinate))
XCTAssertEqual(camera.state, .centered(onCoordinate: expectedCoordinate))
XCTAssertEqual(camera.zoom, 12)
XCTAssertEqual(camera.pitch, pitch)
XCTAssertEqual(camera.direction, direction)
Expand Down

0 comments on commit ad561ea

Please sign in to comment.