Skip to content

Commit a5a329a

Browse files
authored
Merge pull request #32 from stadiamaps/minor-fixes
Minor fixes
2 parents 546e912 + 50a5fdd commit a5a329a

File tree

9 files changed

+50
-11
lines changed

9 files changed

+50
-11
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let package = Package(
2424
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.1.0"),
2525
.package(url: "https://github.com/stadiamaps/maplibre-swift-macros.git", from: "0.0.2"),
2626
// Testing
27-
.package(url: "https://github.com/Kolos65/Mockable.git", from: "0.0.2"),
27+
.package(url: "https://github.com/Kolos65/Mockable.git", exact: "0.0.3"),
2828
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.15.3"),
2929
],
3030
targets: [

Sources/MapLibreSwiftDSL/MapControls.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,26 @@ public extension LogoView {
9797
}
9898
}
9999

100+
public struct AttributionButton: MapControl {
101+
public var position: MLNOrnamentPosition?
102+
public var margins: CGPoint?
103+
public var isHidden: Bool = false
104+
105+
public func configureMapView(_ mapView: MLNMapView) {
106+
if let position {
107+
mapView.attributionButtonPosition = position
108+
}
109+
110+
if let margins {
111+
mapView.attributionButtonMargins = margins
112+
}
113+
114+
mapView.attributionButton.isHidden = isHidden
115+
}
116+
117+
public init() {}
118+
}
119+
100120
@resultBuilder
101121
public enum MapControlsBuilder: DefaultResultBuilder {
102122
public static func buildExpression(_ expression: MapControl) -> [MapControl] {

Sources/MapLibreSwiftUI/Extensions/MapViewCamera/MapViewCameraOperations.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public extension MapViewCamera {
1919
state = .trackingUserLocationWithHeading(zoom: newZoom, pitch: pitch)
2020
case let .trackingUserLocationWithCourse(_, pitch):
2121
state = .trackingUserLocationWithCourse(zoom: newZoom, pitch: pitch)
22-
case let .rect(boundingBox, edgePadding):
22+
case .rect:
2323
return
24-
case let .showcase(shapeCollection):
24+
case .showcase:
2525
return
2626
}
2727

@@ -44,9 +44,9 @@ public extension MapViewCamera {
4444
state = .trackingUserLocationWithHeading(zoom: zoom + increment, pitch: pitch)
4545
case let .trackingUserLocationWithCourse(zoom, pitch):
4646
state = .trackingUserLocationWithCourse(zoom: zoom + increment, pitch: pitch)
47-
case let .rect(boundingBox, edgePadding):
47+
case .rect:
4848
return
49-
case let .showcase(shapeCollection):
49+
case .showcase:
5050
return
5151
}
5252

@@ -60,7 +60,7 @@ public extension MapViewCamera {
6060
/// - Parameter newPitch: The new pitch value.
6161
mutating func setPitch(_ newPitch: CameraPitch) {
6262
switch state {
63-
case let .centered(onCoordinate, zoom, pitch, direction):
63+
case let .centered(onCoordinate, zoom, _, direction):
6464
state = .centered(onCoordinate: onCoordinate,
6565
zoom: zoom,
6666
pitch: newPitch,
@@ -71,9 +71,9 @@ public extension MapViewCamera {
7171
state = .trackingUserLocationWithHeading(zoom: zoom, pitch: newPitch)
7272
case let .trackingUserLocationWithCourse(zoom, _):
7373
state = .trackingUserLocationWithCourse(zoom: zoom, pitch: newPitch)
74-
case let .rect(boundingBox, edgePadding):
74+
case .rect:
7575
return
76-
case let .showcase(shapeCollection):
76+
case .showcase:
7777
return
7878
}
7979

Sources/MapLibreSwiftUI/MapView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ public struct MapView: UIViewRepresentable {
1313
var onStyleLoaded: ((MLNStyle) -> Void)?
1414

1515
public var mapViewContentInset: UIEdgeInsets = .zero
16-
public var isLogoViewHidden = false
17-
public var isCompassViewHidden = false
1816

1917
/// 'Escape hatch' to MLNMapView until we have more modifiers.
2018
/// See ``unsafeMapViewModifier(_:)``
@@ -23,6 +21,7 @@ public struct MapView: UIViewRepresentable {
2321
var controls: [MapControl] = [
2422
CompassView(),
2523
LogoView(),
24+
AttributionButton(),
2625
]
2726

2827
private var locationManager: MLNLocationManager?
@@ -104,6 +103,7 @@ public struct MapView: UIViewRepresentable {
104103
// Assume all controls are hidden by default (so that an empty list returns a map with no controls)
105104
mapView.logoView.isHidden = true
106105
mapView.compassView.isHidden = true
106+
mapView.attributionButton.isHidden = true
107107

108108
// Apply each control configuration
109109
for control in controls {

Sources/MapLibreSwiftUI/StaticLocationManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import MapLibre
1010
///
1111
/// You can provide a new location by setting the ``lastLocation`` property.
1212
///
13-
/// This class does not ever perform any authorization checks. That is the responsiblity of the caller.
13+
/// This class does not ever perform any authorization checks. That is the responsibility of the caller.
1414
public final class StaticLocationManager: NSObject, @unchecked Sendable {
1515
public var delegate: (any MLNLocationManagerDelegate)?
1616

Tests/MapLibreSwiftUITests/Examples/MapControlsTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,23 @@ final class MapControlsTests: XCTestCase {
5050
}
5151
}
5252
}
53+
54+
func testAttributionOnly() {
55+
assertView {
56+
MapView(styleURL: demoTilesURL)
57+
.mapControls {
58+
AttributionButton()
59+
}
60+
}
61+
}
62+
63+
func testAttributionChangePosition() {
64+
assertView {
65+
MapView(styleURL: demoTilesURL)
66+
.mapControls {
67+
AttributionButton()
68+
.position(.topLeft)
69+
}
70+
}
71+
}
5372
}
71.6 KB
Loading
69.2 KB
Loading
-30.7 KB
Loading

0 commit comments

Comments
 (0)