Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions Sources/MapLibreSwiftUI/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentab
var gestures = [MapGesture]()

var onStyleLoaded: ((MLNStyle) -> Void)?
var onUserTrackingModeChanged: ((MLNUserTrackingMode, Bool) -> Void)?
var onViewProxyChanged: ((MapViewProxy) -> Void)?
var proxyUpdateMode: ProxyUpdateMode?

Expand Down Expand Up @@ -105,6 +106,9 @@ public struct MapView<T: MapViewHostViewController>: UIViewControllerRepresentab
// Link the style loaded to the coordinator that emits the delegate event.
context.coordinator.onStyleLoaded = onStyleLoaded

// Link the user tracking change to the coordinator that emits the delegate event.
context.coordinator.onUserTrackingModeChange = onUserTrackingModeChanged

// Add all gesture recognizers
for gesture in gestures {
registerGesture(controller.mapView, context, gesture: gesture)
Expand Down
5 changes: 5 additions & 0 deletions Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ MLNMapViewDelegate {
var cameraUpdateContinuation: CheckedContinuation<Void, Never>?

var onStyleLoaded: ((MLNStyle) -> Void)?
var onUserTrackingModeChange: ((MLNUserTrackingMode, Bool) -> Void)?
var onGesture: (MLNMapView, UIGestureRecognizer) -> Void
var onViewProxyChanged: (MapViewProxy) -> Void
var proxyUpdateMode: ProxyUpdateMode
Expand Down Expand Up @@ -438,6 +439,10 @@ MLNMapViewDelegate {
}
}

public func mapView(_: MLNMapView, didChange mode: MLNUserTrackingMode, animated: Bool) {
onUserTrackingModeChange?(mode, animated)
}

// MARK: MapViewProxy

@MainActor private func updateViewProxy(mapView: MLNMapView, reason: MLNCameraChangeReason) {
Expand Down
6 changes: 6 additions & 0 deletions Sources/MapLibreSwiftUI/MapViewModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public extension MapView {
return newMapView
}

func onUserTrackingModeChanged(_ perform: @escaping (MLNUserTrackingMode, Bool) -> Void) -> MapView {
var newMapView = self
newMapView.onUserTrackingModeChanged = perform
return newMapView
}

/// Allows you to set properties of the underlying MLNMapView directly
/// in cases where these have not been ported to DSL yet.
/// Use this function to modify various properties of the MLNMapView instance.
Expand Down
Loading