Skip to content

Commit

Permalink
improving camera conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
hactar committed Oct 6, 2024
1 parent d1f9ecc commit b11ab25
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,21 @@ public class MapViewCoordinator<T: MapViewHostViewController>: 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
Expand Down

0 comments on commit b11ab25

Please sign in to comment.