mapbox / mapbox/mapbox-maps-ios
Camera animation laggy on initial zoom in on first app install
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
- Xcode version: 14.1
- iOS version: 16
- Devices affected: iPhone 14 Pro
- Maps SDK Version: 10.9
## Observed behavior and steps to reproduce
Upon initial install of an app, the camera zoom-in animation is very laggy (presumably because it's loading and caching tiles), but not laggy on subsequent launches. This creates a negative first impression for new users, and it would be great to have a way to preload these assets and then trigger the zoom in when completed to ensure a smooth animation.
I have tried prefetchZoomDelta but that does not seem to have any effect. The documentation is a bit tough to decipher but it seems to be for another purpose and does not have any impact on first-time load performance.
- Video:
https://user-images.githubusercontent.com/11130748/199375219-9438b6c3-709b-44b7-940c-791f9a7f0313.MP4
- Code snippet:
```
import UIKit
import MapboxMaps
@objc(CameraAnimationExample)
public class CameraAnimationExample: UIViewController, ExampleProtocol {
internal var mapView: MapView!
override public func viewDidLoad() {
super.viewDidLoad()
self.mapView = MapView(frame: view.bounds, mapInitOptions: MapInitOptions(cameraOptions: CameraOptions(center: CLLocationCoordinate2D(latitude: 34.89, longitude: -93.98), zoom: 1)))
try? mapView.mapboxMap.style.setProjection(StyleProjection(name: .globe))
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(mapView)
mapView.mapboxMap.onNext(event: .mapLoaded) { _ in
let centerCoordinate = CLLocationCoordinate2D(
latitude: 25.767546, longitude: -80.191451)
let newCamera = CameraOptions(center: centerCoordinate,
zoom: 15.2,
pitch: 30.0)
self.mapView.camera.fly(to: newCamera, duration: 5.0) { [weak self] (_) in
// The below line is used for internal testing purposes only.
self?.finish()
}
}
}
}
```
Are there any suggested methods we can use to mitigate this at the moment? Is a pre-load callback function a feature that can be added in the future?
## Expected behavior
Should not lag on first-time load.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the MapView initialization and .mapLoaded callback in the provided Swift snippet, then investigate how prefetchZoomDelta relates to first-load tile caching. Reproduce the issue on the stated iOS 16 and iPhone 14 Pro setup and compare first and subsequent launches; done means a tested mitigation or a clearly documented API limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile-dev, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100