Skip to content

Commit 9b306fc

Browse files
authored
Improving Camera Conversion (maplibre#54)
* improving camera conversion * linting
1 parent d1f9ecc commit 9b306fc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Sources/MapLibreSwiftUI/MapViewCoordinator.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,20 @@ public class MapViewCoordinator<T: MapViewHostViewController>: NSObject, MLNMapV
331331
// Publish the MLNMapView's "raw" camera state to the MapView camera binding.
332332
// This path only executes when the map view diverges from the parent state, so this is a "matter of fact"
333333
// state propagation.
334+
335+
// Determine camera pitch range based on current MapView settings
336+
let pitchRange: CameraPitchRange = if mapView.minimumPitch == 0 && mapView.maximumPitch > 59.9 {
337+
.free
338+
} else if mapView.minimumPitch == mapView.maximumPitch {
339+
.fixed(mapView.minimumPitch)
340+
} else {
341+
.freeWithinRange(minimum: mapView.minimumPitch, maximum: mapView.maximumPitch)
342+
}
343+
334344
let newCamera: MapViewCamera = .center(mapView.centerCoordinate,
335345
zoom: mapView.zoomLevel,
336346
pitch: mapView.camera.pitch,
337-
pitchRange: .freeWithinRange(
338-
minimum: mapView.minimumPitch,
339-
maximum: mapView.maximumPitch
340-
),
347+
pitchRange: pitchRange,
341348
direction: mapView.direction,
342349
reason: CameraChangeReason(reason))
343350
snapshotCamera = newCamera

0 commit comments

Comments
 (0)