Open jkrumow opened 9 years ago
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.
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.
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).
@tarbrain Have you seen this API? It will allow you to zoom in to an annotation and select it.
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.
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.
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 ;)
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.
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.
Both addAnnotations:withCompletionHandler:
and removeAnnotations:withCompletionHandler:
have completion handlers that are called when the update is finished.
You're right but I don't know when that updateAnnotationsWithCompletionHandler:
completes.
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
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