Code Monkey home page Code Monkey logo

Comments (8)

choefele avatar choefele commented on July 16, 2024

Thanks for reporting this issue!

It's expected that updateAnnotationsWithCompletionHandler: gets called when you call setCenterCoordinate:animated:. Surprisingly, though, the cell size in map point units returned by CCHMapClusterControllerMapLengthForLength changes. That's why the clusters rearrange.

I have no idea why the cell size changes when calling setCenterCoordinate:animated: but not when panning the map through use interactions.

If you print out the cell size returned by CCHMapClusterControllerMapLengthForLength, you can see that the cell size is bigger when selecting a cluster further north and smaller when selecting one that's further south.

Really strange.

from cchmapclustercontroller.

plu avatar plu commented on July 16, 2024

Thanks for your answer!

I have the feeling, that Apple is internally using setRegion:animated: whenever you use setCenterCoordinate:animated:. There it says:

Changing just the center coordinate of the region can still cause the span values to change
implicitly. The span values might change because that the distances represented by a span
change at different latitudes and longitudes and the map view may need to adjust the span
to account for the new location. If you want to change the center coordinate without
changing the zoom level, use the setCenterCoordinate:animated: instead.

But the last part does not seem to be true, really weird. I've checked OpenRadar, if this is a known issue, but no luck so far.

from cchmapclustercontroller.

choefele avatar choefele commented on July 16, 2024

You are right, the zoom changes. It seems to be a problem specific to iOS 7. I can't reproduce this on iOS 6, but I can on iOS 7 and 7.1 Beta 5 (tested on simulator).

As a workaround, I suggest the following code, which avoids zooming in my tests:

    CLLocationCoordinate2D location = CLLocationCoordinate2DMake(52.526221, 13.397829);
    MKMapPoint point = MKMapPointForCoordinate(location);
    MKMapRect rect = [self.mapView visibleMapRect];
    rect.origin.x = point.x - rect.size.width * 0.5;
    rect.origin.y = point.y - rect.size.height * 0.5;
    [self.mapView setVisibleMapRect:rect animated:YES];

@plu Could you please have a look whether this solves your problem?

from cchmapclustercontroller.

plu avatar plu commented on July 16, 2024

This does fix my problem, thanks a lot! You can close this ticket, if you want to :).

Maybe we should file a Radar then for iOS 7? The other day I was already looking into OpenRadar for similar issues, but could not identify any.

from cchmapclustercontroller.

choefele avatar choefele commented on July 16, 2024

I added a code example for this to the documentation. Thanks again for reporting this issue.

from cchmapclustercontroller.

mikrobi avatar mikrobi commented on July 16, 2024

I'm still facing issues even with using setVisibleMapRect:animated:. In my app I want to center the map whenever the user selects an annotation. In general this works fine, but in case of a big zoom level, the map view somehow ignores the CGRect that I pass to setVisibleMapRect:animated:. After setting the rect, I end up with a bigger rect than I originally passed in. I couldn't find any solutions so far. Have you experienced a similar behaviour?

from cchmapclustercontroller.

mikrobi avatar mikrobi commented on July 16, 2024

I've done some testing with mapRectThatFits:(MKMapRect)mapRect before setting the rect via setVisibleMapRect:(MKMapRect)mapRect animated:(BOOL)animate like described in the docs.

According to the Apple Docs, I assume that the return value of mapRectThatFits:(MKMapRect)mapRect should match the rect that will be applied internally when using setVisibleMapRect:(MKMapRect)mapRect animated:(BOOL)animate

The funny (or annoying) thing is that the calculated rect via

MKMapRect rect = [self.mapView visibleMapRect];
rect.origin.x = point.x - rect.size.width * 0.5;
rect.origin.y = point.y - rect.size.height * 0.5;

never matches the rect returned by [mapView mapRectThatFits:rect]. The size always differs slightly by random values below 0.5. Probably caused by because of all the internal calculations, rounding and conversions by MapKit?

I haven't found any cool way to set the center coordinate or change the visible map rect by not (slightly) changing mapView.region.span.longitudeDelta which is used in CCHMapClusterController to determine if the zoom level changed after changing the map view's region.

I was thinking about adding something like a "zoom change tolerance" so that we ignore marginal zoom changes and only re-cluster when the zoom changed significantly. @choefele what do you think? Should we re-open this issue?

from cchmapclustercontroller.

mikrobi avatar mikrobi commented on July 16, 2024

Hmm, the "zoom change tolerance" prevents the CCHMapClusterController from undesired deselections. But then it might happen, that a selected annotation disappears because it gets merged into a cluster. This is caused because a marginal change of longitudeDelta might trigger a "heavy" cluster re-odering like described in #82. Seems like these issues are highly coupled.

from cchmapclustercontroller.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.