CCHMapClusterController icon indicating copy to clipboard operation
CCHMapClusterController copied to clipboard

Clustering sometimes changes when changing region coordinates, but not zoom level

Open kusamakura opened this issue 8 years ago • 8 comments

Sometimes when changing the map view's center region, the update annotation sequence triggers (namely, in CCHMapClusterController's mapView:regionDidChangeAnimated:). This is due to the longitude delta check. Since calculating the zoom level is already included in this project, wouldn't it be better to use that instead? I have a fork which does just that, and I set the epsilon/difference threshold to a value to something small enough, but not too small to trigger a 'zoom change' when changing the region center.

kusamakura avatar Jan 15 '16 14:01 kusamakura

Does this recipe help?

choefele avatar Jan 17 '16 18:01 choefele

I used it before, but changing the clusters on the same zoom level (even when using the same region span, updateAnnotations would still get triggered) is not desirable for my use case. So I'm not actually sure if this is a bug, since what happens is contrary to what's intended – in the comments, at least.

kusamakura avatar Jan 18 '16 06:01 kusamakura

Sorry for the late reply. Might be a good idea to use CCHMapClusterControllerZoomLevelForRegion with a small delta to decide if the map has been zoomed.

Would you mind creating a pull request and trying out if this works?

choefele avatar Jan 24 '16 18:01 choefele

@choefele, sorry for the late reply as well. I'll get a PR working within this week. :)

kusamakura avatar Feb 02 '16 08:02 kusamakura

@choefele is there an equivalent of the recipe that you mentioned above for when when trying to select an annotation with selectAnnotation:andZoomToRegionWithLatitudinalMeters:longitudinalMeters:?

Otherwise, selecting an annotation programatically would most of the times change clustering, even when zooming didn't change.

I tried tried to use CLLocationDistance MKMetersBetweenMapPoints ( MKMapPoint a, MKMapPoint b ) to compute the latitudinalMeters and longitudinalMeters from the visibleMapRect, but it still sees it as a zoom.

I did some experiments at https://github.com/bhapca/CCHMapClusterController/commit/2988453972fdde114882a8abc2824d85aea69935 and https://github.com/bhapca/CCHMapClusterController/commit/4e57c75f6497411a174b47410aeb945da8a974fb to provide a way of selecting without zooming. Is there a way to achieve the equivalent behaviour with the current API ?

bhapca avatar Jun 03 '16 11:06 bhapca

Also, if setCenterCoordinate:animated: is buggy, so that it needs that workaround, wouldn't this line be a problem ?

bhapca avatar Jun 03 '16 13:06 bhapca

The code to select an annotation assumes that some zooming will happen anyway. I haven't worked on this behaviour for a while, so I don't know any workarounds

choefele avatar Jun 06 '16 15:06 choefele

I think there are several issues with selectAnnotation:andZoomToRegionWithLatitudinalMeters:longitudinalMeters:

  1. Given a set level of zoom there's no way to select between different annotations without changing the clustering.
  2. If called repeatedly, when the map is still animating from a previous call, the map ends up in the middle of the ocean.
  3. If called repeatedly, after the animation from the previous call has settled, you may get errors like "ERROR: Trying to select an annotation which has not been added", at random.

These all can be seen with a change to the sample app that I made at: https://github.com/bhapca/CCHMapClusterController/tree/select-annotation-issues. It simply provides a way to swap the selection between 2 annotations at the East and West sides of Berlin.

I placed a potential fix for all these issues on https://github.com/bhapca/CCHMapClusterController/tree/select-annotation-issues-fix, and created the PR at https://github.com/choefele/CCHMapClusterController/pull/126, if you wish to bring them into master.

bhapca avatar Jun 07 '16 15:06 bhapca