Skip to content

Add onUserTrackingModeChanged modifier to MapView. #100

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Sources/MapLibreSwiftDSL/Style Layers/Background.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public struct BackgroundLayer: StyleLayer {
public let identifier: String
public var insertionPosition: LayerInsertionPosition = .below(.all)
public var isVisible: Bool = true
public var maximumZoomLevel: Float? = nil
public var minimumZoomLevel: Float? = nil
public var maximumZoomLevel: Float?
public var minimumZoomLevel: Float?

public init(identifier: String) {
self.identifier = identifier
Expand Down
4 changes: 2 additions & 2 deletions Sources/MapLibreSwiftDSL/Style Layers/Circle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public struct CircleStyleLayer: SourceBoundVectorStyleLayerDefinition {
public let sourceLayerIdentifier: String?
public var insertionPosition: LayerInsertionPosition = .above(.all)
public var isVisible: Bool = true
public var maximumZoomLevel: Float? = nil
public var minimumZoomLevel: Float? = nil
public var maximumZoomLevel: Float?
public var minimumZoomLevel: Float?

public var source: StyleLayerSource
public var predicate: NSPredicate?
Expand Down
4 changes: 2 additions & 2 deletions Sources/MapLibreSwiftDSL/Style Layers/FillStyleLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public struct FillStyleLayer: SourceBoundVectorStyleLayerDefinition {
public let sourceLayerIdentifier: String?
public var insertionPosition: LayerInsertionPosition = .above(.all)
public var isVisible: Bool = true
public var maximumZoomLevel: Float? = nil
public var minimumZoomLevel: Float? = nil
public var maximumZoomLevel: Float?
public var minimumZoomLevel: Float?

public var source: StyleLayerSource
public var predicate: NSPredicate?
Expand Down
4 changes: 2 additions & 2 deletions Sources/MapLibreSwiftDSL/Style Layers/Line.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public struct LineStyleLayer: SourceBoundVectorStyleLayerDefinition {
public let sourceLayerIdentifier: String?
public var insertionPosition: LayerInsertionPosition = .above(.all)
public var isVisible: Bool = true
public var maximumZoomLevel: Float? = nil
public var minimumZoomLevel: Float? = nil
public var maximumZoomLevel: Float?
public var minimumZoomLevel: Float?

public var source: StyleLayerSource
public var predicate: NSPredicate?
Expand Down
4 changes: 2 additions & 2 deletions Sources/MapLibreSwiftDSL/Style Layers/Symbol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public struct SymbolStyleLayer: SourceBoundVectorStyleLayerDefinition {
public let sourceLayerIdentifier: String?
public var insertionPosition: LayerInsertionPosition = .above(.all)
public var isVisible: Bool = true
public var maximumZoomLevel: Float? = nil
public var minimumZoomLevel: Float? = nil
public var maximumZoomLevel: Float?
public var minimumZoomLevel: Float?

public var source: StyleLayerSource
public var predicate: NSPredicate?
Expand Down
4 changes: 2 additions & 2 deletions Sources/MapLibreSwiftUI/Examples/Camera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ struct CameraDirectManipulationPreview: View {
@State private var camera = MapViewCamera.center(switzerland, zoom: 4)

let styleURL: URL
var onStyleLoaded: (() -> Void)? = nil
var targetCameraAfterDelay: MapViewCamera? = nil
var onStyleLoaded: (() -> Void)?
var targetCameraAfterDelay: MapViewCamera?

var body: some View {
MapView(styleURL: styleURL, camera: $camera)
Expand Down
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