You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
mapViewWillStartLoadingMap not called on initial load #9357
MGLMapViewDelegate.mapViewWillStartLoadingMap is not called for the initial map load.
Is this guaranteed behaviour, a timing issue with the delegate connection, or a bug? In other words: Can I count on the fact that mapViewWillStartLoadingMap will never be called in the following example?
class ViewController: UIViewController, MGLMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let map = MGLMapView(frame: view.frame)
map.delegate = self
view.addSubview(map)
}
func mapViewWillStartLoadingMap(_ mapView: MGLMapView) {
// start loading features
}
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
// setup source and add loaded features
}
}
My use case is this is: I want to start asynchronously loading features whenever the map's style changes. I do it in mapViewWillStartLoadingMap except that I have to treat the initial load as a special case. It would be great if I could just include it in mapViewWillStartLoadingMap.
I think -[MGLMapViewDelegate mapViewWillStartLoadingMap:] should be called on the first initialization, but it is currently true (as of v3.6.0) that it cannot be — mapViewWillStartLoadingMap is sent when a style begins loading, which first happens in initWithCoder:/initWithFrame:.
Setting the delegate in the nib/storyboard would probably be the earliest way (faster than viewDidLoad:), but that still happens after our view’sinit.
So I’d say that the current behavior is a bug that we’ll want to fix, but it’s reliably broken for now.
First call to -[MGLMapView mapViewWillStartLoadingMap]
to add more feedback we prefer to use this method mapViewWillStartLoadingMap to give CLLocation time to acquire. We are forced to using func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) which means the users location is always stale relative to the map at loading.
Activity
friedbunny commentedon Jun 23, 2017
I think
-[MGLMapViewDelegate mapViewWillStartLoadingMap:]should be called on the first initialization, but it is currently true (as of v3.6.0) that it cannot be —mapViewWillStartLoadingMapis sent when a style begins loading, which first happens ininitWithCoder:/initWithFrame:.Setting the delegate in the nib/storyboard would probably be the earliest way (faster than
viewDidLoad:), but that still happens after our view’sinit.So I’d say that the current behavior is a bug that we’ll want to fix, but it’s reliably broken for now.
First call to -[MGLMapView mapViewWillStartLoadingMap]
First call to -[MGLMapView setDelegate:]
stale commentedon Dec 2, 2018
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.
stale commentedon Jun 2, 2019
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.
misterkerry commentedon Jul 26, 2020
to add more feedback we prefer to use this method
mapViewWillStartLoadingMapto give CLLocation time to acquire. We are forced to usingfunc mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle)which means the users location is always stale relative to the map at loading.