From b11ab259ffa91bb199d489d9ea759192a5d89ed7 Mon Sep 17 00:00:00 2001 From: PW Date: Sun, 6 Oct 2024 14:27:46 +0200 Subject: [PATCH] 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