CCHMapClusterController
CCHMapClusterController copied to clipboard
Disabling clusterisation
Hello. First of all, thanks for nice framework, working for me like a charm.
I have a question. I am moving a camera manually (some animation), and when I moving it, framework trying to make clusterisation every frame (I think it;s because of setCamera calls). Is there any way to manually stop and then resume clusterisation?
It will be nice if I'll can stop clusterisation, make animation, and the restart it.
Thanks for your time, Karen.
Hi Karen,
At the moment, it's not possible to disable the clustering.
How do you animate the camera? Could you give me a code example?
The clustering happens whenever mapView:regionDidChangeAnimated: is called. Maybe there's a way to animate the camera without this method being called multiple times.
-Claus
Hi Claus, sure I can, here it is:
-
(void) pinch_func: (UIPinchGestureRecognizer*) sender { if ([sender state] == UIGestureRecognizerStateBegan) { mm = [map.camera copy]; alt_log = log (map.camera.altitude); self.mapClusterController = nil; }
const double alt_log_max = log (alt_max); const double alt_log_min = log (alt_min);
if ([sender velocity] > 0) alt_log -= [sender scale] / 50.0; else alt_log += [sender scale] / 40.0;
if (alt_log > alt_log_max) { alt_log = alt_log_max; } if (alt_log < alt_log_min) { alt_log = alt_log_min; }
alt = exp (alt_log); pitch = [self pitchFromAlt: alt];
mm.altitude = alt; mm.pitch = pitch;
camera_altitude = alt;
[map setCamera: mm animated: NO]; }
@choefele Any ideas? =(
Hi Karen,
At the moment, the only way to disable clustering would be to deallocate the CCHMapClusterController instance. This will leave the current annotations on the map view untouched. Then, when you have finished with the gesture, you could create a new instance and re-add the annotations to the cluster controller.
I know it's a bit of a hack, but could you try if this works?
I could offer a property to disable clustering temporarily, but I'm not sure this is a good idea.
Hi again, Claus =)
Well, you know, too user there is no matter, hack it or not. I will try your idea and then I'll response here about the result.
And by the way I really not sure that disabling clusterisation (I mean property) can be really good feature, but I think it is easy to add, so why not?
I haven't heard back on this issue for a while. Did my suggestion work for you?
Hey Claus. Well, your suggestion worked, but clusterisation working laggy while camera is moving.
I think that it will be very good improvement, if there will be the way to stop automatically clustering and use reclusterisation manually.
Hello. I have the same problem too. I have 10 -30 points in one city. When user tap on point
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view I call ... [self.mapView setRegion:region animated:YES]; ..
And after this clusterisation works. But every time with different values, because region is different a bit. And this looks not good - after each user's selection clusters are redrawing.
but! When user just swipe map regionDidChangeAnimated works too, but clusters are the same!
@lexin you might wanna checkout the code recipes. There is one to center the map around a specific annotation without changing the zoom level: https://github.com/choefele/CCHMapClusterController#centering-the-map-without-changing-the-zoom-level
@mikrobi Yes, thank you. I've made it like that.