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

Annotations are deselected when zooming #65

Open
jkrumow opened this issue Dec 10, 2014 · 12 comments
Open

Annotations are deselected when zooming #65

jkrumow opened this issue Dec 10, 2014 · 12 comments

Comments

@jkrumow
Copy link
Contributor

jkrumow commented Dec 10, 2014

Hello Claus,

thanks for implementing this great library.

What i have noticed is that when i select a cluster annotation and zoom the map the annotation is automatically deselected which I find is a problem sometimes.

Is there a way to exclude a selected cluster annotation from the clustering mechanism? So it stays put and selected?

Best Regards
Julian

@choefele
Copy link
Owner

The deselection is caused by this line of code. I included this because a cluster will change its content when zooming so I'm not sure how much point there is to keep the annotation selected.

Can you describe the scenario where you find this behavior problematic?

Also, @muccy just create PR #66 to modify this behavior.

@muccy
Copy link

muccy commented Dec 11, 2014

I didn't see this issue and, at first, I thought to add an option to exclude this mechanism at all, I confess. After all I agreed with you that there is no much sense to keep a callout opened when content is changed. It would be great if callout would be closed only when clustering changes selected annotation, but I don't know how to detect this easily.

My PR only fixes the case when zoom is detected badly, which is the case of map with heading enabled. Also if I don't touch the map, every time I move a little bit heading changes and so callout is dismissed.

@jkrumow
Copy link
Contributor Author

jkrumow commented Dec 11, 2014

Scenario:
I navigate the map and spot a single annotation. I select the annotation and add an overlay to the map showing the route from the user location to the selected annotation.
Then I zoom the map to have both the user location and the selected annotation visible to see my complete route. Then the annotations gets deselected and the route overlay disappears.

The problem here is that I can not tell who deselected the annotation. Was it the clusterer or the user?

A nice solution would be an exclusion list / lock for annotations which will not be touched by the clusterer (I think OCMapView does it that way).

@choefele
Copy link
Owner

@tarbrain Have you seen this API? It will allow you to zoom in to an annotation and select it.

@jkrumow
Copy link
Contributor Author

jkrumow commented Dec 11, 2014

I do not want to explicitly zoom into a cluster. I want to zoom the map to a size that both user location pin and annotation are visible.

@choefele
Copy link
Owner

Using an MKMapView without clustering, callouts never disappear when zooming/panning. Since this is the default, my suggestion is to remove the call to deselectAllAnnotations in mapView:regionDidChangeAnimated:. The previous behavior, or any other behavior, can be implemented by the application.

@muccy
Copy link

muccy commented Dec 19, 2014

But default MapKit does not change visible annotation views after zooming. Is it possible to get a delegate message to discover which clusters have changed? If so everything would be simpler ;)

@choefele
Copy link
Owner

When a cluster gets selected, you can keep a reference to the annotations in it and compare this information in mapView:regionDidChangeAnimated: to figure out if the cluster has changed. That's why I would like to move this code into applications because there seems to be various ways to handle selection.

@muccy
Copy link

muccy commented Dec 19, 2014

I agree, but updateAnnotationsWithCompletionHandler: (called inside that method) is asynchronous. I would need a point in the code where I'm sure the update is done. That's why I proposed a delegate message.

@choefele
Copy link
Owner

Both addAnnotations:withCompletionHandler: and removeAnnotations:withCompletionHandler: have completion handlers that are called when the update is finished.

@muccy
Copy link

muccy commented Dec 19, 2014

You're right but I don't know when that updateAnnotationsWithCompletionHandler: completes.

@SebC99
Copy link

SebC99 commented Jan 21, 2015

Another scenario:
in my app, I have no callout, but a view at the bottom of the screen with details on the selected annotation. And when I select an annotation, it center this annotation and zoom the map to focus on it.
With the "automatic deselection when zooming", each time a selection is done, it's deselected right after

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

No branches or pull requests

4 participants