ashare80 / TSClusterMapView

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

negative span value results in crash #30

Open aytunch opened 8 years ago

aytunch commented 8 years ago

Crash Report: Inside "TSClusterMapView.m":

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    ....
    if (MKMapRectSizeIsGreaterThanOrEqual(zoomTo, self.visibleMapRect)) {
        zoomTo = MKMapRectInset(zoomTo, zoomTo.size.width/4, zoomTo.size.width/4);
        //At this point zoomTo.size.height becomes negative
    }
    MKCoordinateRegion region = MKCoordinateRegionForMapRect(zoomTo); 
    //and negative zoomTo results in negative(invalid) region.span.latitudeDelta
    ....
    [self setRegion:region animated:YES];  
    //Which results in a crash in this line with the invalid region being set
}

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region <center:+40.97086950, +29.03882550 span:-0.00556946, +0.01978016>' *** img_4418

Scenario: Q:What makes (MKMapRectSizeIsGreaterThanOrEqual(zoomTo, self.visibleMapRect)) equal to YES? A:In my particular case for some clusters(not leafs), when I touch on them the map starts zooming towards the center of the clusterAnnotationView which is good and expected. But for some reason, animation stops early and does not split the cluster that is selected. When the setRegion animation stops, I touch on the same cluster again and MKMapRectSizeIsGreaterThanOrEqual returns yes and I get the crash. img_4419

Conclusion: I can fork the project and make sure the region values are valid before fed into setRegion:Animated: but this is not the real issue. I want to know why the cluster does not get broken when touched on it and stops early and how to avoid this.

aytunch commented 8 years ago

By the way, i added the exact 4 annotations with the same coordinates to your sample app and realized that it works as it should. I am investigating why i am having an odd issue like this in my app. It might be related to something else, i will write soon. Thanks

aytunch commented 8 years ago

I realized this only happens when the map is in landscape mode(width>height). But couldn't exactly pinpoint the code to fix..

ashare80 commented 8 years ago

@aytunch Ok I'll check it out.

In your images are those annotation views or call outs?

If they are annotation views the size may cause some problems with splitting since the algorithm takes into account the size of the views. So if your leafs all appeared as the one with "cookshop" they probably wouldn't all be able to fit on the screen together and the cluster will never split. That can be overcome by changing the mapView's "clusterAnnotationViewSize" but you'll end up with overlapping views.

ashare80 commented 8 years ago

If you could try and see if this fixes the problem with the crash

change in the touches ended method the

if (zoomTo.size.width < 3000)

to

if (zoomTo.size.width < 3000 || zoomTo.size.height < 3000) {