Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

mapViewWillStartLoadingMap not called on initial load #9357

Open

Description

@arthurhammer

Platform: ios
Mapbox SDK version: ios-v3.6.0-rc.1

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.

Activity

  1. added
    accessibility
    iOS
    and removed
    accessibility
    on Jun 23, 2017
  2. friedbunny commented on Jun 23, 2017

    @friedbunny
    Contributor

    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]
    * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
      * frame #0: 0x0000000105bda714 Mapbox`::-[MGLMapView mapViewWillStartLoadingMap](self=0x00007fc04f85b000, _cmd="mapViewWillStartLoadingMap") at MGLMapView.mm:4899
        frame #1: 0x0000000105be30df Mapbox`MBGLView::onWillStartLoadingMap(this=0x00006000000554e0) at MGLMapView.mm:5476
        frame #2: 0x0000000105be4149 Mapbox`non-virtual thunk to MBGLView::onWillStartLoadingMap(this=0x00006000000554e0) at MGLMapView.mm:0
        frame #3: 0x0000000105ecccf8 Mapbox`mbgl::Map::setStyleURL(this=0x000060000001ee30, url="mapbox://styles/mapbox/streets-v10") at map.cpp:333
        frame #4: 0x0000000105b9b177 Mapbox`::-[MGLMapView setStyleURL:](self=0x00007fc04f85b000, _cmd="setStyleURL:", styleURL="mapbox://styles/mapbox/streets-v10") at MGLMapView.mm:398
        frame #5: 0x0000000105b9a918 Mapbox`::-[MGLMapView initWithCoder:](self=0x00007fc04f85b000, _cmd="initWithCoder:", decoder=0x00007fc04f849e00) at MGLMapView.mm:357
        frame #6: 0x00000001094142a4 UIKit`-[UIClassSwapper initWithCoder:] + 246
        frame #7: 0x00000001096047ff UIKit`UINibDecoderDecodeObjectForValue + 693
        frame #8: 0x000000010960453f UIKit`-[UINibDecoder decodeObjectForKey:] + 89
        frame #9: 0x0000000109413f46 UIKit`-[UIRuntimeConnection initWithCoder:] + 136
        frame #10: 0x0000000109738d80 UIKit`-[UIRuntimeOutletCollectionConnection initWithCoder:] + 61
        frame #11: 0x00000001096047ff UIKit`UINibDecoderDecodeObjectForValue + 693
        frame #12: 0x000000010960499d UIKit`UINibDecoderDecodeObjectForValue + 1107
        frame #13: 0x000000010960453f UIKit`-[UINibDecoder decodeObjectForKey:] + 89
        frame #14: 0x000000010941316d UIKit`-[UINib instantiateWithOwner:options:] + 1262
        frame #15: 0x00000001091adfc3 UIKit`-[UIViewController _loadViewFromNibNamed:bundle:] + 381
        frame #16: 0x00000001091ae8d9 UIKit`-[UIViewController loadView] + 177
        frame #17: 0x00000001091aec0a UIKit`-[UIViewController loadViewIfRequired] + 195
        frame #18: 0x00000001091ede6c UIKit`-[UINavigationController _layoutViewController:] + 56
        frame #19: 0x00000001091ee74a UIKit`-[UINavigationController _updateScrollViewFromViewController:toViewController:] + 466
        frame #20: 0x00000001091ee8bb UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 127
        frame #21: 0x00000001091efa03 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 843
        frame #22: 0x00000001091f0b41 UIKit`-[UINavigationController __viewWillLayoutSubviews] + 58
        frame #23: 0x00000001093e260c UIKit`-[UILayoutContainerView layoutSubviews] + 231
        frame #24: 0x00000001090cf55b UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
        frame #25: 0x000000010b5e9904 QuartzCore`-[CALayer layoutSublayers] + 146
        frame #26: 0x000000010b5dd526 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 370
        frame #27: 0x000000010b5dd3a0 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
        frame #28: 0x000000010b56ce92 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 294
        frame #29: 0x000000010b599130 QuartzCore`CA::Transaction::commit() + 468
        frame #30: 0x000000010b599b37 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 115
        frame #31: 0x0000000108404717 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
        frame #32: 0x0000000108404687 CoreFoundation`__CFRunLoopDoObservers + 391
        frame #33: 0x00000001083e9038 CoreFoundation`CFRunLoopRunSpecific + 440
        frame #34: 0x000000010900608f UIKit`-[UIApplication _run] + 468
        frame #35: 0x000000010900c134 UIKit`UIApplicationMain + 159
        frame #36: 0x00000001058b100f Mapbox GL`main(argc=1, argv=0x00007fff5a34e6a0) at main.m:8
        frame #37: 0x000000010a8d965d libdyld.dylib`start + 1
    
    First call to -[MGLMapView setDelegate:]
    * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1
      * frame #0: 0x0000000105ba059e Mapbox`::-[MGLMapView setDelegate:](self=0x00007fc04f85b000, _cmd="setDelegate:", delegate=0x00007fc04f708f80) at MGLMapView.mm:747
        frame #1: 0x00000001079d900b Foundation`-[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
        frame #2: 0x00000001090cee08 UIKit`-[UIView(CALayerDelegate) setValue:forKey:] + 172
        frame #3: 0x0000000109414a09 UIKit`-[UIRuntimeOutletConnection connect] + 109
        frame #4: 0x0000000108404e8d CoreFoundation`-[NSArray makeObjectsPerformSelector:] + 269
        frame #5: 0x00000001094133bf UIKit`-[UINib instantiateWithOwner:options:] + 1856
        frame #6: 0x00000001091adfc3 UIKit`-[UIViewController _loadViewFromNibNamed:bundle:] + 381
        frame #7: 0x00000001091ae8d9 UIKit`-[UIViewController loadView] + 177
        frame #8: 0x00000001091aec0a UIKit`-[UIViewController loadViewIfRequired] + 195
        frame #9: 0x00000001091ede6c UIKit`-[UINavigationController _layoutViewController:] + 56
        frame #10: 0x00000001091ee74a UIKit`-[UINavigationController _updateScrollViewFromViewController:toViewController:] + 466
        frame #11: 0x00000001091ee8bb UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 127
        frame #12: 0x00000001091efa03 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 843
        frame #13: 0x00000001091f0b41 UIKit`-[UINavigationController __viewWillLayoutSubviews] + 58
        frame #14: 0x00000001093e260c UIKit`-[UILayoutContainerView layoutSubviews] + 231
        frame #15: 0x00000001090cf55b UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
        frame #16: 0x000000010b5e9904 QuartzCore`-[CALayer layoutSublayers] + 146
        frame #17: 0x000000010b5dd526 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 370
        frame #18: 0x000000010b5dd3a0 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
        frame #19: 0x000000010b56ce92 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 294
        frame #20: 0x000000010b599130 QuartzCore`CA::Transaction::commit() + 468
        frame #21: 0x000000010b599b37 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 115
        frame #22: 0x0000000108404717 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
        frame #23: 0x0000000108404687 CoreFoundation`__CFRunLoopDoObservers + 391
        frame #24: 0x00000001083e9038 CoreFoundation`CFRunLoopRunSpecific + 440
        frame #25: 0x000000010900608f UIKit`-[UIApplication _run] + 468
        frame #26: 0x000000010900c134 UIKit`UIApplicationMain + 159
        frame #27: 0x00000001058b100f Mapbox GL`main(argc=1, argv=0x00007fff5a34e6a0) at main.m:8
        frame #28: 0x000000010a8d965d libdyld.dylib`start + 1
    
  3. modified the milestones: ios-v3.6.0, on Jun 29, 2017
  4. removed this from the milestone on Sep 18, 2017
  5. added
    archived
    on Nov 4, 2018
  6. stale commented on Dec 2, 2018

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

  7. removed
    archived
    on Dec 3, 2018
  8. added
    archived
    on Jun 1, 2019
  9. stale commented on Jun 2, 2019

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

  10. removed
    archived
    on Jun 3, 2019
  11. misterkerry commented on Jul 26, 2020

    @misterkerry

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggl-iosiOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions