From b11ab259ffa91bb199d489d9ea759192a5d89ed7 Mon Sep 17 00:00:00 2001 From: PW Date: Sun, 6 Oct 2024 14:27:46 +0200 Subject: [PATCH 1/2] improving camera conversion --- Sources/MapLibreSwiftUI/MapViewCoordinator.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Sources/MapLibreSwiftUI/MapViewCoordinator.swift b/Sources/MapLibreSwiftUI/MapViewCoordinator.swift index f6cd0fb..5f2e625 100644 --- a/Sources/MapLibreSwiftUI/MapViewCoordinator.swift +++ b/Sources/MapLibreSwiftUI/MapViewCoordinator.swift @@ -331,13 +331,21 @@ public class MapViewCoordinator: NSObject, MLNMapV // Publish the MLNMapView's "raw" camera state to the MapView camera binding. // This path only executes when the map view diverges from the parent state, so this is a "matter of fact" // state propagation. + + // Determine camera pitch range based on current MapView settings + let pitchRange: CameraPitchRange + if mapView.minimumPitch == 0 && mapView.maximumPitch > 59.9 { + pitchRange = .free + } else if mapView.minimumPitch == mapView.maximumPitch { + pitchRange = .fixed(mapView.minimumPitch) + } else { + pitchRange = .freeWithinRange(minimum: mapView.minimumPitch, maximum: mapView.maximumPitch) + } + let newCamera: MapViewCamera = .center(mapView.centerCoordinate, zoom: mapView.zoomLevel, pitch: mapView.camera.pitch, - pitchRange: .freeWithinRange( - minimum: mapView.minimumPitch, - maximum: mapView.maximumPitch - ), + pitchRange: pitchRange, direction: mapView.direction, reason: CameraChangeReason(reason)) snapshotCamera = newCamera From 6eecb5fd553373dfbd4a0409e8ac53f9165b8858 Mon Sep 17 00:00:00 2001 From: PW Date: Sun, 6 Oct 2024 14:45:25 +0200 Subject: [PATCH 2/2] linting --- Sources/MapLibreSwiftUI/MapViewCoordinator.swift | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sources/MapLibreSwiftUI/MapViewCoordinator.swift b/Sources/MapLibreSwiftUI/MapViewCoordinator.swift index 5f2e625..ea87875 100644 --- a/Sources/MapLibreSwiftUI/MapViewCoordinator.swift +++ b/Sources/MapLibreSwiftUI/MapViewCoordinator.swift @@ -331,17 +331,16 @@ public class MapViewCoordinator: NSObject, MLNMapV // Publish the MLNMapView's "raw" camera state to the MapView camera binding. // This path only executes when the map view diverges from the parent state, so this is a "matter of fact" // state propagation. - + // Determine camera pitch range based on current MapView settings - let pitchRange: CameraPitchRange - if mapView.minimumPitch == 0 && mapView.maximumPitch > 59.9 { - pitchRange = .free + let pitchRange: CameraPitchRange = if mapView.minimumPitch == 0 && mapView.maximumPitch > 59.9 { + .free } else if mapView.minimumPitch == mapView.maximumPitch { - pitchRange = .fixed(mapView.minimumPitch) + .fixed(mapView.minimumPitch) } else { - pitchRange = .freeWithinRange(minimum: mapView.minimumPitch, maximum: mapView.maximumPitch) + .freeWithinRange(minimum: mapView.minimumPitch, maximum: mapView.maximumPitch) } - + let newCamera: MapViewCamera = .center(mapView.centerCoordinate, zoom: mapView.zoomLevel, pitch: mapView.camera.pitch,