ashare80 / TSClusterMapView

MKMapView with animated clustering for iOS and OSX
MIT License
149 stars 21 forks source link

Annotations going crazy when changing map layout and center #11

Open zfrankz opened 9 years ago

zfrankz commented 9 years ago

Hello, I have a "layout changing" map view (changes the height of the view with some user interactions) and those changes (changing map center coordinates as well) make the annotations going crazy, changing their positions and some disappearing!

Screenshots:

https://www.dropbox.com/s/t3kmqytjzl6wtx9/crazy1.png?dl=0

When I select the annotation in the first "O" of London I change the height of the map and on didSelectAnnotationView: delegation method I do [self.theMap setCenterCoordinate:theannotation.coordinate animated:YES];

That's what I have: https://www.dropbox.com/s/hdi2n9nwb848974/crazy2.png?dl=0

As you can see, the annotation has been displaced and any other annotations are gone!

ashare80 commented 9 years ago

If you could try the code on the Develop branch and see if there's any change to you results. Will look into this further.

zfrankz commented 9 years ago

Hello, I'm testing the new code and I realised that now, when an annotation is selected in the map, the class of this annotation view has changed. For example, if is a clustered one, now is member of my custom clustered class instead of the TSClusterAnnotationView class. I haven't checked the changes on the code but at first instance I thought it was because iOS 8.2 (I updated a device) but I tried in a different one and still happening the same. Are you aware of it? Anyway, I made some changes to adapt my code to that new "feature".

Well, coming back to the issue, now the annotations seem to be not so crazy but, after few times expanding/collapsing a clusterAnnotation, I can see how is "moving" to the left (I think is the #8 issue)

ashare80 commented 9 years ago

@zfrankz Yes it was pointed out to me that the TSClusterAnnotationView was being returned instead of the custom cluster annotation view class provided which is a bug. The reason being you'll never have access to the correct annotation when the cluster is split into individual annotations. TSClusterAnnotationView will always point to the wrapper cluster annotation and never the original annotation that you added to the mapView.

Also for any visual changes, you don't want to be making changes to TSClusterAnnotationView

Still looking into #8

zfrankz commented 9 years ago

Ok, please tell me when that bug is solved because I will need access to the custom annotationView to change the image sometimes to make them look as "selected" (the user can select them from a list of locations).

Now with the new code, all the annotations make a kind of blinking when they are "relocated" because of the change of the layout but at least they are not disappearing!

Thanks

ashare80 commented 9 years ago

@zfrankz I'm assuming your map height change is animated? Recreated something like you describe with an animated change of the layout constraints to the mapView.

I believe there's a clashing of the UIView animation in the clustering and the animated layout of subviews during an animated change of the frame or constraints.

Working on a fix to the problem.

zfrankz commented 9 years ago

Yes, is animating the height of the map view. Thanks for the support.

zfrankz commented 9 years ago

Changing the height of the map is very heavy for some devices so I decided to change map region offset instead.

ashare80 commented 9 years ago

@zfrankz Nice that's probably the better way to do it.

Since annotations are treated as subviews they re-layout during frame changes which causes the problems with animations.