Skip to content

Commit 6724a86

Browse files
committed
Add onUserTrackingModeChanged modifier to MapView.
1 parent 98aa8cd commit 6724a86

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Sources/MapLibreSwiftUI/MapView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentab
3333
var gestures = [MapGesture]()
3434

3535
var onStyleLoaded: ((MLNStyle) -> Void)?
36+
var onUserTrackingModeChanged: ((MLNUserTrackingMode, Bool) -> Void)?
3637
var onViewProxyChanged: ((MapViewProxy) -> Void)?
3738
var proxyUpdateMode: ProxyUpdateMode?
3839

@@ -104,6 +105,9 @@ public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentab
104105

105106
// Link the style loaded to the coordinator that emits the delegate event.
106107
context.coordinator.onStyleLoaded = onStyleLoaded
108+
109+
// Link the user tracking change to the coordinator that emits the delegate event.
110+
context.coordinator.onUserTrackingModeChange = onUserTrackingModeChanged
107111

108112
// Add all gesture recognizers
109113
for gesture in gestures {

Sources/MapLibreSwiftUI/MapViewCoordinator.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ MLNMapViewDelegate {
4444
var cameraUpdateContinuation: CheckedContinuation<Void, Never>?
4545

4646
var onStyleLoaded: ((MLNStyle) -> Void)?
47+
var onUserTrackingModeChange: ((MLNUserTrackingMode, Bool) -> Void)?
4748
var onGesture: (MLNMapView, UIGestureRecognizer) -> Void
4849
var onViewProxyChanged: (MapViewProxy) -> Void
4950
var proxyUpdateMode: ProxyUpdateMode
@@ -437,6 +438,10 @@ MLNMapViewDelegate {
437438
updateViewProxy(mapView: mapView, reason: reason)
438439
}
439440
}
441+
442+
public func mapView(_ mapView: MLNMapView, didChange mode: MLNUserTrackingMode, animated: Bool) {
443+
onUserTrackingModeChange?(mode, animated)
444+
}
440445

441446
// MARK: MapViewProxy
442447

Sources/MapLibreSwiftUI/MapViewModifiers.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public extension MapView {
1313
newMapView.onStyleLoaded = perform
1414
return newMapView
1515
}
16+
17+
func onUserTrackingModeChanged(_ perform: @escaping (MLNUserTrackingMode, Bool) -> Void) -> MapView {
18+
var newMapView = self
19+
newMapView.onUserTrackingModeChanged = perform
20+
return newMapView
21+
}
1622

1723
/// Allows you to set properties of the underlying MLNMapView directly
1824
/// in cases where these have not been ported to DSL yet.

0 commit comments

Comments
 (0)