Skip to content

Commit

Permalink
Merge pull request #32 from stadiamaps/minor-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
ianthetechie authored Apr 9, 2024
2 parents 546e912 + 50a5fdd commit a5a329a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 11 deletions.
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 {
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.

0 comments on commit a5a329a

Please sign in to comment.