ashare80 / TSClusterMapView

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

Is there a way to intercept the click to does not expand the pins in the last zoom level? #31

Open pcsantana opened 8 years ago

pcsantana commented 8 years ago

Hii, First, thank you for sharing this great and useful lib. I am trying to use it, but I want a little different behavior when I give zoom in the last level and is not be possible to ungroup the pins. In this scenario, I want to intercept the default behavior (replace the pins around the original coordinate when the user tap on pin). In my case I wish to display some list with the places data (because I need to show all shops (200+) in the mall, for example). But I was not be able to disable this default behavior and insert my code.

If there is a way, I appreciate it if you could help me. Thank you very much! Best regards,

Paulo Santana.

pcsantana commented 8 years ago

Hi, I found out! Just return "false" in:

pcsantana commented 8 years ago

Hi,

If possible I would to suggest a little modification. If there are a lot of places very close to each other, with another places with exactly the same coordinates, the algorithm not call the method below:

-(BOOL)mapView:(TSClusterMapView *)mapView shouldForceSplitClusterAnnotation:(ADClusterAnnotation *)clusterAnnotation;

Debugging the code, I find out the reason. Because the method is only called when the groupedRounded annotations count is equal to 1:


//...TSClusterMapView class, in "splitClusterToOriginal:clusterAnnotation" method
NSDictionary *groupedRoundedLatLonAnnotations = [TSClusterOperation groupAnnotationsByLocationValue:[NSSet setWithArray:clusterAnnotation.cluster.originalAnnotations]];

//Here the condition
if (groupedRoundedLatLonAnnotations.allKeys.count == 1) {
    if ([_clusterDelegate respondsToSelector:@selector(mapView:shouldForceSplitClusterAnnotation:)]) {
        if (![_clusterDelegate mapView:self shouldForceSplitClusterAnnotation:clusterAnnotation]) {
            return;
        }
    }
}

Maybe this condition can be parameterized (count value). In my case, for example, I don't need this condition. Please correct me if I am wrong.

Thank you very much!

ashare80 commented 8 years ago

@pcsantana Hmm yeah I guess the idea there was that if they weren't close enough to get grouped together into 1 single shared coordinate it should always split.

I think we can just get rid of that if statement of that solves your problem?

pcsantana commented 8 years ago

Yes @ashare80, I commented the if statement and it solved my problem

ashare80 commented 8 years ago

@pcsantana ok cool next version will remove it

pcsantana commented 8 years ago

Thank you! :)