Skip to content

Commit

Permalink
pitch workaround for initial load
Browse files Browse the repository at this point in the history
  • Loading branch information
hactar committed May 13, 2024
1 parent 420efc1 commit 2dffff2
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions Sources/MapLibreSwiftUI/MapViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public class MapViewCoordinator: NSObject {
direction: direction,
animated: animated)

let camera = mapView.camera
camera.pitch = pitch
mapView.setCamera(camera, animated: false)
// this is a workaround for no camera - minimum and maximum will be reset below, but this adjusts it.
mapView.minimumPitch = pitch
mapView.maximumPitch = pitch

} else {
let camera = mapView.camera
Expand All @@ -102,9 +102,8 @@ public class MapViewCoordinator: NSObject {
mapView.setZoomLevel(zoom, animated: false)
mapView.direction = direction

let camera = mapView.camera
camera.pitch = pitch
mapView.setCamera(camera, animated: false)
mapView.minimumPitch = pitch
mapView.maximumPitch = pitch

} else {
let camera = mapView.camera
Expand All @@ -121,14 +120,13 @@ public class MapViewCoordinator: NSObject {
mapView.userTrackingMode = .followWithHeading

if mapView.frame.size == .zero {
// On init, the mapView's frame is not set up yet, so altitude via camera is broken,
// On init, the mapView's frame is not set up yet, so manipulation via camera is broken,
// so let's do something else instead.
// Needs to be non-animated or else it messes up following

mapView.setZoomLevel(zoom, animated: false)
let camera = mapView.camera
camera.pitch = pitch
mapView.setCamera(camera, animated: false)
mapView.minimumPitch = pitch
mapView.maximumPitch = pitch

} else {
let camera = mapView.camera
Expand All @@ -145,14 +143,13 @@ public class MapViewCoordinator: NSObject {
mapView.userTrackingMode = .followWithCourse

if mapView.frame.size == .zero {
// On init, the mapView's frame is not set up yet, so altitude via camera is broken,
// On init, the mapView's frame is not set up yet, so manipulation via camera is broken,
// so let's do something else instead.
// Needs to be non-animated or else it messes up following

mapView.setZoomLevel(zoom, animated: false)
let camera = mapView.camera
camera.pitch = pitch
mapView.setCamera(camera, animated: false)
mapView.minimumPitch = pitch
mapView.maximumPitch = pitch

} else {
let camera = mapView.camera
Expand Down

0 comments on commit 2dffff2

Please sign in to comment.