Skip to content

Add CustomStringConvertibles #92

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

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Sources/MapLibreSwiftUI/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ import MapLibreSwiftDSL
import SwiftUI

/// Identifies the activity this ``MapView`` is being used for. Useful for debugging purposes.
public enum MapActivity: Int {
public enum MapActivity: Int, CustomStringConvertible {
/// Navigation in a standard window. Default.
case standard = 0
/// Navigation in a CarPlay template.
case carplay = 2025

public var description: String {
switch self {
case .standard:
"standard"
case .carplay:
"carplay"
}
}
}

public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentable {
Expand Down
21 changes: 21 additions & 0 deletions Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@ import Foundation
import MapLibre
import MapLibreSwiftDSL

extension MLNCameraChangeReason: @retroactive CustomStringConvertible {
private static let descriptions: [(Self, String)] = [
(.programmatic, "programmatic"),
(.resetNorth, "resetNorth"),
(.gesturePan, "gesturePan"),
(.gesturePinch, "gesturePinch"),
(.gestureRotate, "gestureRotate"),
(.gestureZoomIn, "gestureZoomIn"),
(.gestureZoomOut, "gestureZoomOut"),
(.gestureOneFingerZoom, "gestureOneFingerZoom"),
(.gestureTilt, "gestureTilt"),
(.transitionCancelled, "transitionCancelled"),
]

public var description: String {
var names = Self.descriptions.filter { contains($0.0) }.map(\.1)
if names.isEmpty { names = ["none"] }
return names.joined(separator: ",")
}
}

public class MapViewCoordinator<T: MapViewHostViewController>: NSObject, @preconcurrency
MLNMapViewDelegate {
// This must be weak, the UIViewRepresentable owns the MLNMapView.
Expand Down
6 changes: 5 additions & 1 deletion Sources/MapLibreSwiftUI/Models/MapCamera/MapViewCamera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import MapLibre
/// The SwiftUI MapViewCamera.
///
/// This manages the camera state within the MapView.
public struct MapViewCamera: Hashable, Equatable, Sendable {
public struct MapViewCamera: Hashable, Equatable, Sendable, CustomStringConvertible {
public enum Defaults {
public static let coordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0)
public static let zoom: Double = 10
Expand Down Expand Up @@ -139,4 +139,8 @@ public struct MapViewCamera: Hashable, Equatable, Sendable {
MapViewCamera(state: .rect(boundingBox: box, edgePadding: edgePadding),
lastReasonForChange: .programmatic)
}

public var description: String {
"State: \(state) last: \((lastReasonForChange != nil) ? "\(lastReasonForChange!)" : "nil")"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ final class MapGestureTests: XCTestCase {
func testTapGestureDefaults() {
let gesture = MapGesture(method: .tap(),
onChange: .context { _ in

})

XCTAssertEqual(gesture.method, .tap())
Expand All @@ -15,7 +14,6 @@ final class MapGestureTests: XCTestCase {
func testTapGesture() {
let gesture = MapGesture(method: .tap(numberOfTaps: 3),
onChange: .context { _ in

})

XCTAssertEqual(gesture.method, .tap(numberOfTaps: 3))
Expand All @@ -25,7 +23,6 @@ final class MapGestureTests: XCTestCase {
func testLongPressGestureDefaults() {
let gesture = MapGesture(method: .longPress(),
onChange: .context { _ in

})

XCTAssertEqual(gesture.method, .longPress())
Expand All @@ -35,7 +32,6 @@ final class MapGestureTests: XCTestCase {
func testLongPressGesture() {
let gesture = MapGesture(method: .longPress(minimumDuration: 3),
onChange: .context { _ in

})

XCTAssertEqual(gesture.method, .longPress(minimumDuration: 3))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
▿ MapViewCamera
▿ lastReasonForChange: Optional<CameraChangeReason>
- some: CameraChangeReason.programmatic
▿ State: CameraState.rect(northeast: CLLocationCoordinate2D(latitude: 24.6993808, longitude: 46.7709285), southwest: CLLocationCoordinate2D(latitude: 24.6056011, longitude: 46.67369842529297), edgePadding: UIEdgeInsets(top: 20.0, left: 20.0, bottom: 20.0, right: 20.0)) last: programmatic
▿ state: CameraState
▿ rect: (2 elements)
▿ boundingBox: MLNCoordinateBounds
Expand All @@ -15,3 +13,5 @@
- left: 20.0
- right: 20.0
- top: 20.0
▿ lastReasonForChange: Optional<CameraChangeReason>
- some: CameraChangeReason.programmatic
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
▿ MapViewCamera
- lastReasonForChange: Optional<CameraChangeReason>.none
▿ State: CameraState.centered(onCoordinate: CLLocationCoordinate2D(latitude: 12.3, longitude: 23.4), zoom: 5.0, pitch: 12.0, pitchRange: free, direction: 23.0) last: nil
▿ state: CameraState
▿ centered: (5 elements)
▿ onCoordinate: CLLocationCoordinate2D
Expand All @@ -9,3 +8,4 @@
- pitch: 12.0
- pitchRange: CameraPitchRange.free
- direction: 23.0
- lastReasonForChange: Optional<CameraChangeReason>.none
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
▿ MapViewCamera
▿ lastReasonForChange: Optional<CameraChangeReason>
- some: CameraChangeReason.programmatic
▿ State: CameraState.trackingUserLocationWithCourse(zoom: (18.0, 0.0, MapLibreSwiftUI.CameraPitchRange.freeWithinRange(minimum: 12.0, maximum: 34.0))) last: programmatic
▿ state: CameraState
▿ trackingUserLocationWithCourse: (3 elements)
- zoom: 18.0
Expand All @@ -9,3 +7,5 @@
▿ freeWithinRange: (2 elements)
- minimum: 12.0
- maximum: 34.0
▿ lastReasonForChange: Optional<CameraChangeReason>
- some: CameraChangeReason.programmatic
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
▿ MapViewCamera
▿ lastReasonForChange: Optional<CameraChangeReason>
- some: CameraChangeReason.programmatic
▿ State: CameraState.trackingUserLocationWithHeading(zoom: (10.0, 0.0, MapLibreSwiftUI.CameraPitchRange.free)) last: programmatic
▿ state: CameraState
▿ trackingUserLocationWithHeading: (3 elements)
- zoom: 10.0
- pitch: 0.0
- pitchRange: CameraPitchRange.free
▿ lastReasonForChange: Optional<CameraChangeReason>
- some: CameraChangeReason.programmatic
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
▿ MapViewCamera
▿ lastReasonForChange: Optional<CameraChangeReason>
- some: CameraChangeReason.programmatic
▿ State: CameraState.trackingUserLocation(zoom: (10.0, 0.0, MapLibreSwiftUI.CameraPitchRange.freeWithinRange(minimum: 12.0, maximum: 34.0), 0.0)) last: programmatic
▿ state: CameraState
▿ trackingUserLocation: (4 elements)
- zoom: 10.0
Expand All @@ -10,3 +8,5 @@
- minimum: 12.0
- maximum: 34.0
- direction: 0.0
▿ lastReasonForChange: Optional<CameraChangeReason>
- some: CameraChangeReason.programmatic
Loading