Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting annotations in viewDidLoad adds superfluous annotations in Landscape #87

Open
odrobnik opened this issue Apr 23, 2015 · 2 comments
Labels

Comments

@odrobnik
Copy link

If you set up the annotations for your map view controller in viewDidLoad - as suggested in the README then you get a superfluous cluster annotation if presenting the map view controller in Landscape. Note the big "59" cluster on top of ÖSTERREICH.

ios simulator screen shot 23 apr 2015 18 28 24

If you move it to viewWillAppear or later, then this extra cluster does not appear:

ios simulator screen shot 23 apr 2015 18 30 18

I believe that the reason for the misbehavior comes from MKMapView having an incorrect position during viewDidLoad. I added logging for the visible map rect in the -init of CCHMapClusterOperation.

Portrait, viewDidLoad:

Visible map rect = {{141014758.6, 88274850.3}, {6111232.3, 10743653.0}}
Visible map rect = {{141014758.6, 88274850.3}, {6111232.3, 10743653.0}}

Portrait, viewWillAppear:

Visible map rect = {{141014758.6, 88274850.3}, {6111232.3, 10743653.0}}

Landscape, viewDidLoad:

Visible map rect = {{40502319.6, 79459175.3}, {127778493.3, 69020511.0}}
Visible map rect = {{141014758.7, 91996163.0}, {6111232.1, 3301027.8}}

Landscape, viewWillAppear:

Visible map rect = {{141014758.7, 91996163.0}, {6111232.1, 3301027.8}}

The second line in the Landscape-viewDidLoad log comes from this call stack:

screen shot 2015-04-23 at 18 40 37

As you can see there is a timer delay that fixes the visible map rect and calling the mapView:regionDidChange:animated: thus triggering a reclustering.

Putting the setup code into viewWillAppear resolves the issue, but the question for this bug report is, whether the initial clustering shouldn't be delayed until after the first setting of the visible region. The current recommendation and code leads to a superfluous clustering operation.

The second question is, why the second clustering operation does not correct the superfluous cluster annotations that the first one created.

This issue observed on an app with deployment target 8.1, running on 8.3, using a MKMapView from storyboard and size classes throughout.

@choefele
Copy link
Owner

I updated the sample code to read in 500 annotations synchronously in viewDidLoad. In this scenario, CCHMapClusterOperation gets called twice: once for a setRegion call and once for adding annotations. The clusterer has to re-cluster the annotations in both cases because either operation causes a change in the visible annotations (the first one will be basically for free because there are no annotations to cluster). Is this what you are seeing as well?

As for the second case: setting the region should definitely re-cluster all visible annotations. Could you provide sample code that demonstrates this issue? When I use the example project, the app starts in portrait and when I rotate manually to landscape, everything works fine. But your are starting this view controller in landscape?

@odrobnik
Copy link
Author

Unfortunately I don't have time to provide more than these steps to reproduce:

  • map controller is inside a tab view controller as second VC
  • app supports landscape
  • log the visible map rect property of the app
  • run app
  • turn to landscape
  • tap on tab with map controller

This should show you the described behavior

@choefele choefele added the bug label Jun 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants