diff --git a/Package.swift b/Package.swift index b0ba5b1..bc273c8 100644 --- a/Package.swift +++ b/Package.swift @@ -24,7 +24,7 @@ let package = Package( .package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.1.0"), .package(url: "https://github.com/stadiamaps/maplibre-swift-macros.git", from: "0.0.2"), // Testing - .package(url: "https://github.com/Kolos65/Mockable.git", from: "0.0.2"), + .package(url: "https://github.com/Kolos65/Mockable.git", exact: "0.0.3"), .package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.15.3"), ], targets: [ diff --git a/Sources/MapLibreSwiftDSL/MapControls.swift b/Sources/MapLibreSwiftDSL/MapControls.swift index 6593b6b..4faf02e 100644 --- a/Sources/MapLibreSwiftDSL/MapControls.swift +++ b/Sources/MapLibreSwiftDSL/MapControls.swift @@ -97,6 +97,26 @@ public extension LogoView { } } +public struct AttributionButton: MapControl { + public var position: MLNOrnamentPosition? + public var margins: CGPoint? + public var isHidden: Bool = false + + public func configureMapView(_ mapView: MLNMapView) { + if let position { + mapView.attributionButtonPosition = position + } + + if let margins { + mapView.attributionButtonMargins = margins + } + + mapView.attributionButton.isHidden = isHidden + } + + public init() {} +} + @resultBuilder public enum MapControlsBuilder: DefaultResultBuilder { public static func buildExpression(_ expression: MapControl) -> [MapControl] { diff --git a/Sources/MapLibreSwiftUI/Extensions/MapViewCamera/MapViewCameraOperations.swift b/Sources/MapLibreSwiftUI/Extensions/MapViewCamera/MapViewCameraOperations.swift index cb04a1d..a58f330 100644 --- a/Sources/MapLibreSwiftUI/Extensions/MapViewCamera/MapViewCameraOperations.swift +++ b/Sources/MapLibreSwiftUI/Extensions/MapViewCamera/MapViewCameraOperations.swift @@ -19,9 +19,9 @@ public extension MapViewCamera { state = .trackingUserLocationWithHeading(zoom: newZoom, pitch: pitch) case let .trackingUserLocationWithCourse(_, pitch): state = .trackingUserLocationWithCourse(zoom: newZoom, pitch: pitch) - case let .rect(boundingBox, edgePadding): + case .rect: return - case let .showcase(shapeCollection): + case .showcase: return } @@ -44,9 +44,9 @@ public extension MapViewCamera { state = .trackingUserLocationWithHeading(zoom: zoom + increment, pitch: pitch) case let .trackingUserLocationWithCourse(zoom, pitch): state = .trackingUserLocationWithCourse(zoom: zoom + increment, pitch: pitch) - case let .rect(boundingBox, edgePadding): + case .rect: return - case let .showcase(shapeCollection): + case .showcase: return } @@ -60,7 +60,7 @@ public extension MapViewCamera { /// - Parameter newPitch: The new pitch value. mutating func setPitch(_ newPitch: CameraPitch) { switch state { - case let .centered(onCoordinate, zoom, pitch, direction): + case let .centered(onCoordinate, zoom, _, direction): state = .centered(onCoordinate: onCoordinate, zoom: zoom, pitch: newPitch, @@ -71,9 +71,9 @@ public extension MapViewCamera { state = .trackingUserLocationWithHeading(zoom: zoom, pitch: newPitch) case let .trackingUserLocationWithCourse(zoom, _): state = .trackingUserLocationWithCourse(zoom: zoom, pitch: newPitch) - case let .rect(boundingBox, edgePadding): + case .rect: return - case let .showcase(shapeCollection): + case .showcase: return } diff --git a/Sources/MapLibreSwiftUI/MapView.swift b/Sources/MapLibreSwiftUI/MapView.swift index 5b10d9e..932238c 100644 --- a/Sources/MapLibreSwiftUI/MapView.swift +++ b/Sources/MapLibreSwiftUI/MapView.swift @@ -13,8 +13,6 @@ public struct MapView: UIViewRepresentable { var onStyleLoaded: ((MLNStyle) -> Void)? public var mapViewContentInset: UIEdgeInsets = .zero - public var isLogoViewHidden = false - public var isCompassViewHidden = false /// 'Escape hatch' to MLNMapView until we have more modifiers. /// See ``unsafeMapViewModifier(_:)`` @@ -23,6 +21,7 @@ public struct MapView: UIViewRepresentable { var controls: [MapControl] = [ CompassView(), LogoView(), + AttributionButton(), ] private var locationManager: MLNLocationManager? @@ -104,6 +103,7 @@ public struct MapView: UIViewRepresentable { // Assume all controls are hidden by default (so that an empty list returns a map with no controls) mapView.logoView.isHidden = true mapView.compassView.isHidden = true + mapView.attributionButton.isHidden = true // Apply each control configuration for control in controls { diff --git a/Sources/MapLibreSwiftUI/StaticLocationManager.swift b/Sources/MapLibreSwiftUI/StaticLocationManager.swift index ecee763..1bbe6b6 100644 --- a/Sources/MapLibreSwiftUI/StaticLocationManager.swift +++ b/Sources/MapLibreSwiftUI/StaticLocationManager.swift @@ -10,7 +10,7 @@ import MapLibre /// /// You can provide a new location by setting the ``lastLocation`` property. /// -/// This class does not ever perform any authorization checks. That is the responsiblity of the caller. +/// This class does not ever perform any authorization checks. That is the responsibility of the caller. public final class StaticLocationManager: NSObject, @unchecked Sendable { public var delegate: (any MLNLocationManagerDelegate)? diff --git a/Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift b/Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift index 0d087bd..4389911 100644 --- a/Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift +++ b/Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift @@ -50,4 +50,23 @@ final class MapControlsTests: XCTestCase { } } } + + func testAttributionOnly() { + assertView { + MapView(styleURL: demoTilesURL) + .mapControls { + AttributionButton() + } + } + } + + func testAttributionChangePosition() { + assertView { + MapView(styleURL: demoTilesURL) + .mapControls { + AttributionButton() + .position(.topLeft) + } + } + } } diff --git a/Tests/MapLibreSwiftUITests/Examples/__Snapshots__/MapControlsTests/testAttributionChangePosition.1.png b/Tests/MapLibreSwiftUITests/Examples/__Snapshots__/MapControlsTests/testAttributionChangePosition.1.png new file mode 100644 index 0000000..b2fd6e2 Binary files /dev/null and b/Tests/MapLibreSwiftUITests/Examples/__Snapshots__/MapControlsTests/testAttributionChangePosition.1.png differ diff --git a/Tests/MapLibreSwiftUITests/Examples/__Snapshots__/MapControlsTests/testAttributionOnly.1.png b/Tests/MapLibreSwiftUITests/Examples/__Snapshots__/MapControlsTests/testAttributionOnly.1.png new file mode 100644 index 0000000..22296ce Binary files /dev/null and b/Tests/MapLibreSwiftUITests/Examples/__Snapshots__/MapControlsTests/testAttributionOnly.1.png differ diff --git a/Tests/MapLibreSwiftUITests/Examples/__Snapshots__/MapControlsTests/testEmptyControls.1.png b/Tests/MapLibreSwiftUITests/Examples/__Snapshots__/MapControlsTests/testEmptyControls.1.png index 22296ce..80c0081 100644 Binary files a/Tests/MapLibreSwiftUITests/Examples/__Snapshots__/MapControlsTests/testEmptyControls.1.png and b/Tests/MapLibreSwiftUITests/Examples/__Snapshots__/MapControlsTests/testEmptyControls.1.png differ