Skip to content
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

Minor fixes #32

Merged
merged 8 commits into from
Apr 9, 2024
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
20 changes: 20 additions & 0 deletions Sources/MapLibreSwiftDSL/MapControls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ public extension LogoView {
}
}

public struct AttributionButton: MapControl {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol. Was also needing this.

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] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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,
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/MapLibreSwiftUI/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(_:)``
Expand All @@ -23,6 +21,7 @@ public struct MapView: UIViewRepresentable {
var controls: [MapControl] = [
CompassView(),
LogoView(),
AttributionButton(),
]

private var locationManager: MLNLocationManager?
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/MapLibreSwiftUI/StaticLocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)?

Expand Down
19 changes: 19 additions & 0 deletions Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading